2022-12-05 13:52:48 +00:00
|
|
|
//! # Elefren: API Wrapper around the Mastodon API.
|
2022-11-27 14:44:43 +00:00
|
|
|
//!
|
|
|
|
//! Most of the api is documented on [Mastodon's website](https://docs.joinmastodon.org/client/intro/)
|
|
|
|
//!
|
|
|
|
//! ```no_run
|
|
|
|
//! use elefren::{helpers::cli, prelude::*};
|
2022-12-05 13:52:48 +00:00
|
|
|
//! use futures_util::StreamExt;
|
2022-11-27 14:44:43 +00:00
|
|
|
//!
|
2022-12-05 13:52:48 +00:00
|
|
|
//! tokio_test::block_on(async {
|
|
|
|
//! let registration = Registration::new("https://botsin.space")
|
|
|
|
//! .client_name("elefren_test")
|
|
|
|
//! .build()
|
|
|
|
//! .await
|
|
|
|
//! .unwrap();
|
|
|
|
//! let mastodon = cli::authenticate(registration).await.unwrap();
|
2022-11-27 14:44:43 +00:00
|
|
|
//!
|
2022-12-05 13:52:48 +00:00
|
|
|
//! println!(
|
|
|
|
//! "{:?}",
|
|
|
|
//! mastodon
|
|
|
|
//! .get_home_timeline()
|
|
|
|
//! .await
|
|
|
|
//! .unwrap()
|
|
|
|
//! .items_iter()
|
|
|
|
//! .take(100)
|
|
|
|
//! .collect::<Vec<_>>()
|
|
|
|
//! .await
|
|
|
|
//! );
|
|
|
|
//! });
|
2022-11-27 14:44:43 +00:00
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
//! Elefren also supports Mastodon's Streaming API:
|
|
|
|
//!
|
2022-12-05 13:52:48 +00:00
|
|
|
//! ## Example
|
2022-11-27 14:44:43 +00:00
|
|
|
//!
|
|
|
|
//! ```no_run
|
2022-11-29 23:50:29 +00:00
|
|
|
//! use elefren::{prelude::*, entities::event::Event};
|
2022-12-05 13:52:48 +00:00
|
|
|
//! use futures_util::TryStreamExt;
|
|
|
|
//!
|
2022-11-29 23:50:29 +00:00
|
|
|
//! let data = Data::default();
|
2022-11-27 14:44:43 +00:00
|
|
|
//! let client = Mastodon::from(data);
|
2022-12-05 13:52:48 +00:00
|
|
|
//! tokio_test::block_on(async {
|
2022-12-22 17:27:30 +00:00
|
|
|
//! let stream = client.stream_user().await.unwrap();
|
2022-12-05 13:52:48 +00:00
|
|
|
//! stream.try_for_each(|event| async move {
|
|
|
|
//! match event {
|
|
|
|
//! Event::Update(ref status) => { /* .. */ },
|
|
|
|
//! Event::Notification(ref notification) => { /* .. */ },
|
|
|
|
//! Event::Delete(ref id) => { /* .. */ },
|
|
|
|
//! Event::FiltersChanged => { /* .. */ },
|
|
|
|
//! }
|
|
|
|
//! Ok(())
|
|
|
|
//! }).await.unwrap();
|
|
|
|
//! });
|
2022-11-27 14:44:43 +00:00
|
|
|
//! ```
|
|
|
|
|
|
|
|
#![deny(
|
|
|
|
missing_docs,
|
|
|
|
warnings,
|
|
|
|
missing_debug_implementations,
|
|
|
|
missing_copy_implementations,
|
|
|
|
trivial_casts,
|
|
|
|
trivial_numeric_casts,
|
|
|
|
unsafe_code,
|
|
|
|
unstable_features,
|
|
|
|
unused_import_braces,
|
|
|
|
unused_qualifications
|
|
|
|
)]
|
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate doc_comment;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_json;
|
2022-11-29 23:50:29 +00:00
|
|
|
#[macro_use]
|
2022-11-27 14:44:43 +00:00
|
|
|
extern crate serde;
|
|
|
|
|
|
|
|
#[cfg(feature = "env")]
|
|
|
|
extern crate envy;
|
|
|
|
|
|
|
|
#[cfg(feature = "toml")]
|
|
|
|
extern crate toml as tomlcrate;
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
extern crate tempfile;
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
#[cfg_attr(all(test, any(feature = "toml", feature = "json")), macro_use)]
|
|
|
|
extern crate indoc;
|
|
|
|
|
|
|
|
use page::Page;
|
|
|
|
|
|
|
|
pub use data::Data;
|
|
|
|
pub use errors::{ApiError, Error, Result};
|
|
|
|
pub use isolang::Language;
|
2022-12-05 13:52:48 +00:00
|
|
|
pub use mastodon::{Mastodon, MastodonUnauthenticated};
|
|
|
|
// pub use mastodon_client::{MastodonClient, MastodonUnauthenticated};
|
2022-11-27 14:44:43 +00:00
|
|
|
pub use registration::Registration;
|
|
|
|
pub use requests::{
|
|
|
|
AddFilterRequest,
|
|
|
|
AddPushRequest,
|
|
|
|
StatusesRequest,
|
|
|
|
UpdateCredsRequest,
|
|
|
|
UpdatePushRequest,
|
|
|
|
};
|
2022-12-18 21:06:30 +00:00
|
|
|
pub use status_builder::{NewStatus, StatusBuilder, Visibility};
|
2022-11-27 14:44:43 +00:00
|
|
|
|
|
|
|
/// Registering your App
|
|
|
|
pub mod apps;
|
|
|
|
/// Contains the struct that holds the client auth data
|
|
|
|
pub mod data;
|
|
|
|
/// Entities returned from the API
|
|
|
|
pub mod entities;
|
|
|
|
/// Errors
|
|
|
|
pub mod errors;
|
2022-12-05 13:52:48 +00:00
|
|
|
/// Event stream generators
|
|
|
|
pub mod event_stream;
|
2022-11-27 14:44:43 +00:00
|
|
|
/// Collection of helpers for serializing/deserializing `Data` objects
|
|
|
|
pub mod helpers;
|
|
|
|
/// Handling multiple pages of entities.
|
|
|
|
pub mod page;
|
|
|
|
/// Registering your app.
|
|
|
|
pub mod registration;
|
|
|
|
/// Requests
|
|
|
|
pub mod requests;
|
|
|
|
/// OAuth Scopes
|
|
|
|
pub mod scopes;
|
|
|
|
/// Constructing a status
|
|
|
|
pub mod status_builder;
|
|
|
|
#[macro_use]
|
|
|
|
mod macros;
|
|
|
|
/// Automatically import the things you need
|
|
|
|
pub mod prelude {
|
2022-11-29 23:50:29 +00:00
|
|
|
pub use crate::{
|
|
|
|
scopes::Scopes,
|
2022-12-18 21:06:30 +00:00
|
|
|
status_builder::Visibility,
|
2022-11-29 23:50:29 +00:00
|
|
|
Data,
|
|
|
|
Mastodon,
|
2022-12-05 13:52:48 +00:00
|
|
|
// MastodonClient,
|
2022-11-29 23:50:29 +00:00
|
|
|
NewStatus,
|
|
|
|
Registration,
|
|
|
|
StatusBuilder,
|
|
|
|
StatusesRequest,
|
|
|
|
};
|
2022-11-27 14:44:43 +00:00
|
|
|
}
|
2022-12-05 13:52:48 +00:00
|
|
|
/// The mastodon client
|
|
|
|
pub mod mastodon;
|