|
|
@ -68,10 +68,16 @@ macro_rules! methods { |
|
|
|
fn $method<T: serde::Deserialize>(&self, url: String) |
|
|
|
fn $method<T: serde::Deserialize>(&self, url: String) |
|
|
|
-> Result<T> |
|
|
|
-> Result<T> |
|
|
|
{ |
|
|
|
{ |
|
|
|
Ok(self.client.$method(&url) |
|
|
|
let result: std::result::Result<T, ApiError> = |
|
|
|
|
|
|
|
self.client.$method(&url) |
|
|
|
.headers(self.headers.clone()) |
|
|
|
.headers(self.headers.clone()) |
|
|
|
.send()? |
|
|
|
.send()? |
|
|
|
.json()?) |
|
|
|
.json()?; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
match result { |
|
|
|
|
|
|
|
Ok(t) => Ok(t), |
|
|
|
|
|
|
|
Err(error) => Err(Error::Api(error)), |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
)+ |
|
|
|
)+ |
|
|
|
}; |
|
|
|
}; |
|
|
@ -159,6 +165,7 @@ pub struct Data { |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)] |
|
|
|
#[derive(Debug)] |
|
|
|
pub enum Error { |
|
|
|
pub enum Error { |
|
|
|
|
|
|
|
Api(ApiError), |
|
|
|
Serde(SerdeError), |
|
|
|
Serde(SerdeError), |
|
|
|
Http(HttpError), |
|
|
|
Http(HttpError), |
|
|
|
ClientIdRequired, |
|
|
|
ClientIdRequired, |
|
|
@ -166,6 +173,15 @@ pub enum Error { |
|
|
|
AccessTokenRequired, |
|
|
|
AccessTokenRequired, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Error returned from the Mastodon API.
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Deserialize)] |
|
|
|
|
|
|
|
pub struct ApiError { |
|
|
|
|
|
|
|
/// The type of error.
|
|
|
|
|
|
|
|
pub error: String, |
|
|
|
|
|
|
|
/// The description of the error.
|
|
|
|
|
|
|
|
pub error_description: String, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl Mastodon { |
|
|
|
impl Mastodon { |
|
|
|
fn from_registration(base: String, |
|
|
|
fn from_registration(base: String, |
|
|
|
client_id: String, |
|
|
|
client_id: String, |
|
|
|