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>

source

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");
source

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>

source

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

source

pub fn redirect_uris<I: Into<Cow<'a, str>>>(&mut self, uris: I) -> &mut Self

Sets the redirect uris that this app uses

source

pub fn scopes(&mut self, scopes: Scopes) -> &mut Self

Sets the scopes that this app requires

The default for an app is Scopes::Read

source

pub fn website<I: Into<Cow<'a, str>>>(&mut self, website: I) -> &mut Self

Sets the optional “website” to register the app with

source

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

source

pub async fn register<I: TryInto<App>>(&mut self, app: I) -> Result<Registered>
where Error: From<<I as TryInto<App>>::Error>,

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);
});
source

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>

source§

fn clone(&self) -> Registration<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for Registration<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Registration<'a>

§

impl<'a> Send for Registration<'a>

§

impl<'a> Sync for Registration<'a>

§

impl<'a> Unpin for Registration<'a>

§

impl<'a> !UnwindSafe for Registration<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more