1
- # Elefren
1
+ # Async Mastodon client library
2
2
3
- ## A Wrapper for the Mastodon API.
3
+ [ ![ Build Status] ( https://github.com/dscottboggs/mastodon-async/actions/workflows/rust.yml/badge.svg )]
4
+ [ ![ crates.io] ( https://img.shields.io/crates/v/mastodon-async.svg )] ( https://crates.io/crates/mastodon-async )
5
+ [ ![ Docs] ( https://docs.rs/mastodon-async/badge.svg )] ( https://docs.rs/mastodon-async )
6
+ [ ![ MIT/APACHE-2.0] ( https://img.shields.io/crates/l/mastodon-async.svg )] ( https://crates.io/crates/mastodon-async )
4
7
5
- [ ![ Build Status] ( https://github.com/dscottboggs/elefren/actions/workflows/rust.yml/badge.svg )] ( https://travis-ci.org/pwoolcoc/elefren )
6
- <!-- [](https://coveralls.io/github/pwoolcoc/elefren?branch=master) -->
7
- <!-- [](https://crates.io/crates/elefren) -->
8
- <!-- [](https://docs.rs/elefren) -->
9
- <!-- [](https://crates.io/crates/elefren) -->
8
+ [ Documentation] ( https://docs.rs/mastodon-async/ )
10
9
11
- [ Documentation] ( https://docs.rs/elefren/ )
12
-
13
- A wrapper around the [ API] ( https://github.com/tootsuite/documentation/blob/master/docs/Using-the-API/API.md#tag ) for [ Mastodon] ( https://botsin.space/ )
10
+ A type-safe, async wrapper around the client [ API] ( https://github.com/tootsuite/documentation/blob/master/docs/Using-the-API/API.md#tag )
11
+ for [ Mastodon] ( https://botsin.space/ )
14
12
15
13
## Installation
16
14
17
- To add ` elefren ` to your project, add the following to the
15
+ To add ` mastodon-async ` to your project, add the following to the
18
16
` [dependencies] ` section of your ` Cargo.toml `
19
17
20
18
``` toml
21
- elefren = " 0.23 "
19
+ mastodon-async = " 1.0 "
22
20
```
23
21
24
22
Alternatively, run the following command:
25
23
26
24
~~~ console
27
- $ cargo add elefren
25
+ $ cargo add mastodon-async
28
26
~~~
29
27
30
28
## Example
31
29
32
30
In your ` Cargo.toml ` , make sure you enable the ` toml ` feature:
33
31
34
32
``` toml
35
- [dependencies ]
36
- elefren = { version = " 0.22" , features = [" toml" ] }
33
+ [dependencies .mastodon-async ]
34
+ version = " 1.0"
35
+ features = [" toml" ]
37
36
```
38
37
39
38
``` rust,no_run
40
39
// src/main.rs
41
40
42
- use std::error::Error;
43
-
44
- use elefren::prelude::*;
45
- use elefren::helpers::toml; // requires `features = ["toml"]`
46
- use elefren::helpers::cli;
41
+ use mastodon_async::prelude::*;
42
+ use mastodon_async::helpers::toml; // requires `features = ["toml"]`
43
+ use mastodon_async::{helpers::cli, Result};
47
44
48
45
#[tokio::main]
49
- async fn main() -> Result<(), Box<dyn Error> > {
46
+ async fn main() -> Result<()> {
50
47
let mastodon = if let Ok(data) = toml::from_file("mastodon-data.toml") {
51
48
Mastodon::from(data)
52
49
} else {
53
- register()?
50
+ register().await ?
54
51
};
55
52
56
53
let you = mastodon.verify_credentials().await?;
@@ -60,14 +57,15 @@ async fn main() -> Result<(), Box<dyn Error>> {
60
57
Ok(())
61
58
}
62
59
63
- fn register() -> Result<Mastodon, Box<dyn Error> > {
60
+ async fn register() -> Result<Mastodon> {
64
61
let registration = Registration::new("https://botsin.space")
65
- .client_name("elefren-examples")
66
- .build()?;
67
- let mastodon = cli::authenticate(registration)?;
62
+ .client_name("mastodon-async-examples")
63
+ .build()
64
+ .await?;
65
+ let mastodon = cli::authenticate(registration).await?;
68
66
69
67
// Save app data for using on the next run.
70
- toml::to_file(&* mastodon, "mastodon-data.toml")?;
68
+ toml::to_file(&mastodon.data , "mastodon-data.toml")?;
71
69
72
70
Ok(mastodon)
73
71
}
@@ -76,24 +74,23 @@ fn register() -> Result<Mastodon, Box<dyn Error>> {
76
74
It also supports the [ Streaming API] ( https://docs.joinmastodon.org/api/streaming ) :
77
75
78
76
``` rust,no_run
79
- use elefren::prelude::*;
80
- use elefren::entities::event::Event;
81
-
82
- use std::error::Error;
77
+ use mastodon_async::{prelude::*, Result, entities::event::Event};
78
+ use futures_util::TryStreamExt;
83
79
84
80
#[tokio::main]
85
- async fn main() -> Result<(), Box<Error> > {
81
+ async fn main() -> Result<()> {
86
82
let client = Mastodon::from(Data::default());
87
83
88
84
client.stream_user()
89
85
.await?
90
- .try_for_each(|event| {
86
+ .try_for_each(|event| async move {
91
87
match event {
92
88
Event::Update(ref status) => { /* .. */ },
93
89
Event::Notification(ref notification) => { /* .. */ },
94
90
Event::Delete(ref id) => { /* .. */ },
95
91
Event::FiltersChanged => { /* .. */ },
96
92
}
93
+ Ok(())
97
94
})
98
95
.await?;
99
96
Ok(())
0 commit comments