Struct mastodon_async::registration::Registration
source · pub struct Registration<'a> { /* private fields */ }
Expand description
Handles registering your mastodon app to your instance. It is recommended you cache your data struct to avoid registering on every run.
Implementations§
source§impl<'a> Registration<'a>
impl<'a> Registration<'a>
sourcepub fn new<I: Into<String>>(base: I) -> Self
pub fn new<I: Into<String>>(base: I) -> Self
Construct a new registration process to the instance of the base
url.
use mastodon_async::prelude::*;
let registration = Registration::new("https://botsin.space");
sourcepub fn new_with_client<I: Into<String>>(base: I, client: Client) -> Self
pub fn new_with_client<I: Into<String>>(base: I, client: Client) -> Self
Construct a new registration process to the instance of the base
url,
using the provided Client.
use mastodon_async::prelude::*;
let client = reqwest::Client::builder().user_agent("my cool app").build().unwrap();
let registration = Registration::new_with_client("https://botsin.space", client);
source§impl<'a> Registration<'a>
impl<'a> Registration<'a>
sourcepub fn client_name<I: Into<Cow<'a, str>>>(&mut self, name: I) -> &mut Self
pub fn client_name<I: Into<Cow<'a, str>>>(&mut self, name: I) -> &mut Self
Sets the name of this app
This is required, and if this isn’t set then the AppBuilder::build method will fail
sourcepub fn redirect_uris<I: Into<Cow<'a, str>>>(&mut self, uris: I) -> &mut Self
pub fn redirect_uris<I: Into<Cow<'a, str>>>(&mut self, uris: I) -> &mut Self
Sets the redirect uris that this app uses
sourcepub fn scopes(&mut self, scopes: Scopes) -> &mut Self
pub fn scopes(&mut self, scopes: Scopes) -> &mut Self
Sets the scopes that this app requires
The default for an app is Scopes::Read
sourcepub fn website<I: Into<Cow<'a, str>>>(&mut self, website: I) -> &mut Self
pub fn website<I: Into<Cow<'a, str>>>(&mut self, website: I) -> &mut Self
Sets the optional “website” to register the app with
sourcepub fn force_login(&mut self, force_login: bool) -> &mut Self
pub fn force_login(&mut self, force_login: bool) -> &mut Self
Forces the user to re-login (useful if you need to re-auth as a different user on the same instance
sourcepub async fn register<I: TryInto<App>>(&mut self, app: I) -> Result<Registered>
pub async fn register<I: TryInto<App>>(&mut self, app: I) -> Result<Registered>
Register the given application
use mastodon_async::{apps::App, prelude::*};
tokio_test::block_on(async {
let mut app = App::builder();
app.client_name("mastodon-async_test");
let registration = Registration::new("https://botsin.space")
.register(app)
.await
.unwrap();
let url = registration.authorize_url().unwrap();
// Here you now need to open the url in the browser
// And handle a the redirect url coming back with the code.
let code = String::from("RETURNED_FROM_BROWSER");
let mastodon = registration.complete(&code).await.unwrap();
println!("{:?}", mastodon.get_home_timeline().await.unwrap().initial_items);
});
sourcepub async fn build(&mut self) -> Result<Registered>
pub async fn build(&mut self) -> Result<Registered>
Register the application with the server from the base
url.
use mastodon_async::prelude::*;
tokio_test::block_on(async {
let registration = Registration::new("https://botsin.space")
.client_name("mastodon-async_test")
.build()
.await
.unwrap();
let url = registration.authorize_url().unwrap();
// Here you now need to open the url in the browser
// And handle a the redirect url coming back with the code.
let code = String::from("RETURNED_FROM_BROWSER");
let mastodon = registration.complete(&code).await.unwrap();
println!("{:?}", mastodon.get_home_timeline().await.unwrap().initial_items);
});
Trait Implementations§
source§impl<'a> Clone for Registration<'a>
impl<'a> Clone for Registration<'a>
source§fn clone(&self) -> Registration<'a>
fn clone(&self) -> Registration<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more