Crate mastodon_async

Source
Expand description

§mastodon-async: API Wrapper around the Mastodon API.

Most of the api is documented on Mastodon’s website

use mastodon_async::{helpers::cli, prelude::*};
use futures_util::StreamExt;

tokio_test::block_on(async {
    let registration = Registration::new("https://botsin.space")
        .client_name("mastodon-async_test")
        .build()
        .await
        .unwrap();
    let mastodon = cli::authenticate(registration).await.unwrap();

    println!(
        "{:?}",
        mastodon
            .get_home_timeline()
            .await
            .unwrap()
            .items_iter()
            .take(100)
            .collect::<Vec<_>>()
            .await
    );
});

mastodon-async also supports Mastodon’s Streaming API:

§Example

use mastodon_async::{prelude::*, entities::event::Event};
use futures_util::TryStreamExt;

let data = Data::default();
let client = Mastodon::from(data);
tokio_test::block_on(async {
    let stream = client.stream_user().await.unwrap();
    stream.try_for_each(|(event, _client)| async move {
        match event {
            Event::Update(ref status) => { /* .. */ },
            Event::Notification(ref notification) => { /* .. */ },
            Event::Delete(ref id) => { /* .. */ },
            Event::FiltersChanged => { /* .. */ },
        }
        Ok(())
    }).await.unwrap();
});

Re-exports§

pub use data::Data;
pub use errors::ApiError;
pub use errors::Error;
pub use errors::Result;
pub use mastodon::Mastodon;
pub use mastodon::MastodonUnauthenticated;
pub use registration::Registration;
pub use requests::AddFilterRequest;
pub use requests::AddPushRequest;
pub use requests::StatusesRequest;
pub use requests::UpdateCredsRequest;
pub use requests::UpdatePushRequest;
pub use status_builder::NewStatus;
pub use status_builder::StatusBuilder;

Modules§

apps
Registering your App
data
Contains the struct that holds the client auth data
entities
Entities returned from the API
errors
Errors
event_stream
Event stream generators
helpers
Collection of helpers for serializing/deserializing Data objects
mastodon
The mastodon client
page
Handling multiple pages of entities.
polling_time
How much time to wait before checking an endpoint again.
prelude
Automatically import the things you need
registration
Registering your app.
requests
Requests
scopes
OAuth Scopes
status_builder
Constructing a status

Macros§

format_err
Used to easily create errors from strings
log_serde
Log metadata about this request based on the type given:

Enums§

Language
Visibility
The visibility of a status.