summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorD. Scott Boggs <scott@tams.tech>2024-04-09 13:03:44 -0400
committerD. Scott Boggs <scott@tams.tech>2024-04-09 13:03:44 -0400
commit8d0cb43c54b59871bc824c193f453b610eb8b1ce (patch)
tree5863690cfdad264abfa76c0a1fc7c8a650feed16
parentaa38f1808c8433c94dd08aac2d8d502de7ef8211 (diff)
Move Filter GET/DELETE methods to v2
we're not bothering to rig up v1 filters as they're deprecated
-rw-r--r--src/macros.rs49
-rw-r--r--src/mastodon.rs9
2 files changed, 55 insertions, 3 deletions
diff --git a/src/macros.rs b/src/macros.rs
index 2ee50bc..9dc540c 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -239,6 +239,29 @@ macro_rules! route_v2 {
route_v2!{$($rest)*}
};
+
+ (($method:ident) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
+ doc_comment! {
+ concat!(
+ "Equivalent to `", stringify!($method), " /api/v2/",
+ $url,
+ "`\n# Errors\nIf `access_token` is not set.",
+ "\n",
+ "```no_run",
+ "use mastodon_async::prelude::*;\n",
+ "let data = Data::default();\n",
+ "let client = Mastodon::from(data);\n",
+ "client.", stringify!($name), "();\n",
+ "```"
+ ),
+ pub async fn $name(&self) -> Result<$ret> {
+ self.$method(self.route(concat!("/api/v2/", $url))).await
+ }
+ }
+
+ route!{$($rest)*}
+ };
+
() => {}
}
@@ -461,8 +484,34 @@ macro_rules! route_id {
}
)*
}
+}
+macro_rules! route_v2_id {
+ ($(($method:ident) $name:ident[$id_type:ty]: $url:expr => $ret:ty,)*) => {
+ $(
+ doc_comment! {
+ concat!(
+ "Equivalent to `", stringify!($method), " /api/v2/",
+ $url,
+ "`\n# Errors\nIf `access_token` is not set.",
+ "\n",
+ "```no_run",
+ "use mastodon_async::prelude::*;\n",
+ "let data = Data::default();\n",
+ "let client = Mastodon::from(data);\n",
+ "client.", stringify!($name), "(\"42\");\n",
+ "# Ok(())\n",
+ "# }\n",
+ "```"
+ ),
+ pub async fn $name(&self, id: &$id_type) -> Result<$ret> {
+ self.$method(self.route(&format!(concat!("/api/v2/", $url), id))).await
+ }
+ }
+ )*
+ }
}
+
macro_rules! paged_routes_with_id {
(($method:ident) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
diff --git a/src/mastodon.rs b/src/mastodon.rs
index 373d2e7..269d2f5 100644
--- a/src/mastodon.rs
+++ b/src/mastodon.rs
@@ -85,7 +85,6 @@ impl Mastodon {
(post) clear_notifications: "notifications/clear" => Empty,
(get) get_push_subscription: "push/subscription" => Subscription,
(delete) delete_push_subscription: "push/subscription" => Empty,
- (get) get_filters: "filters" => Vec<Filter>,
(get) get_follow_suggestions: "suggestions" => Vec<Account>,
(post (app: forms::Application,)) create_app: "apps" => Application,
(get) verify_app: "apps/verify_credentials" => Application,
@@ -95,6 +94,7 @@ impl Mastodon {
(get (q: &'a str, resolve: bool,)) search: "search" => SearchResult,
(post multipart with description (file: impl AsRef<Path>,)) media: "media" => Attachment,
(post multipart with description (file: impl AsRef<Path>, thumbnail: impl AsRef<Path>,)) media_with_thumbnail: "media" => Attachment,
+ (get) get_filters: "filters" => Vec<Filter>,
}
route_id! {
@@ -115,14 +115,17 @@ impl Mastodon {
(post) favourite[StatusId]: "statuses/{}/favourite" => Status,
(post) unfavourite[StatusId]: "statuses/{}/unfavourite" => Status,
(delete) delete_status[StatusId]: "statuses/{}" => Empty,
- (get) get_filter[FilterId]: "filters/{}" => Filter,
- (delete) delete_filter[FilterId]: "filters/{}" => Empty,
(delete) delete_from_suggestions[AccountId]: "suggestions/{}" => Empty,
(post) endorse_user[AccountId]: "accounts/{}/pin" => Relationship,
(post) unendorse_user[AccountId]: "accounts/{}/unpin" => Relationship,
(get) attachment[AttachmentId]: "media/{}" => Attachment,
}
+ route_v2_id! {
+ (get) get_filter[FilterId]: "filters/{}" => Filter,
+ (delete) delete_filter[FilterId]: "filters/{}" => Empty,
+ }
+
streaming! {
"returns events that are relevant to the authorized user, i.e. home timeline & notifications"
stream_user@"user",