use crate::endpoints::EndpointManager;
use derive_builder::Builder;
#[cfg(not(feature = "async-client"))]
mod blocking;
#[cfg(not(feature = "async-client"))]
pub use blocking::client;
#[cfg(not(feature = "async-client"))]
pub use blocking::Client;
#[cfg(feature = "async-client")]
mod async_client;
#[cfg(feature = "async-client")]
pub use async_client::client;
#[cfg(feature = "async-client")]
pub use async_client::Client;
#[derive(Builder, Clone)]
pub struct ClientOptions {
#[builder(setter(into, strip_option), default)]
host: Option<String>,
api_key: String,
#[builder(default = "30")]
request_timeout_seconds: u64,
#[builder(setter(into, strip_option), default)]
personal_api_key: Option<String>,
#[builder(default = "false")]
enable_local_evaluation: bool,
#[builder(default = "30")]
poll_interval_seconds: u64,
#[builder(default = "false")]
disabled: bool,
#[builder(default = "false")]
disable_geoip: bool,
#[builder(default = "3")]
feature_flags_request_timeout_seconds: u64,
#[builder(default = "false")]
local_evaluation_only: bool,
#[builder(setter(skip))]
#[builder(default = "EndpointManager::new(None)")]
endpoint_manager: EndpointManager,
}
impl ClientOptions {
pub(crate) fn endpoints(&self) -> &EndpointManager {
&self.endpoint_manager
}
pub fn is_disabled(&self) -> bool {
self.disabled
}
fn with_endpoint_manager(mut self) -> Self {
self.endpoint_manager = EndpointManager::new(self.host.clone());
self
}
}
impl From<&str> for ClientOptions {
fn from(api_key: &str) -> Self {
ClientOptionsBuilder::default()
.api_key(api_key.to_string())
.build()
.expect("We always set the API key, so this is infallible")
.with_endpoint_manager()
}
}
impl From<(&str, &str)> for ClientOptions {
fn from((api_key, host): (&str, &str)) -> Self {
ClientOptionsBuilder::default()
.api_key(api_key.to_string())
.host(host.to_string())
.build()
.expect("We always set the API key, so this is infallible")
.with_endpoint_manager()
}
}