From 8d0cb43c54b59871bc824c193f453b610eb8b1ce Mon Sep 17 00:00:00 2001 From: "D. Scott Boggs" Date: Tue, 9 Apr 2024 13:03:44 -0400 Subject: Move Filter GET/DELETE methods to v2 we're not bothering to rig up v1 filters as they're deprecated --- src/macros.rs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ src/mastodon.rs | 9 ++++++--- 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, (get) get_follow_suggestions: "suggestions" => Vec, (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,)) media: "media" => Attachment, (post multipart with description (file: impl AsRef, thumbnail: impl AsRef,)) media_with_thumbnail: "media" => Attachment, + (get) get_filters: "filters" => Vec, } 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", -- cgit v1.2.3