aw_test/services/
locale.rs

1use crate::client::{Client, ParamType};
2use std::collections::HashMap;
3use crate::services::AppwriteException;
4use crate::models;
5use serde_json::json;
6use std::io::Read;
7
8#[derive(Clone)]
9pub struct Locale {
10  client: Client
11}
12
13impl Locale {  
14    pub fn new(client: &Client) -> Self {
15        Self {
16            client: client.clone()
17        }
18    }
19
20    /// Get the current user location based on IP. Returns an object with user
21    /// country code, country name, continent name, continent code, ip address and
22    /// suggested currency. You can use the locale header to get the data in a
23    /// supported language.
24    /// 
25    /// ([IP Geolocation by DB-IP](https://db-ip.com))
26    pub fn get(&self) -> Result<models::Locale, AppwriteException> {
27        let path = "/locale";
28        let  headers: HashMap<String, String> = [
29            ("content-type".to_string(), "application/json".to_string()),
30        ].iter().cloned().collect();
31
32        let  params: HashMap<String, ParamType> = [
33        ].iter().cloned().collect();
34
35        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
36
37        let processedResponse:models::Locale = match response {
38            Ok(r) => {
39                match r.json() {
40                    Ok(json) => json,
41                    Err(e) => {
42                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
43                    }
44                }
45            }
46            Err(e) => {
47                return Err(e);
48            }
49        };
50
51        Ok(processedResponse)
52    }
53
54    /// List of all continents. You can use the locale header to get the data in a
55    /// supported language.
56    pub fn get_continents(&self) -> Result<models::ContinentList, AppwriteException> {
57        let path = "/locale/continents";
58        let  headers: HashMap<String, String> = [
59            ("content-type".to_string(), "application/json".to_string()),
60        ].iter().cloned().collect();
61
62        let  params: HashMap<String, ParamType> = [
63        ].iter().cloned().collect();
64
65        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
66
67        let processedResponse:models::ContinentList = match response {
68            Ok(r) => {
69                match r.json() {
70                    Ok(json) => json,
71                    Err(e) => {
72                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
73                    }
74                }
75            }
76            Err(e) => {
77                return Err(e);
78            }
79        };
80
81        Ok(processedResponse)
82    }
83
84    /// List of all countries. You can use the locale header to get the data in a
85    /// supported language.
86    pub fn get_countries(&self) -> Result<models::CountryList, AppwriteException> {
87        let path = "/locale/countries";
88        let  headers: HashMap<String, String> = [
89            ("content-type".to_string(), "application/json".to_string()),
90        ].iter().cloned().collect();
91
92        let  params: HashMap<String, ParamType> = [
93        ].iter().cloned().collect();
94
95        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
96
97        let processedResponse:models::CountryList = match response {
98            Ok(r) => {
99                match r.json() {
100                    Ok(json) => json,
101                    Err(e) => {
102                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
103                    }
104                }
105            }
106            Err(e) => {
107                return Err(e);
108            }
109        };
110
111        Ok(processedResponse)
112    }
113
114    /// List of all countries that are currently members of the EU. You can use the
115    /// locale header to get the data in a supported language.
116    pub fn get_countries_eu(&self) -> Result<models::CountryList, AppwriteException> {
117        let path = "/locale/countries/eu";
118        let  headers: HashMap<String, String> = [
119            ("content-type".to_string(), "application/json".to_string()),
120        ].iter().cloned().collect();
121
122        let  params: HashMap<String, ParamType> = [
123        ].iter().cloned().collect();
124
125        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
126
127        let processedResponse:models::CountryList = match response {
128            Ok(r) => {
129                match r.json() {
130                    Ok(json) => json,
131                    Err(e) => {
132                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
133                    }
134                }
135            }
136            Err(e) => {
137                return Err(e);
138            }
139        };
140
141        Ok(processedResponse)
142    }
143
144    /// List of all countries phone codes. You can use the locale header to get the
145    /// data in a supported language.
146    pub fn get_countries_phones(&self) -> Result<models::PhoneList, AppwriteException> {
147        let path = "/locale/countries/phones";
148        let  headers: HashMap<String, String> = [
149            ("content-type".to_string(), "application/json".to_string()),
150        ].iter().cloned().collect();
151
152        let  params: HashMap<String, ParamType> = [
153        ].iter().cloned().collect();
154
155        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
156
157        let processedResponse:models::PhoneList = match response {
158            Ok(r) => {
159                match r.json() {
160                    Ok(json) => json,
161                    Err(e) => {
162                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
163                    }
164                }
165            }
166            Err(e) => {
167                return Err(e);
168            }
169        };
170
171        Ok(processedResponse)
172    }
173
174    /// List of all currencies, including currency symbol, name, plural, and
175    /// decimal digits for all major and minor currencies. You can use the locale
176    /// header to get the data in a supported language.
177    pub fn get_currencies(&self) -> Result<models::CurrencyList, AppwriteException> {
178        let path = "/locale/currencies";
179        let  headers: HashMap<String, String> = [
180            ("content-type".to_string(), "application/json".to_string()),
181        ].iter().cloned().collect();
182
183        let  params: HashMap<String, ParamType> = [
184        ].iter().cloned().collect();
185
186        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
187
188        let processedResponse:models::CurrencyList = match response {
189            Ok(r) => {
190                match r.json() {
191                    Ok(json) => json,
192                    Err(e) => {
193                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
194                    }
195                }
196            }
197            Err(e) => {
198                return Err(e);
199            }
200        };
201
202        Ok(processedResponse)
203    }
204
205    /// List of all languages classified by ISO 639-1 including 2-letter code, name
206    /// in English, and name in the respective language.
207    pub fn get_languages(&self) -> Result<models::LanguageList, AppwriteException> {
208        let path = "/locale/languages";
209        let  headers: HashMap<String, String> = [
210            ("content-type".to_string(), "application/json".to_string()),
211        ].iter().cloned().collect();
212
213        let  params: HashMap<String, ParamType> = [
214        ].iter().cloned().collect();
215
216        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
217
218        let processedResponse:models::LanguageList = match response {
219            Ok(r) => {
220                match r.json() {
221                    Ok(json) => json,
222                    Err(e) => {
223                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
224                    }
225                }
226            }
227            Err(e) => {
228                return Err(e);
229            }
230        };
231
232        Ok(processedResponse)
233    }
234}