fundamentum_sdk_api/client/
config.rs

1//! Client's configuration to be used when making calls to the Fundamentum API
2
3use serde::{Deserialize, Serialize};
4
5const PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
6
7/// Client's configuration.
8#[derive(Default, Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
9#[serde(deny_unknown_fields)]
10pub struct ClientConfig {
11    /// Client's Base-Path.
12    pub base_path: String,
13    /// Client's User-Agent.
14    pub user_agent: Option<String>,
15    /// Client's token.
16    pub api_token: Option<String>,
17}
18
19impl ClientConfig {
20    /// Create a Client's default configuration.
21    #[must_use]
22    pub fn builder(base_path: String) -> ClientConfigBuilder {
23        ClientConfigBuilder::new(base_path)
24    }
25}
26
27/// Client's configuration builder.
28#[derive(Default)]
29pub struct ClientConfigBuilder {
30    base_path: String,
31    user_agent: Option<String>,
32    api_token: Option<String>,
33}
34
35impl ClientConfigBuilder {
36    /// Create a new Client's configuration builder.
37    #[must_use]
38    pub fn new(base_path: String) -> Self {
39        Self {
40            base_path,
41            user_agent: Some(format!("Fundamentum/SDK/{PKG_VERSION}/rust")),
42            api_token: None,
43        }
44    }
45
46    /// Set the User-Agent.
47    #[must_use]
48    pub fn user_agent(mut self, user_agent: Option<String>) -> Self {
49        self.user_agent = user_agent;
50        self
51    }
52
53    /// Set the API Token.
54    #[must_use]
55    pub fn api_token(mut self, api_token: Option<String>) -> Self {
56        self.api_token = api_token;
57        self
58    }
59
60    /// Build the Client's configuration.
61    #[must_use]
62    pub fn build(self) -> ClientConfig {
63        ClientConfig {
64            base_path: self.base_path,
65            user_agent: self.user_agent,
66            api_token: self.api_token,
67        }
68    }
69}