Change Mastodon::from_data to just Mastodon::from
This commit is contained in:
@@ -25,7 +25,7 @@ fn main() {
|
|||||||
let mut config = String::new();
|
let mut config = String::new();
|
||||||
file.read_to_string(&mut config).unwrap();
|
file.read_to_string(&mut config).unwrap();
|
||||||
let data: Data = toml::from_str(&config).unwrap();
|
let data: Data = toml::from_str(&config).unwrap();
|
||||||
Mastodon::from_data(data)
|
Mastodon::from(data)
|
||||||
},
|
},
|
||||||
Err(_) => register(),
|
Err(_) => register(),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
extern crate elefren;
|
extern crate elefren;
|
||||||
extern crate toml;
|
extern crate toml;
|
||||||
|
|
||||||
pub use self::elefren::MastodonClient;
|
pub use self::elefren::{Data, MastodonClient};
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
error::Error,
|
error::Error,
|
||||||
@@ -28,7 +28,8 @@ fn main() -> Result<(), Box<Error>> {
|
|||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn get_mastodon_data() -> Result<Mastodon, Box<Error>> {
|
pub fn get_mastodon_data() -> Result<Mastodon, Box<Error>> {
|
||||||
if let Ok(config) = fs::read_to_string("mastodon-data.toml") {
|
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 {
|
} else {
|
||||||
register()
|
register()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use serde::Deserialize;
|
|||||||
/// # redirect: "".into(),
|
/// # redirect: "".into(),
|
||||||
/// # token: "".into(),
|
/// # token: "".into(),
|
||||||
/// # };
|
/// # };
|
||||||
/// let client = Mastodon::from_data(data);
|
/// let client = Mastodon::from(data);
|
||||||
/// let statuses = client.statuses("user-id", None)?;
|
/// let statuses = client.statuses("user-id", None)?;
|
||||||
/// for status in statuses.items_iter() {
|
/// for status in statuses.items_iter() {
|
||||||
/// // do something with `status`
|
/// // do something with `status`
|
||||||
|
|||||||
+13
-11
@@ -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.
|
/// 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();
|
let mut headers = Headers::new();
|
||||||
headers.set(Authorization(Bearer { token: (*data.token).to_owned() }));
|
headers.set(Authorization(Bearer { token: (*data.token).to_owned() }));
|
||||||
|
|
||||||
@@ -449,14 +459,6 @@ impl Mastodon {
|
|||||||
data: data,
|
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 {
|
impl MastodonClient for Mastodon {
|
||||||
@@ -586,7 +588,7 @@ impl MastodonClient for Mastodon {
|
|||||||
/// # redirect: "".into(),
|
/// # redirect: "".into(),
|
||||||
/// # token: "".into(),
|
/// # token: "".into(),
|
||||||
/// # };
|
/// # };
|
||||||
/// let client = Mastodon::from_data(data);
|
/// let client = Mastodon::from(data);
|
||||||
/// let statuses = client.statuses("user-id", None)?;
|
/// let statuses = client.statuses("user-id", None)?;
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
@@ -604,7 +606,7 @@ impl MastodonClient for Mastodon {
|
|||||||
/// # redirect: "".into(),
|
/// # redirect: "".into(),
|
||||||
/// # token: "".into(),
|
/// # token: "".into(),
|
||||||
/// # };
|
/// # };
|
||||||
/// let client = Mastodon::from_data(data);
|
/// let client = Mastodon::from(data);
|
||||||
/// let request = StatusesRequest::default()
|
/// let request = StatusesRequest::default()
|
||||||
/// .only_media();
|
/// .only_media();
|
||||||
/// let statuses = client.statuses("user-id", request)?;
|
/// let statuses = client.statuses("user-id", request)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user