diff options
author | Paul Woolcock <paul@woolcock.us> | 2018-10-03 05:12:37 -0400 |
---|---|---|
committer | Paul Woolcock <paul@woolcock.us> | 2018-10-10 10:28:22 -0400 |
commit | 4dd40422b3de11aaadcfc600317c0df3556b38f5 (patch) | |
tree | 88ee4f0549421ce8c35278df8dc0df146987571c | |
parent | d524a64bfd65d789b0dd54434a848fccba505471 (diff) |
feat(api): shortcut methods for following & followers
-rwxr-xr-x | examples/follows_me.rs | 25 | ||||
-rw-r--r-- | src/lib.rs | 12 | ||||
-rw-r--r-- | src/mastodon_client.rs | 43 |
3 files changed, 80 insertions, 0 deletions
diff --git a/examples/follows_me.rs b/examples/follows_me.rs new file mode 100755 index 0000000..c423b1c --- /dev/null +++ b/examples/follows_me.rs @@ -0,0 +1,25 @@ +#![cfg_attr(not(feature = "toml"), allow(dead_code))] +#![cfg_attr(not(feature = "toml"), allow(unused_imports))] +mod register; + +use register::MastodonClient; +use std::error; + +#[cfg(feature = "toml")] +fn main() -> Result<(), Box<error::Error>> { + let mastodon = register::get_mastodon_data()?; + for account in mastodon.follows_me()?.items_iter() { + println!("{}", account.acct); + } + + Ok(()) +} + +#[cfg(not(feature = "toml"))] +fn main() { + println!( + "examples require the `toml` feature, run this command for this example:\n\ncargo run \ + --example print_your_profile --features toml\n" + ); +} + @@ -407,6 +407,18 @@ impl<H: HttpSend> MastodonClient<H> for Mastodon<H> { deserialise(response) } + + /// Get all accounts that follow the authenticated user + fn follows_me(&self) -> Result<Page<Account, H>> { + let me = self.verify_credentials()?; + Ok(self.followers(&me.id)?) + } + + /// Get all accounts that the authenticated user follows + fn followed_by_me(&self) -> Result<Page<Account, H>> { + let me = self.verify_credentials()?; + Ok(self.following(&me.id)?) + } } impl<H: HttpSend> ops::Deref for Mastodon<H> { diff --git a/src/mastodon_client.rs b/src/mastodon_client.rs index ca8a98a..83a2948 100644 --- a/src/mastodon_client.rs +++ b/src/mastodon_client.rs @@ -273,4 +273,47 @@ pub trait MastodonClient<H: HttpSend = HttpSender> { fn unendorse_user(&self, id: &str) -> Result<Relationship> { unimplemented!("This method was not implemented"); } + /// Shortcut for: `let me = client.verify_credentials(); client.followers()` + /// + /// ```no_run + /// # extern crate elefren; + /// # use std::error::Error; + /// # use elefren::prelude::*; + /// # fn main() -> Result<(), Box<Error>> { + /// # let data = Data { + /// # base: "".into(), + /// # client_id: "".into(), + /// # client_secret: "".into(), + /// # redirect: "".into(), + /// # token: "".into(), + /// # }; + /// # let client = Mastodon::from(data); + /// let follows_me = client.follows_me()?; + /// # Ok(()) + /// # } + fn follows_me(&self) -> Result<Page<Account, H>> { + unimplemented!("This method was not implemented"); + } + /// Shortcut for + /// `let me = client.verify_credentials(); client.following(&me.id)` + /// + /// ```no_run + /// # extern crate elefren; + /// # use std::error::Error; + /// # use elefren::prelude::*; + /// # fn main() -> Result<(), Box<Error>> { + /// # let data = Data { + /// # base: "".into(), + /// # client_id: "".into(), + /// # client_secret: "".into(), + /// # redirect: "".into(), + /// # token: "".into(), + /// # }; + /// # let client = Mastodon::from(data); + /// let follows_me = client.followed_by_me()?; + /// # Ok(()) + /// # } + fn followed_by_me(&self) -> Result<Page<Account, H>> { + unimplemented!("This method was not implemented"); + } } |