mastodon_async/lib.rs
1//! # mastodon-async: API Wrapper around the Mastodon API.
2//!
3//! Most of the api is documented on [Mastodon's website](https://docs.joinmastodon.org/client/intro/)
4//!
5//! ```no_run
6//! use mastodon_async::{helpers::cli, prelude::*};
7//! use futures_util::StreamExt;
8//!
9//! tokio_test::block_on(async {
10//! let registration = Registration::new("https://botsin.space")
11//! .client_name("mastodon-async_test")
12//! .build()
13//! .await
14//! .unwrap();
15//! let mastodon = cli::authenticate(registration).await.unwrap();
16//!
17//! println!(
18//! "{:?}",
19//! mastodon
20//! .get_home_timeline()
21//! .await
22//! .unwrap()
23//! .items_iter()
24//! .take(100)
25//! .collect::<Vec<_>>()
26//! .await
27//! );
28//! });
29//! ```
30//!
31//! mastodon-async also supports Mastodon's Streaming API:
32//!
33//! ## Example
34//!
35//! ```no_run
36//! use mastodon_async::{prelude::*, entities::event::Event};
37//! use futures_util::TryStreamExt;
38//!
39//! let data = Data::default();
40//! let client = Mastodon::from(data);
41//! tokio_test::block_on(async {
42//! let stream = client.stream_user().await.unwrap();
43//! stream.try_for_each(|(event, _client)| async move {
44//! match event {
45//! Event::Update(ref status) => { /* .. */ },
46//! Event::Notification(ref notification) => { /* .. */ },
47//! Event::Delete(ref id) => { /* .. */ },
48//! Event::FiltersChanged => { /* .. */ },
49//! }
50//! Ok(())
51//! }).await.unwrap();
52//! });
53//! ```
54
55#![deny(
56 missing_docs,
57 warnings,
58 missing_debug_implementations,
59 missing_copy_implementations,
60 trivial_casts,
61 trivial_numeric_casts,
62 unsafe_code,
63 unstable_features,
64 unused_import_braces,
65 unused_qualifications
66)]
67
68#[macro_use]
69extern crate doc_comment;
70#[macro_use]
71extern crate serde_json;
72#[macro_use]
73extern crate serde;
74
75#[cfg(feature = "env")]
76extern crate envy;
77
78#[cfg(feature = "toml")]
79extern crate toml as tomlcrate;
80
81#[cfg(test)]
82extern crate tempfile;
83
84#[cfg(test)]
85#[cfg_attr(all(test, any(feature = "toml", feature = "json")), macro_use)]
86extern crate indoc;
87
88use page::Page;
89
90pub use data::Data;
91pub use errors::{ApiError, Error, Result};
92pub use isolang::Language;
93pub use mastodon::{Mastodon, MastodonUnauthenticated};
94// pub use mastodon_client::{MastodonClient, MastodonUnauthenticated};
95pub use mastodon_async_entities::visibility::Visibility;
96pub use registration::Registration;
97pub use requests::{
98 AddFilterRequest, AddPushRequest, StatusesRequest, UpdateCredsRequest, UpdatePushRequest,
99};
100pub use status_builder::{NewStatus, StatusBuilder};
101
102/// Registering your App
103pub mod apps;
104/// Contains the struct that holds the client auth data
105pub mod data;
106/// Entities returned from the API
107pub mod entities;
108/// Errors
109pub mod errors;
110/// Event stream generators
111pub mod event_stream;
112/// Collection of helpers for serializing/deserializing `Data` objects
113pub mod helpers;
114/// Handling multiple pages of entities.
115pub mod page;
116/// Registering your app.
117pub mod registration;
118/// Requests
119pub mod requests;
120/// OAuth Scopes
121pub mod scopes;
122/// Constructing a status
123pub mod status_builder;
124#[macro_use]
125mod macros;
126/// How much time to wait before checking an endpoint again.
127pub mod polling_time;
128/// Automatically import the things you need
129pub mod prelude {
130 pub use crate::{
131 entities::prelude::*,
132 scopes::Scopes,
133 Data,
134 Mastodon,
135 // MastodonClient,
136 NewStatus,
137 Registration,
138 StatusBuilder,
139 StatusesRequest,
140 Visibility,
141 };
142}
143/// The mastodon client
144pub mod mastodon;