aw_test/services/
projects.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 Projects {
10  client: Client
11}
12
13impl Projects {  
14    pub fn new(client: &Client) -> Self {
15        Self {
16            client: client.clone()
17        }
18    }
19
20    pub fn list(&self, search: Option<&str>, limit: Option<i64>, offset: Option<i64>, cursor: Option<&str>, cursor_direction: Option<&str>, order_type: Option<&str>) -> Result<models::ProjectList, AppwriteException> {
21        let path = "/projects";
22        let  headers: HashMap<String, String> = [
23            ("content-type".to_string(), "application/json".to_string()),
24        ].iter().cloned().collect();
25
26        let search:&str = match search {
27            Some(data) => data,
28            None => ""
29        };
30
31        let cursor:&str = match cursor {
32            Some(data) => data,
33            None => ""
34        };
35
36        let cursor_direction:&str = match cursor_direction {
37            Some(data) => data,
38            None => ""
39        };
40
41        let order_type:&str = match order_type {
42            Some(data) => data,
43            None => ""
44        };
45
46        let  params: HashMap<String, ParamType> = [
47            ("search".to_string(), ParamType::String(search.to_string())),
48            ("limit".to_string(),  ParamType::OptionalNumber(limit)),
49            ("offset".to_string(),  ParamType::OptionalNumber(offset)),
50            ("cursor".to_string(), ParamType::String(cursor.to_string())),
51            ("cursorDirection".to_string(), ParamType::String(cursor_direction.to_string())),
52            ("orderType".to_string(), ParamType::String(order_type.to_string())),
53        ].iter().cloned().collect();
54
55        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
56
57        let processedResponse:models::ProjectList = match response {
58            Ok(r) => {
59                match r.json() {
60                    Ok(json) => json,
61                    Err(e) => {
62                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
63                    }
64                }
65            }
66            Err(e) => {
67                return Err(e);
68            }
69        };
70
71        Ok(processedResponse)
72    }
73
74    pub fn create(&self, project_id: &str, name: &str, team_id: &str, description: Option<&str>, logo: Option<&str>, url: Option<&str>, legal_name: Option<&str>, legal_country: Option<&str>, legal_state: Option<&str>, legal_city: Option<&str>, legal_address: Option<&str>, legal_tax_id: Option<&str>) -> Result<models::Project, AppwriteException> {
75        let path = "/projects";
76        let  headers: HashMap<String, String> = [
77            ("content-type".to_string(), "application/json".to_string()),
78        ].iter().cloned().collect();
79
80        let description:&str = match description {
81            Some(data) => data,
82            None => ""
83        };
84
85        let logo:&str = match logo {
86            Some(data) => data,
87            None => ""
88        };
89
90        let url:&str = match url {
91            Some(data) => data,
92            None => ""
93        };
94
95        let legal_name:&str = match legal_name {
96            Some(data) => data,
97            None => ""
98        };
99
100        let legal_country:&str = match legal_country {
101            Some(data) => data,
102            None => ""
103        };
104
105        let legal_state:&str = match legal_state {
106            Some(data) => data,
107            None => ""
108        };
109
110        let legal_city:&str = match legal_city {
111            Some(data) => data,
112            None => ""
113        };
114
115        let legal_address:&str = match legal_address {
116            Some(data) => data,
117            None => ""
118        };
119
120        let legal_tax_id:&str = match legal_tax_id {
121            Some(data) => data,
122            None => ""
123        };
124
125        let  params: HashMap<String, ParamType> = [
126            ("projectId".to_string(), ParamType::String(project_id.to_string())),
127            ("name".to_string(), ParamType::String(name.to_string())),
128            ("teamId".to_string(), ParamType::String(team_id.to_string())),
129            ("description".to_string(), ParamType::String(description.to_string())),
130            ("logo".to_string(), ParamType::String(logo.to_string())),
131            ("url".to_string(), ParamType::String(url.to_string())),
132            ("legalName".to_string(), ParamType::String(legal_name.to_string())),
133            ("legalCountry".to_string(), ParamType::String(legal_country.to_string())),
134            ("legalState".to_string(), ParamType::String(legal_state.to_string())),
135            ("legalCity".to_string(), ParamType::String(legal_city.to_string())),
136            ("legalAddress".to_string(), ParamType::String(legal_address.to_string())),
137            ("legalTaxId".to_string(), ParamType::String(legal_tax_id.to_string())),
138        ].iter().cloned().collect();
139
140        let response = self.client.clone().call("POST", &path, Some(headers), Some(params) );
141
142        let processedResponse:models::Project = match response {
143            Ok(r) => {
144                match r.json() {
145                    Ok(json) => json,
146                    Err(e) => {
147                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
148                    }
149                }
150            }
151            Err(e) => {
152                return Err(e);
153            }
154        };
155
156        Ok(processedResponse)
157    }
158
159    pub fn get(&self, project_id: &str) -> Result<models::Project, AppwriteException> {
160        let path = "/projects/projectId".replace("projectId", &project_id);
161        let  headers: HashMap<String, String> = [
162            ("content-type".to_string(), "application/json".to_string()),
163        ].iter().cloned().collect();
164
165        let  params: HashMap<String, ParamType> = [
166        ].iter().cloned().collect();
167
168        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
169
170        let processedResponse:models::Project = match response {
171            Ok(r) => {
172                match r.json() {
173                    Ok(json) => json,
174                    Err(e) => {
175                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
176                    }
177                }
178            }
179            Err(e) => {
180                return Err(e);
181            }
182        };
183
184        Ok(processedResponse)
185    }
186
187    pub fn update(&self, project_id: &str, name: &str, description: Option<&str>, logo: Option<&str>, url: Option<&str>, legal_name: Option<&str>, legal_country: Option<&str>, legal_state: Option<&str>, legal_city: Option<&str>, legal_address: Option<&str>, legal_tax_id: Option<&str>) -> Result<models::Project, AppwriteException> {
188        let path = "/projects/projectId".replace("projectId", &project_id);
189        let  headers: HashMap<String, String> = [
190            ("content-type".to_string(), "application/json".to_string()),
191        ].iter().cloned().collect();
192
193        let description:&str = match description {
194            Some(data) => data,
195            None => ""
196        };
197
198        let logo:&str = match logo {
199            Some(data) => data,
200            None => ""
201        };
202
203        let url:&str = match url {
204            Some(data) => data,
205            None => ""
206        };
207
208        let legal_name:&str = match legal_name {
209            Some(data) => data,
210            None => ""
211        };
212
213        let legal_country:&str = match legal_country {
214            Some(data) => data,
215            None => ""
216        };
217
218        let legal_state:&str = match legal_state {
219            Some(data) => data,
220            None => ""
221        };
222
223        let legal_city:&str = match legal_city {
224            Some(data) => data,
225            None => ""
226        };
227
228        let legal_address:&str = match legal_address {
229            Some(data) => data,
230            None => ""
231        };
232
233        let legal_tax_id:&str = match legal_tax_id {
234            Some(data) => data,
235            None => ""
236        };
237
238        let  params: HashMap<String, ParamType> = [
239            ("name".to_string(), ParamType::String(name.to_string())),
240            ("description".to_string(), ParamType::String(description.to_string())),
241            ("logo".to_string(), ParamType::String(logo.to_string())),
242            ("url".to_string(), ParamType::String(url.to_string())),
243            ("legalName".to_string(), ParamType::String(legal_name.to_string())),
244            ("legalCountry".to_string(), ParamType::String(legal_country.to_string())),
245            ("legalState".to_string(), ParamType::String(legal_state.to_string())),
246            ("legalCity".to_string(), ParamType::String(legal_city.to_string())),
247            ("legalAddress".to_string(), ParamType::String(legal_address.to_string())),
248            ("legalTaxId".to_string(), ParamType::String(legal_tax_id.to_string())),
249        ].iter().cloned().collect();
250
251        let response = self.client.clone().call("PATCH", &path, Some(headers), Some(params) );
252
253        let processedResponse:models::Project = match response {
254            Ok(r) => {
255                match r.json() {
256                    Ok(json) => json,
257                    Err(e) => {
258                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
259                    }
260                }
261            }
262            Err(e) => {
263                return Err(e);
264            }
265        };
266
267        Ok(processedResponse)
268    }
269
270    pub fn delete(&self, project_id: &str, password: &str) -> Result<serde_json::value::Value, AppwriteException> {
271        let path = "/projects/projectId".replace("projectId", &project_id);
272        let  headers: HashMap<String, String> = [
273            ("content-type".to_string(), "application/json".to_string()),
274        ].iter().cloned().collect();
275
276        let  params: HashMap<String, ParamType> = [
277            ("password".to_string(), ParamType::String(password.to_string())),
278        ].iter().cloned().collect();
279
280        let response = self.client.clone().call("DELETE", &path, Some(headers), Some(params) );
281
282        match response {
283            Ok(r) => {
284                let status_code = r.status();
285                if status_code == reqwest::StatusCode::NO_CONTENT {
286                    Ok(json!(true))
287                } else {
288                    Ok(serde_json::from_str(&r.text().unwrap()).unwrap())
289                }
290            }
291            Err(e) => {
292                Err(e)
293            }
294        }
295    }
296
297    pub fn update_auth_limit(&self, project_id: &str, limit: i64) -> Result<models::Project, AppwriteException> {
298        let path = "/projects/projectId/auth/limit".replace("projectId", &project_id);
299        let  headers: HashMap<String, String> = [
300            ("content-type".to_string(), "application/json".to_string()),
301        ].iter().cloned().collect();
302
303        let  params: HashMap<String, ParamType> = [
304            ("limit".to_string(),  ParamType::Number(limit)),
305        ].iter().cloned().collect();
306
307        let response = self.client.clone().call("PATCH", &path, Some(headers), Some(params) );
308
309        let processedResponse:models::Project = match response {
310            Ok(r) => {
311                match r.json() {
312                    Ok(json) => json,
313                    Err(e) => {
314                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
315                    }
316                }
317            }
318            Err(e) => {
319                return Err(e);
320            }
321        };
322
323        Ok(processedResponse)
324    }
325
326    pub fn update_auth_status(&self, project_id: &str, method: &str, status: bool) -> Result<models::Project, AppwriteException> {
327        let path = "/projects/projectId/auth/method".replace("projectId", &project_id).replace("method", &method);
328        let  headers: HashMap<String, String> = [
329            ("content-type".to_string(), "application/json".to_string()),
330        ].iter().cloned().collect();
331
332        let  params: HashMap<String, ParamType> = [
333            ("status".to_string(), ParamType::Bool(status)),
334        ].iter().cloned().collect();
335
336        let response = self.client.clone().call("PATCH", &path, Some(headers), Some(params) );
337
338        let processedResponse:models::Project = match response {
339            Ok(r) => {
340                match r.json() {
341                    Ok(json) => json,
342                    Err(e) => {
343                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
344                    }
345                }
346            }
347            Err(e) => {
348                return Err(e);
349            }
350        };
351
352        Ok(processedResponse)
353    }
354
355    pub fn list_domains(&self, project_id: &str) -> Result<models::DomainList, AppwriteException> {
356        let path = "/projects/projectId/domains".replace("projectId", &project_id);
357        let  headers: HashMap<String, String> = [
358            ("content-type".to_string(), "application/json".to_string()),
359        ].iter().cloned().collect();
360
361        let  params: HashMap<String, ParamType> = [
362        ].iter().cloned().collect();
363
364        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
365
366        let processedResponse:models::DomainList = match response {
367            Ok(r) => {
368                match r.json() {
369                    Ok(json) => json,
370                    Err(e) => {
371                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
372                    }
373                }
374            }
375            Err(e) => {
376                return Err(e);
377            }
378        };
379
380        Ok(processedResponse)
381    }
382
383    pub fn create_domain(&self, project_id: &str, domain: &str) -> Result<models::Domain, AppwriteException> {
384        let path = "/projects/projectId/domains".replace("projectId", &project_id);
385        let  headers: HashMap<String, String> = [
386            ("content-type".to_string(), "application/json".to_string()),
387        ].iter().cloned().collect();
388
389        let  params: HashMap<String, ParamType> = [
390            ("domain".to_string(), ParamType::String(domain.to_string())),
391        ].iter().cloned().collect();
392
393        let response = self.client.clone().call("POST", &path, Some(headers), Some(params) );
394
395        let processedResponse:models::Domain = match response {
396            Ok(r) => {
397                match r.json() {
398                    Ok(json) => json,
399                    Err(e) => {
400                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
401                    }
402                }
403            }
404            Err(e) => {
405                return Err(e);
406            }
407        };
408
409        Ok(processedResponse)
410    }
411
412    pub fn get_domain(&self, project_id: &str, domain_id: &str) -> Result<models::Domain, AppwriteException> {
413        let path = "/projects/projectId/domains/domainId".replace("projectId", &project_id).replace("domainId", &domain_id);
414        let  headers: HashMap<String, String> = [
415            ("content-type".to_string(), "application/json".to_string()),
416        ].iter().cloned().collect();
417
418        let  params: HashMap<String, ParamType> = [
419        ].iter().cloned().collect();
420
421        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
422
423        let processedResponse:models::Domain = match response {
424            Ok(r) => {
425                match r.json() {
426                    Ok(json) => json,
427                    Err(e) => {
428                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
429                    }
430                }
431            }
432            Err(e) => {
433                return Err(e);
434            }
435        };
436
437        Ok(processedResponse)
438    }
439
440    pub fn delete_domain(&self, project_id: &str, domain_id: &str) -> Result<serde_json::value::Value, AppwriteException> {
441        let path = "/projects/projectId/domains/domainId".replace("projectId", &project_id).replace("domainId", &domain_id);
442        let  headers: HashMap<String, String> = [
443            ("content-type".to_string(), "application/json".to_string()),
444        ].iter().cloned().collect();
445
446        let  params: HashMap<String, ParamType> = [
447        ].iter().cloned().collect();
448
449        let response = self.client.clone().call("DELETE", &path, Some(headers), Some(params) );
450
451        match response {
452            Ok(r) => {
453                let status_code = r.status();
454                if status_code == reqwest::StatusCode::NO_CONTENT {
455                    Ok(json!(true))
456                } else {
457                    Ok(serde_json::from_str(&r.text().unwrap()).unwrap())
458                }
459            }
460            Err(e) => {
461                Err(e)
462            }
463        }
464    }
465
466    pub fn update_domain_verification(&self, project_id: &str, domain_id: &str) -> Result<models::Domain, AppwriteException> {
467        let path = "/projects/projectId/domains/domainId/verification".replace("projectId", &project_id).replace("domainId", &domain_id);
468        let  headers: HashMap<String, String> = [
469            ("content-type".to_string(), "application/json".to_string()),
470        ].iter().cloned().collect();
471
472        let  params: HashMap<String, ParamType> = [
473        ].iter().cloned().collect();
474
475        let response = self.client.clone().call("PATCH", &path, Some(headers), Some(params) );
476
477        let processedResponse:models::Domain = match response {
478            Ok(r) => {
479                match r.json() {
480                    Ok(json) => json,
481                    Err(e) => {
482                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
483                    }
484                }
485            }
486            Err(e) => {
487                return Err(e);
488            }
489        };
490
491        Ok(processedResponse)
492    }
493
494    pub fn list_keys(&self, project_id: &str) -> Result<models::KeyList, AppwriteException> {
495        let path = "/projects/projectId/keys".replace("projectId", &project_id);
496        let  headers: HashMap<String, String> = [
497            ("content-type".to_string(), "application/json".to_string()),
498        ].iter().cloned().collect();
499
500        let  params: HashMap<String, ParamType> = [
501        ].iter().cloned().collect();
502
503        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
504
505        let processedResponse:models::KeyList = match response {
506            Ok(r) => {
507                match r.json() {
508                    Ok(json) => json,
509                    Err(e) => {
510                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
511                    }
512                }
513            }
514            Err(e) => {
515                return Err(e);
516            }
517        };
518
519        Ok(processedResponse)
520    }
521
522    pub fn create_key(&self, project_id: &str, name: &str, scopes: &[&str]) -> Result<models::Key, AppwriteException> {
523        let path = "/projects/projectId/keys".replace("projectId", &project_id);
524        let  headers: HashMap<String, String> = [
525            ("content-type".to_string(), "application/json".to_string()),
526        ].iter().cloned().collect();
527
528        let  params: HashMap<String, ParamType> = [
529            ("name".to_string(), ParamType::String(name.to_string())),
530            ("scopes".to_string(), ParamType::Array(scopes.into_iter().map(|x| ParamType::String(x.to_string())).collect())),
531        ].iter().cloned().collect();
532
533        let response = self.client.clone().call("POST", &path, Some(headers), Some(params) );
534
535        let processedResponse:models::Key = match response {
536            Ok(r) => {
537                match r.json() {
538                    Ok(json) => json,
539                    Err(e) => {
540                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
541                    }
542                }
543            }
544            Err(e) => {
545                return Err(e);
546            }
547        };
548
549        Ok(processedResponse)
550    }
551
552    pub fn get_key(&self, project_id: &str, key_id: &str) -> Result<models::Key, AppwriteException> {
553        let path = "/projects/projectId/keys/keyId".replace("projectId", &project_id).replace("keyId", &key_id);
554        let  headers: HashMap<String, String> = [
555            ("content-type".to_string(), "application/json".to_string()),
556        ].iter().cloned().collect();
557
558        let  params: HashMap<String, ParamType> = [
559        ].iter().cloned().collect();
560
561        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
562
563        let processedResponse:models::Key = match response {
564            Ok(r) => {
565                match r.json() {
566                    Ok(json) => json,
567                    Err(e) => {
568                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
569                    }
570                }
571            }
572            Err(e) => {
573                return Err(e);
574            }
575        };
576
577        Ok(processedResponse)
578    }
579
580    pub fn update_key(&self, project_id: &str, key_id: &str, name: &str, scopes: &[&str]) -> Result<models::Key, AppwriteException> {
581        let path = "/projects/projectId/keys/keyId".replace("projectId", &project_id).replace("keyId", &key_id);
582        let  headers: HashMap<String, String> = [
583            ("content-type".to_string(), "application/json".to_string()),
584        ].iter().cloned().collect();
585
586        let  params: HashMap<String, ParamType> = [
587            ("name".to_string(), ParamType::String(name.to_string())),
588            ("scopes".to_string(), ParamType::Array(scopes.into_iter().map(|x| ParamType::String(x.to_string())).collect())),
589        ].iter().cloned().collect();
590
591        let response = self.client.clone().call("PUT", &path, Some(headers), Some(params) );
592
593        let processedResponse:models::Key = match response {
594            Ok(r) => {
595                match r.json() {
596                    Ok(json) => json,
597                    Err(e) => {
598                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
599                    }
600                }
601            }
602            Err(e) => {
603                return Err(e);
604            }
605        };
606
607        Ok(processedResponse)
608    }
609
610    pub fn delete_key(&self, project_id: &str, key_id: &str) -> Result<serde_json::value::Value, AppwriteException> {
611        let path = "/projects/projectId/keys/keyId".replace("projectId", &project_id).replace("keyId", &key_id);
612        let  headers: HashMap<String, String> = [
613            ("content-type".to_string(), "application/json".to_string()),
614        ].iter().cloned().collect();
615
616        let  params: HashMap<String, ParamType> = [
617        ].iter().cloned().collect();
618
619        let response = self.client.clone().call("DELETE", &path, Some(headers), Some(params) );
620
621        match response {
622            Ok(r) => {
623                let status_code = r.status();
624                if status_code == reqwest::StatusCode::NO_CONTENT {
625                    Ok(json!(true))
626                } else {
627                    Ok(serde_json::from_str(&r.text().unwrap()).unwrap())
628                }
629            }
630            Err(e) => {
631                Err(e)
632            }
633        }
634    }
635
636    pub fn update_o_auth2(&self, project_id: &str, provider: &str, app_id: Option<&str>, secret: Option<&str>) -> Result<models::Project, AppwriteException> {
637        let path = "/projects/projectId/oauth2".replace("projectId", &project_id);
638        let  headers: HashMap<String, String> = [
639            ("content-type".to_string(), "application/json".to_string()),
640        ].iter().cloned().collect();
641
642        let app_id:&str = match app_id {
643            Some(data) => data,
644            None => ""
645        };
646
647        let secret:&str = match secret {
648            Some(data) => data,
649            None => ""
650        };
651
652        let  params: HashMap<String, ParamType> = [
653            ("provider".to_string(), ParamType::String(provider.to_string())),
654            ("appId".to_string(), ParamType::String(app_id.to_string())),
655            ("secret".to_string(), ParamType::String(secret.to_string())),
656        ].iter().cloned().collect();
657
658        let response = self.client.clone().call("PATCH", &path, Some(headers), Some(params) );
659
660        let processedResponse:models::Project = match response {
661            Ok(r) => {
662                match r.json() {
663                    Ok(json) => json,
664                    Err(e) => {
665                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
666                    }
667                }
668            }
669            Err(e) => {
670                return Err(e);
671            }
672        };
673
674        Ok(processedResponse)
675    }
676
677    pub fn list_platforms(&self, project_id: &str) -> Result<models::PlatformList, AppwriteException> {
678        let path = "/projects/projectId/platforms".replace("projectId", &project_id);
679        let  headers: HashMap<String, String> = [
680            ("content-type".to_string(), "application/json".to_string()),
681        ].iter().cloned().collect();
682
683        let  params: HashMap<String, ParamType> = [
684        ].iter().cloned().collect();
685
686        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
687
688        let processedResponse:models::PlatformList = match response {
689            Ok(r) => {
690                match r.json() {
691                    Ok(json) => json,
692                    Err(e) => {
693                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
694                    }
695                }
696            }
697            Err(e) => {
698                return Err(e);
699            }
700        };
701
702        Ok(processedResponse)
703    }
704
705    pub fn create_platform(&self, project_id: &str, xtype: &str, name: &str, key: Option<&str>, store: Option<&str>, hostname: Option<&str>) -> Result<models::Platform, AppwriteException> {
706        let path = "/projects/projectId/platforms".replace("projectId", &project_id);
707        let  headers: HashMap<String, String> = [
708            ("content-type".to_string(), "application/json".to_string()),
709        ].iter().cloned().collect();
710
711        let key:&str = match key {
712            Some(data) => data,
713            None => ""
714        };
715
716        let store:&str = match store {
717            Some(data) => data,
718            None => ""
719        };
720
721        let hostname:&str = match hostname {
722            Some(data) => data,
723            None => ""
724        };
725
726        let  params: HashMap<String, ParamType> = [
727            ("type".to_string(), ParamType::String(xtype.to_string())),
728            ("name".to_string(), ParamType::String(name.to_string())),
729            ("key".to_string(), ParamType::String(key.to_string())),
730            ("store".to_string(), ParamType::String(store.to_string())),
731            ("hostname".to_string(), ParamType::String(hostname.to_string())),
732        ].iter().cloned().collect();
733
734        let response = self.client.clone().call("POST", &path, Some(headers), Some(params) );
735
736        let processedResponse:models::Platform = match response {
737            Ok(r) => {
738                match r.json() {
739                    Ok(json) => json,
740                    Err(e) => {
741                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
742                    }
743                }
744            }
745            Err(e) => {
746                return Err(e);
747            }
748        };
749
750        Ok(processedResponse)
751    }
752
753    pub fn get_platform(&self, project_id: &str, platform_id: &str) -> Result<models::Platform, AppwriteException> {
754        let path = "/projects/projectId/platforms/platformId".replace("projectId", &project_id).replace("platformId", &platform_id);
755        let  headers: HashMap<String, String> = [
756            ("content-type".to_string(), "application/json".to_string()),
757        ].iter().cloned().collect();
758
759        let  params: HashMap<String, ParamType> = [
760        ].iter().cloned().collect();
761
762        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
763
764        let processedResponse:models::Platform = match response {
765            Ok(r) => {
766                match r.json() {
767                    Ok(json) => json,
768                    Err(e) => {
769                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
770                    }
771                }
772            }
773            Err(e) => {
774                return Err(e);
775            }
776        };
777
778        Ok(processedResponse)
779    }
780
781    pub fn update_platform(&self, project_id: &str, platform_id: &str, name: &str, key: Option<&str>, store: Option<&str>, hostname: Option<&str>) -> Result<models::Platform, AppwriteException> {
782        let path = "/projects/projectId/platforms/platformId".replace("projectId", &project_id).replace("platformId", &platform_id);
783        let  headers: HashMap<String, String> = [
784            ("content-type".to_string(), "application/json".to_string()),
785        ].iter().cloned().collect();
786
787        let key:&str = match key {
788            Some(data) => data,
789            None => ""
790        };
791
792        let store:&str = match store {
793            Some(data) => data,
794            None => ""
795        };
796
797        let hostname:&str = match hostname {
798            Some(data) => data,
799            None => ""
800        };
801
802        let  params: HashMap<String, ParamType> = [
803            ("name".to_string(), ParamType::String(name.to_string())),
804            ("key".to_string(), ParamType::String(key.to_string())),
805            ("store".to_string(), ParamType::String(store.to_string())),
806            ("hostname".to_string(), ParamType::String(hostname.to_string())),
807        ].iter().cloned().collect();
808
809        let response = self.client.clone().call("PUT", &path, Some(headers), Some(params) );
810
811        let processedResponse:models::Platform = match response {
812            Ok(r) => {
813                match r.json() {
814                    Ok(json) => json,
815                    Err(e) => {
816                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
817                    }
818                }
819            }
820            Err(e) => {
821                return Err(e);
822            }
823        };
824
825        Ok(processedResponse)
826    }
827
828    pub fn delete_platform(&self, project_id: &str, platform_id: &str) -> Result<serde_json::value::Value, AppwriteException> {
829        let path = "/projects/projectId/platforms/platformId".replace("projectId", &project_id).replace("platformId", &platform_id);
830        let  headers: HashMap<String, String> = [
831            ("content-type".to_string(), "application/json".to_string()),
832        ].iter().cloned().collect();
833
834        let  params: HashMap<String, ParamType> = [
835        ].iter().cloned().collect();
836
837        let response = self.client.clone().call("DELETE", &path, Some(headers), Some(params) );
838
839        match response {
840            Ok(r) => {
841                let status_code = r.status();
842                if status_code == reqwest::StatusCode::NO_CONTENT {
843                    Ok(json!(true))
844                } else {
845                    Ok(serde_json::from_str(&r.text().unwrap()).unwrap())
846                }
847            }
848            Err(e) => {
849                Err(e)
850            }
851        }
852    }
853
854    pub fn update_service_status(&self, project_id: &str, service: &str, status: bool) -> Result<models::Project, AppwriteException> {
855        let path = "/projects/projectId/service".replace("projectId", &project_id);
856        let  headers: HashMap<String, String> = [
857            ("content-type".to_string(), "application/json".to_string()),
858        ].iter().cloned().collect();
859
860        let  params: HashMap<String, ParamType> = [
861            ("service".to_string(), ParamType::String(service.to_string())),
862            ("status".to_string(), ParamType::Bool(status)),
863        ].iter().cloned().collect();
864
865        let response = self.client.clone().call("PATCH", &path, Some(headers), Some(params) );
866
867        let processedResponse:models::Project = match response {
868            Ok(r) => {
869                match r.json() {
870                    Ok(json) => json,
871                    Err(e) => {
872                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
873                    }
874                }
875            }
876            Err(e) => {
877                return Err(e);
878            }
879        };
880
881        Ok(processedResponse)
882    }
883
884    pub fn get_usage(&self, project_id: &str, range: Option<&str>) -> Result<models::UsageProject, AppwriteException> {
885        let path = "/projects/projectId/usage".replace("projectId", &project_id);
886        let  headers: HashMap<String, String> = [
887            ("content-type".to_string(), "application/json".to_string()),
888        ].iter().cloned().collect();
889
890        let range:&str = match range {
891            Some(data) => data,
892            None => ""
893        };
894
895        let  params: HashMap<String, ParamType> = [
896            ("range".to_string(), ParamType::String(range.to_string())),
897        ].iter().cloned().collect();
898
899        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
900
901        let processedResponse:models::UsageProject = match response {
902            Ok(r) => {
903                match r.json() {
904                    Ok(json) => json,
905                    Err(e) => {
906                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
907                    }
908                }
909            }
910            Err(e) => {
911                return Err(e);
912            }
913        };
914
915        Ok(processedResponse)
916    }
917
918    pub fn list_webhooks(&self, project_id: &str) -> Result<models::WebhookList, AppwriteException> {
919        let path = "/projects/projectId/webhooks".replace("projectId", &project_id);
920        let  headers: HashMap<String, String> = [
921            ("content-type".to_string(), "application/json".to_string()),
922        ].iter().cloned().collect();
923
924        let  params: HashMap<String, ParamType> = [
925        ].iter().cloned().collect();
926
927        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
928
929        let processedResponse:models::WebhookList = match response {
930            Ok(r) => {
931                match r.json() {
932                    Ok(json) => json,
933                    Err(e) => {
934                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
935                    }
936                }
937            }
938            Err(e) => {
939                return Err(e);
940            }
941        };
942
943        Ok(processedResponse)
944    }
945
946    pub fn create_webhook(&self, project_id: &str, name: &str, events: &[&str], url: &str, security: bool, http_user: Option<&str>, http_pass: Option<&str>) -> Result<models::Webhook, AppwriteException> {
947        let path = "/projects/projectId/webhooks".replace("projectId", &project_id);
948        let  headers: HashMap<String, String> = [
949            ("content-type".to_string(), "application/json".to_string()),
950        ].iter().cloned().collect();
951
952        let http_user:&str = match http_user {
953            Some(data) => data,
954            None => ""
955        };
956
957        let http_pass:&str = match http_pass {
958            Some(data) => data,
959            None => ""
960        };
961
962        let  params: HashMap<String, ParamType> = [
963            ("name".to_string(), ParamType::String(name.to_string())),
964            ("events".to_string(), ParamType::Array(events.into_iter().map(|x| ParamType::String(x.to_string())).collect())),
965            ("url".to_string(), ParamType::String(url.to_string())),
966            ("security".to_string(), ParamType::Bool(security)),
967            ("httpUser".to_string(), ParamType::String(http_user.to_string())),
968            ("httpPass".to_string(), ParamType::String(http_pass.to_string())),
969        ].iter().cloned().collect();
970
971        let response = self.client.clone().call("POST", &path, Some(headers), Some(params) );
972
973        let processedResponse:models::Webhook = match response {
974            Ok(r) => {
975                match r.json() {
976                    Ok(json) => json,
977                    Err(e) => {
978                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
979                    }
980                }
981            }
982            Err(e) => {
983                return Err(e);
984            }
985        };
986
987        Ok(processedResponse)
988    }
989
990    pub fn get_webhook(&self, project_id: &str, webhook_id: &str) -> Result<models::Webhook, AppwriteException> {
991        let path = "/projects/projectId/webhooks/webhookId".replace("projectId", &project_id).replace("webhookId", &webhook_id);
992        let  headers: HashMap<String, String> = [
993            ("content-type".to_string(), "application/json".to_string()),
994        ].iter().cloned().collect();
995
996        let  params: HashMap<String, ParamType> = [
997        ].iter().cloned().collect();
998
999        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
1000
1001        let processedResponse:models::Webhook = match response {
1002            Ok(r) => {
1003                match r.json() {
1004                    Ok(json) => json,
1005                    Err(e) => {
1006                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
1007                    }
1008                }
1009            }
1010            Err(e) => {
1011                return Err(e);
1012            }
1013        };
1014
1015        Ok(processedResponse)
1016    }
1017
1018    pub fn update_webhook(&self, project_id: &str, webhook_id: &str, name: &str, events: &[&str], url: &str, security: bool, http_user: Option<&str>, http_pass: Option<&str>) -> Result<models::Webhook, AppwriteException> {
1019        let path = "/projects/projectId/webhooks/webhookId".replace("projectId", &project_id).replace("webhookId", &webhook_id);
1020        let  headers: HashMap<String, String> = [
1021            ("content-type".to_string(), "application/json".to_string()),
1022        ].iter().cloned().collect();
1023
1024        let http_user:&str = match http_user {
1025            Some(data) => data,
1026            None => ""
1027        };
1028
1029        let http_pass:&str = match http_pass {
1030            Some(data) => data,
1031            None => ""
1032        };
1033
1034        let  params: HashMap<String, ParamType> = [
1035            ("name".to_string(), ParamType::String(name.to_string())),
1036            ("events".to_string(), ParamType::Array(events.into_iter().map(|x| ParamType::String(x.to_string())).collect())),
1037            ("url".to_string(), ParamType::String(url.to_string())),
1038            ("security".to_string(), ParamType::Bool(security)),
1039            ("httpUser".to_string(), ParamType::String(http_user.to_string())),
1040            ("httpPass".to_string(), ParamType::String(http_pass.to_string())),
1041        ].iter().cloned().collect();
1042
1043        let response = self.client.clone().call("PUT", &path, Some(headers), Some(params) );
1044
1045        let processedResponse:models::Webhook = match response {
1046            Ok(r) => {
1047                match r.json() {
1048                    Ok(json) => json,
1049                    Err(e) => {
1050                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
1051                    }
1052                }
1053            }
1054            Err(e) => {
1055                return Err(e);
1056            }
1057        };
1058
1059        Ok(processedResponse)
1060    }
1061
1062    pub fn delete_webhook(&self, project_id: &str, webhook_id: &str) -> Result<serde_json::value::Value, AppwriteException> {
1063        let path = "/projects/projectId/webhooks/webhookId".replace("projectId", &project_id).replace("webhookId", &webhook_id);
1064        let  headers: HashMap<String, String> = [
1065            ("content-type".to_string(), "application/json".to_string()),
1066        ].iter().cloned().collect();
1067
1068        let  params: HashMap<String, ParamType> = [
1069        ].iter().cloned().collect();
1070
1071        let response = self.client.clone().call("DELETE", &path, Some(headers), Some(params) );
1072
1073        match response {
1074            Ok(r) => {
1075                let status_code = r.status();
1076                if status_code == reqwest::StatusCode::NO_CONTENT {
1077                    Ok(json!(true))
1078                } else {
1079                    Ok(serde_json::from_str(&r.text().unwrap()).unwrap())
1080                }
1081            }
1082            Err(e) => {
1083                Err(e)
1084            }
1085        }
1086    }
1087}