|
|
@ -68,15 +68,14 @@ macro_rules! methods { |
|
|
|
fn $method<T: serde::Deserialize>(&self, url: String) |
|
|
|
fn $method<T: serde::Deserialize>(&self, url: String) |
|
|
|
-> Result<T> |
|
|
|
-> Result<T> |
|
|
|
{ |
|
|
|
{ |
|
|
|
let result: std::result::Result<T, ApiError> = |
|
|
|
let mut response = self.client.$method(&url) |
|
|
|
self.client.$method(&url) |
|
|
|
|
|
|
|
.headers(self.headers.clone()) |
|
|
|
.headers(self.headers.clone()) |
|
|
|
.send()? |
|
|
|
.send()?; |
|
|
|
.json()?; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
match result { |
|
|
|
if let Ok(t) = response.json::<T>() { |
|
|
|
Ok(t) => Ok(t), |
|
|
|
Ok(t) |
|
|
|
Err(error) => Err(Error::Api(error)), |
|
|
|
} else { |
|
|
|
|
|
|
|
Err(Error::Api(response.json()?)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
)+ |
|
|
|
)+ |
|
|
@ -100,11 +99,16 @@ macro_rules! route { |
|
|
|
)* |
|
|
|
)* |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
Ok(self.client.post(&self.route(concat!("/api/v1/", $url))) |
|
|
|
let mut response = self.client.post(&self.route(concat!("/api/v1/", $url))) |
|
|
|
.headers(self.headers.clone()) |
|
|
|
.headers(self.headers.clone()) |
|
|
|
.form(&form_data) |
|
|
|
.form(&form_data) |
|
|
|
.send()? |
|
|
|
.send()?; |
|
|
|
.json()?) |
|
|
|
|
|
|
|
|
|
|
|
if let Ok(t) = response.json::<$ret>() { |
|
|
|
|
|
|
|
Ok(t) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
Err(Error::Api(response.json()?)) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
route!{$($rest)*} |
|
|
|
route!{$($rest)*} |
|
|
|
}; |
|
|
|
}; |
|
|
|