Last active
May 20, 2019 16:38
-
-
Save mpalmr/9f670b1cf8f47f09f5519f47fb4e4d16 to your computer and use it in GitHub Desktop.
This file contains 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
use reqwest::header::{ | |
HeaderMap, HeaderValue, ACCEPT, ACCEPT_ENCODING, ACCEPT_LANGUAGE, CACHE_CONTROL, DNT, | |
USER_AGENT, HOST, PRAGMA, | |
}; | |
use reqwest::{Error, Response}; | |
pub struct Client { | |
client: reqwest::Client, | |
headers: HeaderMap, | |
} | |
impl Client { | |
pub fn new(user_agent: &'static str) -> Self { | |
let mut headers = HeaderMap::new(); | |
headers.insert(USER_AGENT, HeaderValue::from_static(user_agent)); | |
headers.insert(ACCEPT, HeaderValue::from_static("application/json")); | |
headers.insert(ACCEPT_ENCODING, HeaderValue::from_static("gzip, deflate, br")); | |
headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static("en-US,en;q=0.9")); | |
headers.insert(CACHE_CONTROL, HeaderValue::from_static("no-cache")); | |
headers.insert(DNT, HeaderValue::from_static("1")); | |
headers.insert(HOST, HeaderValue::from_static("api.arcsecond.io")); | |
headers.insert(PRAGMA, HeaderValue::from_static("no-cache")); | |
Self { | |
headers, | |
client: reqwest::Client::new(), | |
} | |
} | |
pub fn request(&self, path: &str) -> Result<Response, Error> { | |
Ok(self | |
.client | |
.get(&format!("https://api.arcsecond.io{}", path)) | |
.headers(self.headers) | |
.send()?) | |
} | |
} | |
impl Default for Client { | |
fn default() -> Self { | |
Self::new("reqwest") | |
} | |
} |
This file contains 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
On line 34 .headers(self.headers) | |
cannot move out of borrowed content |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment