Change `Mastodon::from_data` to just `Mastodon::from`

master
Paul Woolcock 6 years ago
parent 1847160369
commit cc083e335e
  1. 2
      README.md
  2. 5
      examples/register.rs
  3. 2
      src/entities/itemsiter.rs
  4. 24
      src/lib.rs

@ -25,7 +25,7 @@ fn main() {
let mut config = String::new();
file.read_to_string(&mut config).unwrap();
let data: Data = toml::from_str(&config).unwrap();
Mastodon::from_data(data)
Mastodon::from(data)
},
Err(_) => register(),
};

@ -1,7 +1,7 @@
extern crate elefren;
extern crate toml;
pub use self::elefren::MastodonClient;
pub use self::elefren::{Data, MastodonClient};
use std::{
error::Error,
@ -28,7 +28,8 @@ fn main() -> Result<(), Box<Error>> {
#[allow(dead_code)]
pub fn get_mastodon_data() -> Result<Mastodon, Box<Error>> {
if let Ok(config) = fs::read_to_string("mastodon-data.toml") {
Ok(Mastodon::from_data(toml::from_str(&config)?))
let data: Data = toml::from_str(&config)?;
Ok(Mastodon::from(data))
} else {
register()
}

@ -15,7 +15,7 @@ use serde::Deserialize;
/// # redirect: "".into(),
/// # token: "".into(),
/// # };
/// let client = Mastodon::from_data(data);
/// let client = Mastodon::from(data);
/// let statuses = client.statuses("user-id", None)?;
/// for status in statuses.items_iter() {
/// // do something with `status`

@ -438,8 +438,18 @@ impl Mastodon {
}
}
methods![get, post, delete,];
fn route(&self, url: &str) -> String {
let mut s = (*self.base).to_owned();
s += url;
s
}
}
impl From<Data> for Mastodon {
/// Creates a mastodon instance from the data struct.
pub fn from_data(data: Data) -> Self {
fn from(data: Data) -> Mastodon {
let mut headers = Headers::new();
headers.set(Authorization(Bearer { token: (*data.token).to_owned() }));
@ -449,14 +459,6 @@ impl Mastodon {
data: data,
}
}
methods![get, post, delete,];
fn route(&self, url: &str) -> String {
let mut s = (*self.base).to_owned();
s += url;
s
}
}
impl MastodonClient for Mastodon {
@ -586,7 +588,7 @@ impl MastodonClient for Mastodon {
/// # redirect: "".into(),
/// # token: "".into(),
/// # };
/// let client = Mastodon::from_data(data);
/// let client = Mastodon::from(data);
/// let statuses = client.statuses("user-id", None)?;
/// # Ok(())
/// # }
@ -604,7 +606,7 @@ impl MastodonClient for Mastodon {
/// # redirect: "".into(),
/// # token: "".into(),
/// # };
/// let client = Mastodon::from_data(data);
/// let client = Mastodon::from(data);
/// let request = StatusesRequest::default()
/// .only_media();
/// let statuses = client.statuses("user-id", request)?;

Loading…
Cancel
Save