diff --git a/examples/follow_profile.rs b/examples/follow_profile.rs index 9f48ff8..01f6ed2 100644 --- a/examples/follow_profile.rs +++ b/examples/follow_profile.rs @@ -1,5 +1,6 @@ mod register; +use register::MastodonClient; use std::error; fn main() -> Result<(), Box> { diff --git a/examples/print_your_profile.rs b/examples/print_your_profile.rs index f1b3bae..515c7c4 100644 --- a/examples/print_your_profile.rs +++ b/examples/print_your_profile.rs @@ -1,7 +1,9 @@ mod register; +use register::MastodonClient; use std::error; + fn main() -> Result<(), Box> { let mastodon = register::get_mastodon_data()?; let you = mastodon.verify_credentials()?; diff --git a/examples/register.rs b/examples/register.rs index cfc8c5e..89c05e5 100644 --- a/examples/register.rs +++ b/examples/register.rs @@ -1,6 +1,8 @@ extern crate mammut; extern crate toml; +pub use self::mammut::MastodonClient; + use std::{ error::Error, fs, diff --git a/examples/search.rs b/examples/search.rs index bb772af..00a7a76 100644 --- a/examples/search.rs +++ b/examples/search.rs @@ -1,5 +1,6 @@ mod register; +use register::MastodonClient; use std::error; fn main() -> Result<(), Box> { diff --git a/examples/upload_photo.rs b/examples/upload_photo.rs index bcd3687..4fa3790 100644 --- a/examples/upload_photo.rs +++ b/examples/upload_photo.rs @@ -1,5 +1,6 @@ mod register; +use register::MastodonClient; use std::error; fn main() -> Result<(), Box> { diff --git a/src/entities/itemsiter.rs b/src/entities/itemsiter.rs index f01ddb1..e5f835a 100644 --- a/src/entities/itemsiter.rs +++ b/src/entities/itemsiter.rs @@ -5,7 +5,7 @@ use serde::Deserialize; /// /// ```no_run /// # extern crate mammut; -/// # use mammut::{Data, Mastodon}; +/// # use mammut::{Data, Mastodon, MastodonClient}; /// # use std::error::Error; /// # fn main() -> Result<(), Box> { /// # let data = Data { diff --git a/src/lib.rs b/src/lib.rs index d354274..4894b8c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,7 @@ //! # try().unwrap(); //! # } //! # fn try() -> mammut::Result<()> { -//! use mammut::Registration; +//! use mammut::{MastodonClient, Registration}; //! use mammut::apps::{AppBuilder, Scopes}; //! //! let app = AppBuilder { @@ -98,7 +98,7 @@ macro_rules! paged_routes { "Equivalent to `/api/v1/", $url, "`\n# Errors\nIf `access_token` is not set."), - pub fn $name(&self) -> Result> { + fn $name(&self) -> Result> { let url = self.route(concat!("/api/v1/", $url)); let response = self.client.$method(&url) .headers(self.headers.clone()) @@ -123,7 +123,7 @@ macro_rules! route { "Equivalent to `/api/v1/", $url, "`\n# Errors\nIf `access_token` is not set."), - pub fn $name(&self, $($param: $typ,)*) -> Result<$ret> { + fn $name(&self, $($param: $typ,)*) -> Result<$ret> { use reqwest::multipart::Form; let form_data = Form::new() @@ -158,7 +158,7 @@ macro_rules! route { $url, "`\n# Errors\nIf `access_token` is not set."), - pub fn $name(&self, $($param: $typ,)*) -> Result<$ret> { + fn $name(&self, $($param: $typ,)*) -> Result<$ret> { let form_data = json!({ $( @@ -192,7 +192,7 @@ macro_rules! route { "Equivalent to `/api/v1/", $url, "`\n# Errors\nIf `access_token` is not set."), - pub fn $name(&self) -> Result<$ret> { + fn $name(&self) -> Result<$ret> { self.$method(self.route(concat!("/api/v1/", $url))) } } @@ -212,7 +212,7 @@ macro_rules! route_id { "Equivalent to `/api/v1/", $url, "`\n# Errors\nIf `access_token` is not set."), - pub fn $name(&self, id: u64) -> Result<$ret> { + fn $name(&self, id: u64) -> Result<$ret> { self.$method(self.route(&format!(concat!("/api/v1/", $url), id))) } } @@ -228,7 +228,7 @@ macro_rules! paged_routes_with_id { "Equivalent to `/api/v1/", $url, "`\n# Errors\nIf `access_token` is not set."), - pub fn $name(&self, id: &str) -> Result> { + fn $name(&self, id: &str) -> Result> { let url = self.route(&format!(concat!("/api/v1/", $url), id)); let response = self.client.$method(&url) .headers(self.headers.clone()) @@ -433,6 +433,57 @@ impl<'a> StatusesRequest<'a> { } } +#[allow(unused)] +pub trait MastodonClient { + fn favourites(&self) -> Result> { unimplemented!("This method was not implemented"); } + fn blocks(&self) -> Result> { unimplemented!("This method was not implemented"); } + fn domain_blocks(&self) -> Result> { unimplemented!("This method was not implemented"); } + fn follow_requests(&self) -> Result> { unimplemented!("This method was not implemented"); } + fn get_home_timeline(&self) -> Result> { unimplemented!("This method was not implemented"); } + fn get_emojis(&self) -> Result> { unimplemented!("This method was not implemented"); } + fn mutes(&self) -> Result> { unimplemented!("This method was not implemented"); } + fn notifications(&self) -> Result> { unimplemented!("This method was not implemented"); } + fn reports(&self) -> Result> { unimplemented!("This method was not implemented"); } + fn followers(&self, id: &str) -> Result> { unimplemented!("This method was not implemented"); } + fn following(&self) -> Result { unimplemented!("This method was not implemented"); } + fn reblogged_by(&self) -> Result { unimplemented!("This method was not implemented"); } + fn favourited_by(&self) -> Result { unimplemented!("This method was not implemented"); } + fn unblock_domain(&self, domain: String) -> Result { unimplemented!("This method was not implemented"); } + fn instance(&self) -> Result { unimplemented!("This method was not implemented"); } + fn verify_credentials(&self) -> Result { unimplemented!("This method was not implemented"); } + fn report(&self, account_id: &str, status_ids: Vec<&str>, comment: String) -> Result { unimplemented!("This method was not implemented"); } + fn block_domain(&self, domain: String) -> Result { unimplemented!("This method was not implemented"); } + fn authorize_follow_request(&self, id: &str) -> Result { unimplemented!("This method was not implemented"); } + fn reject_follow_request(&self, id: &str) -> Result { unimplemented!("This method was not implemented"); } + fn search(&self, q: String, resolve: bool) -> Result { unimplemented!("This method was not implemented"); } + fn follows(&self, uri: Cow<'static, str>) -> Result { unimplemented!("This method was not implemented"); } + fn media(&self, file: Cow<'static, str>) -> Result { unimplemented!("This method was not implemented"); } + fn clear_notifications(&self) -> Result { unimplemented!("This method was not implemented"); } + fn get_account(&self, id: u64) -> Result { unimplemented!("This method was not implemented"); } + fn follow(&self, id: u64) -> Result { unimplemented!("This method was not implemented"); } + fn unfollow(&self, id: u64) -> Result { unimplemented!("This method was not implemented"); } + fn block(&self, id: u64) -> Result { unimplemented!("This method was not implemented"); } + fn unblock(&self, id: u64) -> Result { unimplemented!("This method was not implemented"); } + fn mute(&self, id: u64) -> Result { unimplemented!("This method was not implemented"); } + fn unmute(&self, id: u64) -> Result { unimplemented!("This method was not implemented"); } + fn get_notification(&self, id: u64) -> Result { unimplemented!("This method was not implemented"); } + fn get_status(&self, id: u64) -> Result { unimplemented!("This method was not implemented"); } + fn get_context(&self, id: u64) -> Result { unimplemented!("This method was not implemented"); } + fn get_card(&self, id: u64) -> Result { unimplemented!("This method was not implemented"); } + fn reblog(&self, id: u64) -> Result { unimplemented!("This method was not implemented"); } + fn unreblog(&self, id: u64) -> Result { unimplemented!("This method was not implemented"); } + fn favourite(&self, id: u64) -> Result { unimplemented!("This method was not implemented"); } + fn unfavourite(&self, id: u64) -> Result { unimplemented!("This method was not implemented"); } + fn delete_status(&self, id: u64) -> Result { unimplemented!("This method was not implemented"); } + fn update_credentials(&self, changes: CredientialsBuilder) -> Result { unimplemented!("This method was not implemented"); } + fn new_status(&self, status: StatusBuilder) -> Result { unimplemented!("This method was not implemented"); } + fn get_public_timeline(&self, local: bool) -> Result> { unimplemented!("This method was not implemented"); } + fn get_tagged_timeline(&self, hashtag: String, local: bool) -> Result> { unimplemented!("This method was not implemented"); } + fn statuses<'a, 'b: 'a, S>(&'b self, id: &'b str, request: S) -> Result> where S: Into>> { unimplemented!("This method was not implemented"); } + fn relationships(&self, ids: &[&str]) -> Result> { unimplemented!("This method was not implemented"); } + fn search_accounts(&self, query: &str, limit: Option, following: bool) -> Result> { unimplemented!("This method was not implemented"); } +} + impl Mastodon { fn from_registration(base: I, client_id: I, @@ -474,6 +525,17 @@ impl Mastodon { } } + methods![get, post, delete,]; + + fn route(&self, url: &str) -> String { + let mut s = (*self.base).to_owned(); + s += url; + s + } +} + +impl MastodonClient for Mastodon { + paged_routes! { (get) favourites: "favourites" => Status, (get) blocks: "blocks" => Account, @@ -526,7 +588,7 @@ impl Mastodon { (delete) delete_status: "statuses/{}" => Empty, } - pub fn update_credentials(&self, changes: CredientialsBuilder) + fn update_credentials(&self, changes: CredientialsBuilder) -> Result { @@ -548,7 +610,7 @@ impl Mastodon { } /// Post a new status to the account. - pub fn new_status(&self, status: StatusBuilder) -> Result { + fn new_status(&self, status: StatusBuilder) -> Result { let response = self.client.post(&self.route("/api/v1/statuses")) .headers(self.headers.clone()) @@ -559,7 +621,7 @@ impl Mastodon { } /// Get the federated timeline for the instance. - pub fn get_public_timeline(&self, local: bool) -> Result> { + fn get_public_timeline(&self, local: bool) -> Result> { let mut url = self.route("/api/v1/timelines/public"); if local { @@ -571,7 +633,7 @@ impl Mastodon { /// Get timeline filtered by a hashtag(eg. `#coffee`) either locally or /// federated. - pub fn get_tagged_timeline(&self, hashtag: String, local: bool) -> Result> { + fn get_tagged_timeline(&self, hashtag: String, local: bool) -> Result> { let mut url = self.route("/api/v1/timelines/tag/"); url += &hashtag; @@ -589,7 +651,7 @@ impl Mastodon { /// /// ```no_run /// # extern crate mammut; - /// # use mammut::{Data, Mastodon}; + /// # use mammut::{Data, Mastodon, MastodonClient}; /// # use std::error::Error; /// # fn main() -> Result<(), Box> { /// # let data = Data { @@ -607,7 +669,7 @@ impl Mastodon { /// /// ```no_run /// # extern crate mammut; - /// # use mammut::{Data, Mastodon, StatusesRequest}; + /// # use mammut::{Data, Mastodon, MastodonClient, StatusesRequest}; /// # use std::error::Error; /// # fn main() -> Result<(), Box> { /// # let data = Data { @@ -624,7 +686,7 @@ impl Mastodon { /// # Ok(()) /// # } /// ``` - pub fn statuses<'a, S>(&self, id: &str, request: S) -> Result> + fn statuses<'a, 'b: 'a, S>(&'b self, id: &'b str, request: S) -> Result> where S: Into>> { let mut url = format!("{}/api/v1/accounts/{}/statuses", self.base, id); @@ -642,7 +704,7 @@ impl Mastodon { /// Returns the client account's relationship to a list of other accounts. /// Such as whether they follow them or vice versa. - pub fn relationships(&self, ids: &[&str]) -> Result> { + fn relationships(&self, ids: &[&str]) -> Result> { let mut url = self.route("/api/v1/accounts/relationships?"); if ids.len() == 1 { @@ -667,7 +729,7 @@ impl Mastodon { /// Search for accounts by their name. /// Will lookup an account remotely if the search term is in the /// `username@domain` format and not yet in the database. - pub fn search_accounts(&self, + fn search_accounts(&self, query: &str, limit: Option, following: bool) @@ -685,14 +747,6 @@ impl Mastodon { Page::new(self, response) } - - methods![get, post, delete,]; - - fn route(&self, url: &str) -> String { - let mut s = (*self.base).to_owned(); - s += url; - s - } } impl ops::Deref for Mastodon { diff --git a/src/registration.rs b/src/registration.rs index 08ed2d6..b977dcf 100644 --- a/src/registration.rs +++ b/src/registration.rs @@ -52,7 +52,7 @@ impl Registration { /// # try().unwrap(); /// # } /// # fn try() -> mammut::Result<()> { - /// use mammut::Registration; + /// use mammut::{MastodonClient, Registration}; /// use mammut::apps::{AppBuilder, Scopes}; /// /// let app = AppBuilder {