v6.1 fixed routes not deserialising correctly.

master
Aaron Power 8 years ago
parent 39e539646b
commit 5332b47ede
  1. 2
      Cargo.toml
  2. 32
      src/lib.rs

@ -1,6 +1,6 @@
[package]
name = "mammut"
version = "0.6.0"
version = "0.6.1"
description = "A wrapper around the Mastodon API."
authors = ["Aaron Power <theaaronepower@gmail.com>"]
license = "MIT/Apache-2.0"

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

Loading…
Cancel
Save