small readme updates
This commit is contained in:
@@ -25,56 +25,55 @@ elefren = "0.12"
|
|||||||
|
|
||||||
To use this crate in your project, add this to your crate root (lib.rs, main.rs, etc):
|
To use this crate in your project, add this to your crate root (lib.rs, main.rs, etc):
|
||||||
|
|
||||||
```rust
|
```rust,ignore
|
||||||
extern crate elefren;
|
extern crate elefren;
|
||||||
```
|
```
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
```rust
|
```rust,no_run
|
||||||
extern crate elefren;
|
extern crate elefren;
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::fs::File;
|
use std::error::Error;
|
||||||
use std::io::prelude::*;
|
|
||||||
|
|
||||||
use elefren::{Data, Mastodon, Registration};
|
use elefren::prelude::*;
|
||||||
use elefren::apps::{AppBuilder, Scopes};
|
use elefren::apps::prelude::*;
|
||||||
use elefren::data::toml; // requires `features = ["toml"]`
|
use elefren::data::toml; // requires `features = ["toml"]`
|
||||||
|
|
||||||
fn main() {
|
fn main() -> Result<(), Box<Error>> {
|
||||||
let mastodon = match toml::from_file("mastodon-data.toml") {
|
let mastodon = if let Ok(data) = toml::from_file("mastodon-data.toml") {
|
||||||
Ok(data) => {
|
Mastodon::from(data)
|
||||||
Mastodon::from(data)
|
} else {
|
||||||
},
|
register()?
|
||||||
Err(_) => register(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let you = mastodon.verify_credentials().unwrap();
|
let you = mastodon.verify_credentials()?;
|
||||||
|
|
||||||
println!("{:#?}", you);
|
println!("{:#?}", you);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register() -> Mastodon {
|
fn register() -> Result<Mastodon, Box<Error>> {
|
||||||
let mut app = App::builder();
|
let mut app = App::builder();
|
||||||
app.client_name("elefren-examples");
|
app.client_name("elefren-examples");
|
||||||
|
|
||||||
let registration = Registration::new("https://mastodon.social");
|
let registration = Registration::new("https://mastodon.social")
|
||||||
.register(app).unwrap();
|
.register(app)?;
|
||||||
let url = registration.authorize_url().unwrap();
|
let url = registration.authorize_url()?;
|
||||||
|
|
||||||
println!("Click this link to authorize on Mastodon: {}", url);
|
println!("Click this link to authorize on Mastodon: {}", url);
|
||||||
println!("Paste the returned authorization code: ");
|
println!("Paste the returned authorization code: ");
|
||||||
|
|
||||||
let mut input = String::new();
|
let mut input = String::new();
|
||||||
io::stdin().read_line(&mut input).unwrap();
|
io::stdin().read_line(&mut input)?;
|
||||||
|
|
||||||
let code = input.trim().to_string();
|
let code = input.trim().to_string();
|
||||||
let mastodon = registration.complete(code).unwrap();
|
let mastodon = registration.complete(code)?;
|
||||||
|
|
||||||
// Save app data for using on the next run.
|
// Save app data for using on the next run.
|
||||||
toml::to_file(&*mastodon, "mastodon-data.toml").unwrap();
|
toml::to_file(&*mastodon, "mastodon-data.toml")?;
|
||||||
|
|
||||||
mastodon
|
Ok(mastodon)
|
||||||
}
|
}
|
||||||
```
|
|
||||||
|
|||||||
Reference in New Issue
Block a user