use crate::blocking::Client;
use crate::{LTAError, LTAResult};
use reqwest::blocking::Client as BlockingClient;
use reqwest::blocking::RequestBuilder;
#[derive(Debug, Clone)]
pub struct LTAClient {
api_key: String,
client: BlockingClient,
}
impl Client for LTAClient {
type InternalClient = BlockingClient;
type RB = RequestBuilder;
fn new(api_key: impl Into<String>, client: Self::InternalClient) -> LTAClient {
let api_key = api_key.into();
LTAClient { api_key, client }
}
fn with_api_key(api_key: impl Into<String>) -> LTAResult<Self> {
let api_key = api_key.into();
if api_key.is_empty() {
return Err(LTAError::InvalidAPIKey);
}
let client = BlockingClient::new();
Ok(LTAClient { api_key, client })
}
fn req_builder(&self, url: &str) -> Self::RB {
self.client
.get(url)
.header("AccountKey", self.api_key.as_str())
}
}