Skip to main content

tank01_data/
config.rs

1use std::time::Duration;
2
3use utils::Secret;
4
5const DEFAULT_API_BASE_URL: &str =
6    "https://tank01-nfl-live-in-game-real-time-statistics-nfl.p.rapidapi.com";
7const DEFAULT_RAPIDAPI_HOST: &str =
8    "tank01-nfl-live-in-game-real-time-statistics-nfl.p.rapidapi.com";
9
10#[derive(Clone)]
11pub struct Tank01Config {
12    pub api_key: Secret,
13    pub api_base_url: String,
14    pub rapidapi_host: String,
15    pub timeout: Duration,
16}
17
18impl std::fmt::Debug for Tank01Config {
19    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20        formatter
21            .debug_struct("Tank01Config")
22            .field("api_key", &self.api_key)
23            .field("api_base_url", &self.api_base_url)
24            .field("rapidapi_host", &self.rapidapi_host)
25            .field("timeout", &self.timeout)
26            .finish()
27    }
28}
29
30impl Tank01Config {
31    pub fn new(api_key: Secret) -> Self {
32        Self {
33            api_key,
34            api_base_url: DEFAULT_API_BASE_URL.into(),
35            rapidapi_host: DEFAULT_RAPIDAPI_HOST.into(),
36            timeout: Duration::from_secs(20),
37        }
38    }
39
40    pub fn with_base_url(mut self, api_base_url: impl Into<String>) -> Self {
41        self.api_base_url = api_base_url.into();
42        self
43    }
44
45    pub fn with_api_base_url(self, api_base_url: impl Into<String>) -> Self {
46        self.with_base_url(api_base_url)
47    }
48
49    pub fn with_rapidapi_host(mut self, rapidapi_host: impl Into<String>) -> Self {
50        self.rapidapi_host = rapidapi_host.into();
51        self
52    }
53
54    pub fn with_host(self, rapidapi_host: impl Into<String>) -> Self {
55        self.with_rapidapi_host(rapidapi_host)
56    }
57
58    pub fn with_timeout(mut self, timeout: Duration) -> Self {
59        self.timeout = timeout;
60        self
61    }
62}