1use crate::endpoints::EndpointManager;
2use derive_builder::Builder;
3
4#[cfg(not(feature = "async-client"))]
5mod blocking;
6#[cfg(not(feature = "async-client"))]
7pub use blocking::client;
8#[cfg(not(feature = "async-client"))]
9pub use blocking::Client;
10
11#[cfg(feature = "async-client")]
12mod async_client;
13#[cfg(feature = "async-client")]
14pub use async_client::client;
15#[cfg(feature = "async-client")]
16pub use async_client::Client;
17
18#[derive(Builder, Clone)]
35pub struct ClientOptions {
36 #[builder(setter(into, strip_option), default)]
38 host: Option<String>,
39
40 api_key: String,
42
43 #[builder(default = "30")]
45 request_timeout_seconds: u64,
46
47 #[builder(setter(into, strip_option), default)]
49 personal_api_key: Option<String>,
50
51 #[builder(default = "false")]
53 enable_local_evaluation: bool,
54
55 #[builder(default = "30")]
57 poll_interval_seconds: u64,
58
59 #[builder(default = "false")]
61 disabled: bool,
62
63 #[builder(default = "false")]
65 disable_geoip: bool,
66
67 #[builder(default = "3")]
69 feature_flags_request_timeout_seconds: u64,
70
71 #[builder(setter(skip))]
72 #[builder(default = "EndpointManager::new(None)")]
73 endpoint_manager: EndpointManager,
74}
75
76impl ClientOptions {
77 pub(crate) fn endpoints(&self) -> &EndpointManager {
79 &self.endpoint_manager
80 }
81
82 pub fn is_disabled(&self) -> bool {
84 self.disabled
85 }
86
87 fn with_endpoint_manager(mut self) -> Self {
89 self.endpoint_manager = EndpointManager::new(self.host.clone());
90 self
91 }
92}
93
94impl From<&str> for ClientOptions {
95 fn from(api_key: &str) -> Self {
96 ClientOptionsBuilder::default()
97 .api_key(api_key.to_string())
98 .build()
99 .expect("We always set the API key, so this is infallible")
100 .with_endpoint_manager()
101 }
102}
103
104impl From<(&str, &str)> for ClientOptions {
105 fn from((api_key, host): (&str, &str)) -> Self {
107 ClientOptionsBuilder::default()
108 .api_key(api_key.to_string())
109 .host(host.to_string())
110 .build()
111 .expect("We always set the API key, so this is infallible")
112 .with_endpoint_manager()
113 }
114}