Guest User

Untitled

a guest
Jun 20th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. /// Send a given request and deserialize the response
  2. pub fn send_and_deserialize(&self, header: OAuthAuthorizationHeader) -> Result<Root, Error> {
  3. let req = self.clone();
  4.  
  5. // Send the request
  6. let mut response = req
  7. .client
  8. .hyper
  9. .request(req.method, &req.url)
  10. .header(Authorization(header.to_string()))
  11. .send()?;
  12.  
  13. // Read our response and write to a buffer.
  14. // We can just `unwrap` here since we already error checked.
  15. let mut buf = String::new();
  16. response.read_to_string(&mut buf);
  17.  
  18. // deserialize from JSON to a `Root` object
  19. serde_json::from_str(&buf)
  20. }
Add Comment
Please, Sign In to add comment