1#[derive(Debug, Clone, Serialize, Deserialize)]
4pub struct Config {
5 base_api_url: String,
6 upload_url: String,
7 pub oauth2_api_url: String,
8 pub oauth2_authorize_url: String,
9 pub api_version: String,
10 pub max_retry_attempts: u8,
11 pub chunk_upload_threads: u8,
12 pub user_agent: String,
13}
14
15impl Default for Config {
23 fn default() -> Self {
24 Config {
25 base_api_url: String::from("https://api.box.com"),
26 upload_url: String::from("https://upload.box.com/api"),
27 oauth2_api_url: String::from("https://api.box.com/oauth2"),
28 oauth2_authorize_url: String::from("https://account.box.com/api/oauth2/authorize"),
29 api_version: String::from("2.0"),
30 max_retry_attempts: 5,
31 chunk_upload_threads: 5,
32 user_agent: "box-rust-sdk/rusty-box".to_owned(),
33 }
34 }
35}
36
37impl Config {
38 pub fn new() -> Self {
39 Config::default()
40 }
41 pub fn base_api_url(&self) -> String {
42 format!("{}/{}", self.base_api_url, self.api_version)
43 }
44 pub fn upload_url(&self) -> String {
48 format!("{}/{}", self.upload_url, self.api_version)
49 }
50 pub fn set_upload_url(&mut self, upload_url: String) {
51 self.upload_url = upload_url;
52 }
53
54 pub fn user_agent(&self) -> String {
55 self.user_agent.clone()
56 }
57 }
82
83#[cfg(test)]
84mod tests {
85 use super::Config;
86
87 #[test]
88 fn test_default_config_values() {
89 let config = Config::default();
90
91 assert_eq!(config.base_api_url, "https://api.box.com");
92 assert_eq!(config.base_api_url(), "https://api.box.com/2.0");
93
94 assert_eq!(config.upload_url, "https://upload.box.com/api");
95 assert_eq!(config.upload_url(), "https://upload.box.com/api/2.0");
96
97 assert_eq!(config.oauth2_api_url, "https://api.box.com/oauth2");
98 assert_eq!(
99 config.oauth2_authorize_url,
100 "https://account.box.com/api/oauth2/authorize"
101 );
102 assert_eq!(config.max_retry_attempts, 5);
103 assert_eq!(config.chunk_upload_threads, 5);
104 assert_eq!(config.api_version, "2.0");
105 assert_eq!(config.user_agent, "box-rust-sdk/rusty-box".to_owned());
106 }
107
108 #[test]
109 fn test_config_values_v3() {
110 let config = Config {
111 api_version: String::from("3.0"),
112 ..Default::default()
113 };
114 assert_eq!(config.base_api_url(), "https://api.box.com/3.0");
115 assert_eq!(config.upload_url(), "https://upload.box.com/api/3.0");
116 }
117}