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§
- Registering your App
- Contains the struct that holds the client auth data
- Entities returned from the API
- Errors
- Event stream generators
- Collection of helpers for serializing/deserializing
Data
objects - The mastodon client
- Handling multiple pages of entities.
- How much time to wait before checking an endpoint again.
- Automatically import the things you need
- Registering your app.
- Requests
- OAuth Scopes
- Constructing a status
Macros§
- Used to easily create errors from strings
- Log metadata about this request based on the type given:
Enums§
- The visibility of a status.