Created
June 19, 2018 00:27
-
-
Save piedoom/844c1c4f1d8c08b291996e0698c80dc6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Send a given request and deserialize the response | |
pub fn send_and_deserialize(&self, header: OAuthAuthorizationHeader) -> Result<Root, Error> { | |
let req = self.clone(); | |
// Send the request | |
let mut response = req | |
.client | |
.hyper | |
.request(req.method, &req.url) | |
.header(Authorization(header.to_string())) | |
.send()?; | |
// Read our response and write to a buffer. | |
// We can just `unwrap` here since we already error checked. | |
let mut buf = String::new(); | |
response.read_to_string(&mut buf); | |
// deserialize from JSON to a `Root` object | |
serde_json::from_str(&buf) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment