Add some docs for streaming

master
Paul Woolcock 5 years ago
parent eb1a676a98
commit f204ee190b
  1. 31
      README.md
  2. 58
      src/lib.rs

@ -76,6 +76,37 @@ fn register() -> Result<Mastodon, Box<Error>> {
}
```
It also supports the [Streaming API](https://docs.joinmastodon.org/api/streaming):
```no_run
use elefren::prelude::*;
use elefren::entities::event::Event;
use std::error::Error;
fn main() -> Result<(), Box<Error>> {
let data = Data {
base: "".into(),
client_id: "".into(),
client_secret: "".into(),
redirect: "".into(),
token: "".into(),
};
let client = Mastodon::from(data);
for event in client.streaming_user()? {
match event {
Event::Update(ref status) => { /* .. */ },
Event::Notification(ref notification) => { /* .. */ },
Event::Delete(ref id) => { /* .. */ },
Event::FiltersChanged => { /* .. */ },
}
}
Ok(())
}
```
## Relationship to [Mammut](https://github.com/Aaronepower/mammut)
This library was forked from Mammut around elefren commit

@ -27,6 +27,36 @@
//! # Ok(())
//! # }
//! ```
//!
//! Elefren also supports Mastodon's Streaming API:
//!
//! # Example
//!
//! ```no_run
//! # extern crate elefren;
//! # use elefren::prelude::*;
//! # use std::error::Error;
//! use elefren::entities::event::Event;
//! # fn main() -> Result<(), Box<Error>> {
//! # let data = Data {
//! # base: "".into(),
//! # client_id: "".into(),
//! # client_secret: "".into(),
//! # redirect: "".into(),
//! # token: "".into(),
//! # };
//! let client = Mastodon::from(data);
//! for event in client.streaming_user()? {
//! match event {
//! Event::Update(ref status) => { /* .. */ },
//! Event::Notification(ref notification) => { /* .. */ },
//! Event::Delete(ref id) => { /* .. */ },
//! Event::FiltersChanged => { /* .. */ },
//! }
//! }
//! # Ok(())
//! # }
//! ```
#![deny(
missing_docs,
@ -428,6 +458,34 @@ impl<H: HttpSend> MastodonClient<H> for Mastodon<H> {
/// returns events that are relevant to the authorized user, i.e. home
/// timeline & notifications
///
/// # Example
///
/// ```no_run
/// # extern crate elefren;
/// # use elefren::prelude::*;
/// # use std::error::Error;
/// use elefren::entities::event::Event;
/// # fn main() -> Result<(), Box<Error>> {
/// # let data = Data {
/// # base: "".into(),
/// # client_id: "".into(),
/// # client_secret: "".into(),
/// # redirect: "".into(),
/// # token: "".into(),
/// # };
/// let client = Mastodon::from(data);
/// for event in client.streaming_user()? {
/// match event {
/// Event::Update(ref status) => { /* .. */ },
/// Event::Notification(ref notification) => { /* .. */ },
/// Event::Delete(ref id) => { /* .. */ },
/// Event::FiltersChanged => { /* .. */ },
/// }
/// }
/// # Ok(())
/// # }
/// ```
fn streaming_user(&self) -> Result<Self::Stream> {
let response = self.send(self.client.get(&self.route("/api/v1/streaming/user")))?;
let reader = BufReader::new(response);

Loading…
Cancel
Save