|
|
@ -69,11 +69,20 @@ macro_rules! methods { |
|
|
|
fn $method<T: serde::Deserialize>(&self, url: String) |
|
|
|
fn $method<T: serde::Deserialize>(&self, url: String) |
|
|
|
-> Result<T> |
|
|
|
-> Result<T> |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
use std::io::Read; |
|
|
|
|
|
|
|
|
|
|
|
let mut response = self.client.$method(&url) |
|
|
|
let mut response = self.client.$method(&url) |
|
|
|
.headers(self.headers.clone()) |
|
|
|
.headers(self.headers.clone()) |
|
|
|
.send()?; |
|
|
|
.send()?; |
|
|
|
|
|
|
|
|
|
|
|
response.json()? |
|
|
|
let mut vec = Vec::new(); |
|
|
|
|
|
|
|
response.read_to_end(&mut vec)?; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if let Ok(t) = json::from_slice(&vec) { |
|
|
|
|
|
|
|
Ok(t) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
Err(Error::Api(json::from_slice(&vec)?)) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
)+ |
|
|
|
)+ |
|
|
|
}; |
|
|
|
}; |
|
|
@ -106,7 +115,11 @@ macro_rules! route { |
|
|
|
|
|
|
|
|
|
|
|
response.read_to_end(&mut vec)?; |
|
|
|
response.read_to_end(&mut vec)?; |
|
|
|
|
|
|
|
|
|
|
|
json::from_slice(&vec)? |
|
|
|
if let Ok(t) = json::from_slice(&vec) { |
|
|
|
|
|
|
|
Ok(t) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
Err(Error::Api(json::from_slice(&vec)?)) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
route!{$($rest)*} |
|
|
|
route!{$($rest)*} |
|
|
|
}; |
|
|
|
}; |
|
|
@ -279,8 +292,7 @@ impl Mastodon { |
|
|
|
let mut response = self.client.post(&self.route("/api/v1/statuses")) |
|
|
|
let mut response = self.client.post(&self.route("/api/v1/statuses")) |
|
|
|
.headers(self.headers.clone()) |
|
|
|
.headers(self.headers.clone()) |
|
|
|
.json(&status) |
|
|
|
.json(&status) |
|
|
|
.send().expect("STAUS BUILDER IS BAD"); |
|
|
|
.send()?; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut vec = Vec::new(); |
|
|
|
let mut vec = Vec::new(); |
|
|
|
response.read_to_end(&mut vec)?; |
|
|
|
response.read_to_end(&mut vec)?; |
|
|
|