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§

Modules§

Macros§

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

Enums§