pub mod async_api;
pub mod auth;
#[cfg(all(feature = "blocking", not(target_arch = "wasm32")))]
pub mod blocking_api;
pub mod endpoint;
pub mod response;
use serde::Serialize;
use std::net::IpAddr;
use std::time::Duration;
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("Reqwest returned an error when connecting to the Cloudflare API: {0}")]
ReqwestError(#[from] reqwest::Error),
}
#[derive(Serialize, Clone, Debug)]
pub enum OrderDirection {
#[serde(rename = "asc")]
Ascending,
#[serde(rename = "desc")]
Descending,
}
#[derive(Serialize, Clone, Debug)]
#[serde(rename_all = "lowercase")]
pub enum SearchMatch {
All,
Any,
}
#[derive(Debug)]
pub enum Environment {
Production,
Custom(url::Url),
#[cfg(feature = "mockito")]
Mockito,
}
impl<'a> From<&'a Environment> for url::Url {
fn from(environment: &Environment) -> Self {
match environment {
Environment::Production => {
url::Url::parse("https://api.cloudflare.com/client/v4/").unwrap()
}
Environment::Custom(url) => url.clone(),
#[cfg(feature = "mockito")]
Environment::Mockito => url::Url::parse(&mockito::server_url()).unwrap(),
}
}
}
#[cfg(all(feature = "blocking", not(target_arch = "wasm32")))]
pub struct HttpApiClient {
environment: Environment,
credentials: auth::Credentials,
http_client: reqwest::blocking::Client,
}
#[cfg(all(feature = "blocking", not(target_arch = "wasm32")))]
impl HttpApiClient {
#[cfg(feature = "mockito")]
pub fn is_mock(&self) -> bool {
matches!(self.environment, Environment::Mockito)
}
}
pub struct HttpApiClientConfig {
pub http_timeout: Duration,
pub default_headers: http::HeaderMap,
pub resolve_ip: Option<IpAddr>,
}
impl Default for HttpApiClientConfig {
fn default() -> Self {
HttpApiClientConfig {
http_timeout: Duration::from_secs(30),
default_headers: http::HeaderMap::default(),
resolve_ip: None,
}
}
}