You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.4 KiB
57 lines
1.4 KiB
6 years ago
|
#![cfg_attr(not(feature = "toml"), allow(dead_code))]
|
||
|
#![cfg_attr(not(feature = "toml"), allow(unused_imports))]
|
||
6 years ago
|
|
||
6 years ago
|
pub use elefren::prelude::*;
|
||
6 years ago
|
|
||
6 years ago
|
use std::{error::Error, io};
|
||
6 years ago
|
|
||
6 years ago
|
use elefren::helpers::cli;
|
||
6 years ago
|
#[cfg(feature = "toml")]
|
||
6 years ago
|
use elefren::helpers::toml;
|
||
6 years ago
|
|
||
6 years ago
|
#[allow(dead_code)]
|
||
6 years ago
|
#[cfg(feature = "toml")]
|
||
6 years ago
|
fn main() -> Result<(), Box<Error>> {
|
||
|
register()?;
|
||
|
Ok(())
|
||
|
}
|
||
|
|
||
|
#[allow(dead_code)]
|
||
6 years ago
|
#[cfg(feature = "toml")]
|
||
6 years ago
|
pub fn get_mastodon_data() -> Result<Mastodon, Box<Error>> {
|
||
6 years ago
|
if let Ok(data) = toml::from_file("mastodon-data.toml") {
|
||
6 years ago
|
Ok(Mastodon::from(data))
|
||
6 years ago
|
} else {
|
||
|
register()
|
||
|
}
|
||
|
}
|
||
|
|
||
6 years ago
|
#[cfg(feature = "toml")]
|
||
6 years ago
|
pub fn register() -> Result<Mastodon, Box<Error>> {
|
||
6 years ago
|
let website = read_line("Please enter your mastodon instance url:")?;
|
||
6 years ago
|
let registration = Registration::new(website.trim())
|
||
6 years ago
|
.client_name("elefren-examples")
|
||
6 years ago
|
.scopes(Scopes::all())
|
||
6 years ago
|
.website("https://github.com/pwoolcoc/elefren")
|
||
6 years ago
|
.build()?;
|
||
6 years ago
|
let mastodon = cli::authenticate(registration)?;
|
||
6 years ago
|
|
||
|
// Save app data for using on the next run.
|
||
6 years ago
|
toml::to_file(&*mastodon, "mastodon-data.toml")?;
|
||
6 years ago
|
|
||
|
Ok(mastodon)
|
||
|
}
|
||
|
|
||
6 years ago
|
#[cfg(feature = "toml")]
|
||
6 years ago
|
pub fn read_line(message: &str) -> Result<String, Box<Error>> {
|
||
|
println!("{}", message);
|
||
|
|
||
|
let mut input = String::new();
|
||
|
io::stdin().read_line(&mut input)?;
|
||
|
|
||
6 years ago
|
Ok(input.trim().to_string())
|
||
6 years ago
|
}
|
||
6 years ago
|
|
||
|
#[cfg(not(feature = "toml"))]
|
||
6 years ago
|
fn main() {}
|