noah_sdk/
config.rs

1//! Configuration for the Noah SDK
2
3use url::Url;
4
5/// Environment configuration
6#[derive(Debug, Clone, Default)]
7pub enum Environment {
8    /// Sandbox environment
9    #[default]
10    Sandbox,
11    /// Production environment
12    Production,
13    /// Custom base URL
14    Custom(Url),
15}
16
17impl Environment {
18    /// Get the base URL for the environment
19    pub fn base_url(&self) -> Url {
20        match self {
21            Environment::Sandbox => {
22                Url::parse("https://api.sandbox.noah.com/v1").expect("Invalid sandbox URL")
23            }
24            Environment::Production => {
25                Url::parse("https://api.noah.com/v1").expect("Invalid production URL")
26            }
27            Environment::Custom(url) => url.clone(),
28        }
29    }
30}
31
32/// Client configuration
33#[derive(Debug, Clone)]
34pub struct Config {
35    /// Base URL for API requests
36    pub base_url: Url,
37    /// Request timeout in seconds
38    pub timeout_secs: u64,
39    /// User agent string
40    pub user_agent: String,
41    /// Enable request/response logging
42    pub enable_logging: bool,
43}
44
45impl Config {
46    /// Create a new configuration with default values
47    pub fn new(environment: Environment) -> Self {
48        Self {
49            base_url: environment.base_url(),
50            timeout_secs: 30,
51            user_agent: format!("noah-sdk/{}", env!("CARGO_PKG_VERSION")),
52            enable_logging: false,
53        }
54    }
55
56    /// Set the timeout
57    pub fn with_timeout(mut self, timeout_secs: u64) -> Self {
58        self.timeout_secs = timeout_secs;
59        self
60    }
61
62    /// Set a custom user agent
63    pub fn with_user_agent(mut self, user_agent: String) -> Self {
64        self.user_agent = user_agent;
65        self
66    }
67
68    /// Enable logging
69    pub fn with_logging(mut self, enable: bool) -> Self {
70        self.enable_logging = enable;
71        self
72    }
73}
74
75impl Default for Config {
76    fn default() -> Self {
77        Self::new(Environment::default())
78    }
79}