Skip to content

Instantly share code, notes, and snippets.

@mpalmr
Last active May 20, 2019 16:38
Show Gist options
  • Save mpalmr/9f670b1cf8f47f09f5519f47fb4e4d16 to your computer and use it in GitHub Desktop.
Save mpalmr/9f670b1cf8f47f09f5519f47fb4e4d16 to your computer and use it in GitHub Desktop.
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")
}
}
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