1use crate::api::resources::LatticeClient;
2use crate::{ApiError, ClientConfig};
3use std::collections::HashMap;
4use std::time::Duration;
5
6pub struct ApiClientBuilder {
23 config: ClientConfig,
24}
25
26impl ApiClientBuilder {
27 pub fn new(base_url: impl Into<String>) -> Self {
29 let mut config = ClientConfig::default();
30 config.base_url = base_url.into();
31 Self { config }
32 }
33
34 pub fn api_key(mut self, key: impl Into<String>) -> Self {
36 self.config.api_key = Some(key.into());
37 self
38 }
39
40 pub fn token(mut self, token: impl Into<String>) -> Self {
42 self.config.token = Some(token.into());
43 self
44 }
45
46 pub fn username(mut self, username: impl Into<String>) -> Self {
48 self.config.username = Some(username.into());
49 self
50 }
51
52 pub fn password(mut self, password: impl Into<String>) -> Self {
54 self.config.password = Some(password.into());
55 self
56 }
57
58 pub fn timeout(mut self, timeout: Duration) -> Self {
60 self.config.timeout = timeout;
61 self
62 }
63
64 pub fn max_retries(mut self, retries: u32) -> Self {
66 self.config.max_retries = retries;
67 self
68 }
69
70 pub fn custom_header(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
72 self.config.custom_headers.insert(key.into(), value.into());
73 self
74 }
75
76 pub fn custom_headers(mut self, headers: HashMap<String, String>) -> Self {
78 self.config.custom_headers.extend(headers);
79 self
80 }
81
82 pub fn user_agent(mut self, user_agent: impl Into<String>) -> Self {
84 self.config.user_agent = user_agent.into();
85 self
86 }
87
88 pub fn build(self) -> Result<LatticeClient, ApiError> {
90 LatticeClient::new(self.config)
91 }
92}