use std::time::Duration;
use reqwest::Client as HttpClient;
pub const DEFAULT_BASE_URL: &str = "https://api.pickpoint.io";
pub const DEFAULT_MAX_RETRIES: u32 = 3;
pub const DEFAULT_RETRY_BASE: Duration = Duration::from_secs(1);
pub const MIN_RETRY_BASE: Duration = Duration::from_millis(200);
pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(30);
pub const MAX_CONCURRENCY: usize = 20;
pub const DEFAULT_CONCURRENCY: usize = 20;
pub(crate) const CLIENT_AUTH_REFRESH_AT: f64 = 0.5;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ClientAuth {
pub access_token: String,
pub refresh_token: String,
pub expires_at: i64,
}
#[derive(Debug, Clone, Default)]
pub struct Config {
pub api_key: Option<String>,
pub client_auth: Option<ClientAuth>,
pub access_token: Option<String>,
pub base_url: Option<String>,
pub http_client: Option<HttpClient>,
pub max_retries: Option<u32>,
pub retry_base: Option<Duration>,
pub timeout: Option<Duration>,
pub concurrency: Option<usize>,
}
impl Config {
pub fn with_api_key(api_key: impl Into<String>) -> Self {
Self {
api_key: Some(api_key.into()),
..Default::default()
}
}
pub fn with_client_auth(auth: ClientAuth) -> Self {
Self {
client_auth: Some(auth),
..Default::default()
}
}
pub fn with_access_token(token: impl Into<String>) -> Self {
Self {
access_token: Some(token.into()),
..Default::default()
}
}
pub fn base_url(mut self, url: impl Into<String>) -> Self {
self.base_url = Some(url.into());
self
}
pub fn http_client(mut self, client: HttpClient) -> Self {
self.http_client = Some(client);
self
}
pub fn max_retries(mut self, n: u32) -> Self {
self.max_retries = Some(n);
self
}
pub fn retry_base(mut self, d: Duration) -> Self {
self.retry_base = Some(d);
self
}
pub fn timeout(mut self, d: Duration) -> Self {
self.timeout = Some(d);
self
}
pub fn concurrency(mut self, n: usize) -> Self {
self.concurrency = Some(n);
self
}
}