aw_test/services/
account.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 Account {
10  client: Client
11}
12
13impl Account {  
14    pub fn new(client: &Client) -> Self {
15        Self {
16            client: client.clone()
17        }
18    }
19
20    /// Get currently logged in user data as JSON object.
21    pub fn get(&self) -> Result<models::User, AppwriteException> {
22        let path = "/account";
23        let  headers: HashMap<String, String> = [
24            ("content-type".to_string(), "application/json".to_string()),
25        ].iter().cloned().collect();
26
27        let  params: HashMap<String, ParamType> = [
28        ].iter().cloned().collect();
29
30        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
31
32        let processedResponse:models::User = match response {
33            Ok(r) => {
34                match r.json() {
35                    Ok(json) => json,
36                    Err(e) => {
37                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
38                    }
39                }
40            }
41            Err(e) => {
42                return Err(e);
43            }
44        };
45
46        Ok(processedResponse)
47    }
48
49    /// Use this endpoint to allow a new user to register a new account in your
50    /// project. After the user registration completes successfully, you can use
51    /// the [/account/verfication](/docs/client/account#accountCreateVerification)
52    /// route to start verifying the user email address. To allow the new user to
53    /// login to their new account, you need to create a new [account
54    /// session](/docs/client/account#accountCreateSession).
55    pub fn create(&self, user_id: &str, email: &str, password: &str, name: Option<&str>) -> Result<models::User, AppwriteException> {
56        let path = "/account";
57        let  headers: HashMap<String, String> = [
58            ("content-type".to_string(), "application/json".to_string()),
59        ].iter().cloned().collect();
60
61        let name:&str = match name {
62            Some(data) => data,
63            None => ""
64        };
65
66        let  params: HashMap<String, ParamType> = [
67            ("userId".to_string(), ParamType::String(user_id.to_string())),
68            ("email".to_string(), ParamType::String(email.to_string())),
69            ("password".to_string(), ParamType::String(password.to_string())),
70            ("name".to_string(), ParamType::String(name.to_string())),
71        ].iter().cloned().collect();
72
73        let response = self.client.clone().call("POST", &path, Some(headers), Some(params) );
74
75        let processedResponse:models::User = match response {
76            Ok(r) => {
77                match r.json() {
78                    Ok(json) => json,
79                    Err(e) => {
80                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
81                    }
82                }
83            }
84            Err(e) => {
85                return Err(e);
86            }
87        };
88
89        Ok(processedResponse)
90    }
91
92    /// Delete a currently logged in user account. Behind the scene, the user
93    /// record is not deleted but permanently blocked from any access. This is done
94    /// to avoid deleted accounts being overtaken by new users with the same email
95    /// address. Any user-related resources like documents or storage files should
96    /// be deleted separately.
97    pub fn delete(&self) -> Result<serde_json::value::Value, AppwriteException> {
98        let path = "/account";
99        let  headers: HashMap<String, String> = [
100            ("content-type".to_string(), "application/json".to_string()),
101        ].iter().cloned().collect();
102
103        let  params: HashMap<String, ParamType> = [
104        ].iter().cloned().collect();
105
106        let response = self.client.clone().call("DELETE", &path, Some(headers), Some(params) );
107
108        match response {
109            Ok(r) => {
110                let status_code = r.status();
111                if status_code == reqwest::StatusCode::NO_CONTENT {
112                    Ok(json!(true))
113                } else {
114                    Ok(serde_json::from_str(&r.text().unwrap()).unwrap())
115                }
116            }
117            Err(e) => {
118                Err(e)
119            }
120        }
121    }
122
123    /// Update currently logged in user account email address. After changing user
124    /// address, the user confirmation status will get reset. A new confirmation
125    /// email is not sent automatically however you can use the send confirmation
126    /// email endpoint again to send the confirmation email. For security measures,
127    /// user password is required to complete this request.
128    /// This endpoint can also be used to convert an anonymous account to a normal
129    /// one, by passing an email address and a new password.
130    /// 
131    pub fn update_email(&self, email: &str, password: &str) -> Result<models::User, AppwriteException> {
132        let path = "/account/email";
133        let  headers: HashMap<String, String> = [
134            ("content-type".to_string(), "application/json".to_string()),
135        ].iter().cloned().collect();
136
137        let  params: HashMap<String, ParamType> = [
138            ("email".to_string(), ParamType::String(email.to_string())),
139            ("password".to_string(), ParamType::String(password.to_string())),
140        ].iter().cloned().collect();
141
142        let response = self.client.clone().call("PATCH", &path, Some(headers), Some(params) );
143
144        let processedResponse:models::User = match response {
145            Ok(r) => {
146                match r.json() {
147                    Ok(json) => json,
148                    Err(e) => {
149                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
150                    }
151                }
152            }
153            Err(e) => {
154                return Err(e);
155            }
156        };
157
158        Ok(processedResponse)
159    }
160
161    /// Use this endpoint to create a JSON Web Token. You can use the resulting JWT
162    /// to authenticate on behalf of the current user when working with the
163    /// Appwrite server-side API and SDKs. The JWT secret is valid for 15 minutes
164    /// from its creation and will be invalid if the user will logout in that time
165    /// frame.
166    pub fn create_jwt(&self) -> Result<models::Jwt, AppwriteException> {
167        let path = "/account/jwt";
168        let  headers: HashMap<String, String> = [
169            ("content-type".to_string(), "application/json".to_string()),
170        ].iter().cloned().collect();
171
172        let  params: HashMap<String, ParamType> = [
173        ].iter().cloned().collect();
174
175        let response = self.client.clone().call("POST", &path, Some(headers), Some(params) );
176
177        let processedResponse:models::Jwt = match response {
178            Ok(r) => {
179                match r.json() {
180                    Ok(json) => json,
181                    Err(e) => {
182                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
183                    }
184                }
185            }
186            Err(e) => {
187                return Err(e);
188            }
189        };
190
191        Ok(processedResponse)
192    }
193
194    /// Get currently logged in user list of latest security activity logs. Each
195    /// log returns user IP address, location and date and time of log.
196    pub fn get_logs(&self, limit: Option<i64>, offset: Option<i64>) -> Result<models::LogList, AppwriteException> {
197        let path = "/account/logs";
198        let  headers: HashMap<String, String> = [
199            ("content-type".to_string(), "application/json".to_string()),
200        ].iter().cloned().collect();
201
202        let  params: HashMap<String, ParamType> = [
203            ("limit".to_string(),  ParamType::OptionalNumber(limit)),
204            ("offset".to_string(),  ParamType::OptionalNumber(offset)),
205        ].iter().cloned().collect();
206
207        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
208
209        let processedResponse:models::LogList = match response {
210            Ok(r) => {
211                match r.json() {
212                    Ok(json) => json,
213                    Err(e) => {
214                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
215                    }
216                }
217            }
218            Err(e) => {
219                return Err(e);
220            }
221        };
222
223        Ok(processedResponse)
224    }
225
226    /// Update currently logged in user account name.
227    pub fn update_name(&self, name: &str) -> Result<models::User, AppwriteException> {
228        let path = "/account/name";
229        let  headers: HashMap<String, String> = [
230            ("content-type".to_string(), "application/json".to_string()),
231        ].iter().cloned().collect();
232
233        let  params: HashMap<String, ParamType> = [
234            ("name".to_string(), ParamType::String(name.to_string())),
235        ].iter().cloned().collect();
236
237        let response = self.client.clone().call("PATCH", &path, Some(headers), Some(params) );
238
239        let processedResponse:models::User = match response {
240            Ok(r) => {
241                match r.json() {
242                    Ok(json) => json,
243                    Err(e) => {
244                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
245                    }
246                }
247            }
248            Err(e) => {
249                return Err(e);
250            }
251        };
252
253        Ok(processedResponse)
254    }
255
256    /// Update currently logged in user password. For validation, user is required
257    /// to pass in the new password, and the old password. For users created with
258    /// OAuth and Team Invites, oldPassword is optional.
259    pub fn update_password(&self, password: &str, old_password: Option<&str>) -> Result<models::User, AppwriteException> {
260        let path = "/account/password";
261        let  headers: HashMap<String, String> = [
262            ("content-type".to_string(), "application/json".to_string()),
263        ].iter().cloned().collect();
264
265        let old_password:&str = match old_password {
266            Some(data) => data,
267            None => ""
268        };
269
270        let  params: HashMap<String, ParamType> = [
271            ("password".to_string(), ParamType::String(password.to_string())),
272            ("oldPassword".to_string(), ParamType::String(old_password.to_string())),
273        ].iter().cloned().collect();
274
275        let response = self.client.clone().call("PATCH", &path, Some(headers), Some(params) );
276
277        let processedResponse:models::User = match response {
278            Ok(r) => {
279                match r.json() {
280                    Ok(json) => json,
281                    Err(e) => {
282                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
283                    }
284                }
285            }
286            Err(e) => {
287                return Err(e);
288            }
289        };
290
291        Ok(processedResponse)
292    }
293
294    /// Get currently logged in user preferences as a key-value object.
295    pub fn get_prefs(&self) -> Result<models::Preferences, AppwriteException> {
296        let path = "/account/prefs";
297        let  headers: HashMap<String, String> = [
298            ("content-type".to_string(), "application/json".to_string()),
299        ].iter().cloned().collect();
300
301        let  params: HashMap<String, ParamType> = [
302        ].iter().cloned().collect();
303
304        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
305
306        let processedResponse:models::Preferences = match response {
307            Ok(r) => {
308                match r.json() {
309                    Ok(json) => json,
310                    Err(e) => {
311                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
312                    }
313                }
314            }
315            Err(e) => {
316                return Err(e);
317            }
318        };
319
320        Ok(processedResponse)
321    }
322
323    /// Update currently logged in user account preferences. The object you pass is
324    /// stored as is, and replaces any previous value. The maximum allowed prefs
325    /// size is 64kB and throws error if exceeded.
326    pub fn update_prefs(&self, prefs: Option<HashMap<String, crate::client::ParamType>>) -> Result<models::User, AppwriteException> {
327        let path = "/account/prefs";
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            ("prefs".to_string(), ParamType::Object(prefs.unwrap())),
334        ].iter().cloned().collect();
335
336        let response = self.client.clone().call("PATCH", &path, Some(headers), Some(params) );
337
338        let processedResponse:models::User = 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    /// Sends the user an email with a temporary secret key for password reset.
356    /// When the user clicks the confirmation link he is redirected back to your
357    /// app password reset URL with the secret key and email address values
358    /// attached to the URL query string. Use the query string params to submit a
359    /// request to the [PUT
360    /// /account/recovery](/docs/client/account#accountUpdateRecovery) endpoint to
361    /// complete the process. The verification link sent to the user's email
362    /// address is valid for 1 hour.
363    pub fn create_recovery(&self, email: &str, url: &str) -> Result<models::Token, AppwriteException> {
364        let path = "/account/recovery";
365        let  headers: HashMap<String, String> = [
366            ("content-type".to_string(), "application/json".to_string()),
367        ].iter().cloned().collect();
368
369        let  params: HashMap<String, ParamType> = [
370            ("email".to_string(), ParamType::String(email.to_string())),
371            ("url".to_string(), ParamType::String(url.to_string())),
372        ].iter().cloned().collect();
373
374        let response = self.client.clone().call("POST", &path, Some(headers), Some(params) );
375
376        let processedResponse:models::Token = match response {
377            Ok(r) => {
378                match r.json() {
379                    Ok(json) => json,
380                    Err(e) => {
381                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
382                    }
383                }
384            }
385            Err(e) => {
386                return Err(e);
387            }
388        };
389
390        Ok(processedResponse)
391    }
392
393    /// Use this endpoint to complete the user account password reset. Both the
394    /// **userId** and **secret** arguments will be passed as query parameters to
395    /// the redirect URL you have provided when sending your request to the [POST
396    /// /account/recovery](/docs/client/account#accountCreateRecovery) endpoint.
397    /// 
398    /// Please note that in order to avoid a [Redirect
399    /// Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md)
400    /// the only valid redirect URLs are the ones from domains you have set when
401    /// adding your platforms in the console interface.
402    pub fn update_recovery(&self, user_id: &str, secret: &str, password: &str, password_again: &str) -> Result<models::Token, AppwriteException> {
403        let path = "/account/recovery";
404        let  headers: HashMap<String, String> = [
405            ("content-type".to_string(), "application/json".to_string()),
406        ].iter().cloned().collect();
407
408        let  params: HashMap<String, ParamType> = [
409            ("userId".to_string(), ParamType::String(user_id.to_string())),
410            ("secret".to_string(), ParamType::String(secret.to_string())),
411            ("password".to_string(), ParamType::String(password.to_string())),
412            ("passwordAgain".to_string(), ParamType::String(password_again.to_string())),
413        ].iter().cloned().collect();
414
415        let response = self.client.clone().call("PUT", &path, Some(headers), Some(params) );
416
417        let processedResponse:models::Token = match response {
418            Ok(r) => {
419                match r.json() {
420                    Ok(json) => json,
421                    Err(e) => {
422                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
423                    }
424                }
425            }
426            Err(e) => {
427                return Err(e);
428            }
429        };
430
431        Ok(processedResponse)
432    }
433
434    /// Get currently logged in user list of active sessions across different
435    /// devices.
436    pub fn get_sessions(&self) -> Result<models::SessionList, AppwriteException> {
437        let path = "/account/sessions";
438        let  headers: HashMap<String, String> = [
439            ("content-type".to_string(), "application/json".to_string()),
440        ].iter().cloned().collect();
441
442        let  params: HashMap<String, ParamType> = [
443        ].iter().cloned().collect();
444
445        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
446
447        let processedResponse:models::SessionList = match response {
448            Ok(r) => {
449                match r.json() {
450                    Ok(json) => json,
451                    Err(e) => {
452                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
453                    }
454                }
455            }
456            Err(e) => {
457                return Err(e);
458            }
459        };
460
461        Ok(processedResponse)
462    }
463
464    /// Allow the user to login into their account by providing a valid email and
465    /// password combination. This route will create a new session for the user.
466    pub fn create_session(&self, email: &str, password: &str) -> Result<models::Session, AppwriteException> {
467        let path = "/account/sessions";
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            ("email".to_string(), ParamType::String(email.to_string())),
474            ("password".to_string(), ParamType::String(password.to_string())),
475        ].iter().cloned().collect();
476
477        let response = self.client.clone().call("POST", &path, Some(headers), Some(params) );
478
479        let processedResponse:models::Session = match response {
480            Ok(r) => {
481                match r.json() {
482                    Ok(json) => json,
483                    Err(e) => {
484                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
485                    }
486                }
487            }
488            Err(e) => {
489                return Err(e);
490            }
491        };
492
493        Ok(processedResponse)
494    }
495
496    /// Delete all sessions from the user account and remove any sessions cookies
497    /// from the end client.
498    pub fn delete_sessions(&self) -> Result<serde_json::value::Value, AppwriteException> {
499        let path = "/account/sessions";
500        let  headers: HashMap<String, String> = [
501            ("content-type".to_string(), "application/json".to_string()),
502        ].iter().cloned().collect();
503
504        let  params: HashMap<String, ParamType> = [
505        ].iter().cloned().collect();
506
507        let response = self.client.clone().call("DELETE", &path, Some(headers), Some(params) );
508
509        match response {
510            Ok(r) => {
511                let status_code = r.status();
512                if status_code == reqwest::StatusCode::NO_CONTENT {
513                    Ok(json!(true))
514                } else {
515                    Ok(serde_json::from_str(&r.text().unwrap()).unwrap())
516                }
517            }
518            Err(e) => {
519                Err(e)
520            }
521        }
522    }
523
524    /// Use this endpoint to allow a new user to register an anonymous account in
525    /// your project. This route will also create a new session for the user. To
526    /// allow the new user to convert an anonymous account to a normal account, you
527    /// need to update its [email and
528    /// password](/docs/client/account#accountUpdateEmail) or create an [OAuth2
529    /// session](/docs/client/account#accountCreateOAuth2Session).
530    pub fn create_anonymous_session(&self) -> Result<models::Session, AppwriteException> {
531        let path = "/account/sessions/anonymous";
532        let  headers: HashMap<String, String> = [
533            ("content-type".to_string(), "application/json".to_string()),
534        ].iter().cloned().collect();
535
536        let  params: HashMap<String, ParamType> = [
537        ].iter().cloned().collect();
538
539        let response = self.client.clone().call("POST", &path, Some(headers), Some(params) );
540
541        let processedResponse:models::Session = match response {
542            Ok(r) => {
543                match r.json() {
544                    Ok(json) => json,
545                    Err(e) => {
546                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
547                    }
548                }
549            }
550            Err(e) => {
551                return Err(e);
552            }
553        };
554
555        Ok(processedResponse)
556    }
557
558    /// Sends the user an email with a secret key for creating a session. When the
559    /// user clicks the link in the email, the user is redirected back to the URL
560    /// you provided with the secret key and userId values attached to the URL
561    /// query string. Use the query string parameters to submit a request to the
562    /// [PUT
563    /// /account/sessions/magic-url](/docs/client/account#accountUpdateMagicURLSession)
564    /// endpoint to complete the login process. The link sent to the user's email
565    /// address is valid for 1 hour. If you are on a mobile device you can leave
566    /// the URL parameter empty, so that the login completion will be handled by
567    /// your Appwrite instance by default.
568    pub fn create_magic_url_session(&self, user_id: &str, email: &str, url: Option<&str>) -> Result<models::Token, AppwriteException> {
569        let path = "/account/sessions/magic-url";
570        let  headers: HashMap<String, String> = [
571            ("content-type".to_string(), "application/json".to_string()),
572        ].iter().cloned().collect();
573
574        let url:&str = match url {
575            Some(data) => data,
576            None => ""
577        };
578
579        let  params: HashMap<String, ParamType> = [
580            ("userId".to_string(), ParamType::String(user_id.to_string())),
581            ("email".to_string(), ParamType::String(email.to_string())),
582            ("url".to_string(), ParamType::String(url.to_string())),
583        ].iter().cloned().collect();
584
585        let response = self.client.clone().call("POST", &path, Some(headers), Some(params) );
586
587        let processedResponse:models::Token = match response {
588            Ok(r) => {
589                match r.json() {
590                    Ok(json) => json,
591                    Err(e) => {
592                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
593                    }
594                }
595            }
596            Err(e) => {
597                return Err(e);
598            }
599        };
600
601        Ok(processedResponse)
602    }
603
604    /// Use this endpoint to complete creating the session with the Magic URL. Both
605    /// the **userId** and **secret** arguments will be passed as query parameters
606    /// to the redirect URL you have provided when sending your request to the
607    /// [POST
608    /// /account/sessions/magic-url](/docs/client/account#accountCreateMagicURLSession)
609    /// endpoint.
610    /// 
611    /// Please note that in order to avoid a [Redirect
612    /// Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md)
613    /// the only valid redirect URLs are the ones from domains you have set when
614    /// adding your platforms in the console interface.
615    pub fn update_magic_url_session(&self, user_id: &str, secret: &str) -> Result<models::Session, AppwriteException> {
616        let path = "/account/sessions/magic-url";
617        let  headers: HashMap<String, String> = [
618            ("content-type".to_string(), "application/json".to_string()),
619        ].iter().cloned().collect();
620
621        let  params: HashMap<String, ParamType> = [
622            ("userId".to_string(), ParamType::String(user_id.to_string())),
623            ("secret".to_string(), ParamType::String(secret.to_string())),
624        ].iter().cloned().collect();
625
626        let response = self.client.clone().call("PUT", &path, Some(headers), Some(params) );
627
628        let processedResponse:models::Session = match response {
629            Ok(r) => {
630                match r.json() {
631                    Ok(json) => json,
632                    Err(e) => {
633                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
634                    }
635                }
636            }
637            Err(e) => {
638                return Err(e);
639            }
640        };
641
642        Ok(processedResponse)
643    }
644
645    /// Allow the user to login to their account using the OAuth2 provider of their
646    /// choice. Each OAuth2 provider should be enabled from the Appwrite console
647    /// first. Use the success and failure arguments to provide a redirect URL's
648    /// back to your app when login is completed.
649    /// 
650    /// If there is already an active session, the new session will be attached to
651    /// the logged-in account. If there are no active sessions, the server will
652    /// attempt to look for a user with the same email address as the email
653    /// received from the OAuth2 provider and attach the new session to the
654    /// existing user. If no matching user is found - the server will create a new
655    /// user..
656    /// 
657    pub fn create_o_auth2_session(&self, provider: &str, success: Option<&str>, failure: Option<&str>, scopes: Option<&[&str]>) -> Result<serde_json::value::Value, AppwriteException> {
658        let path = "/account/sessions/oauth2/provider".replace("provider", &provider);
659        let  headers: HashMap<String, String> = [
660            ("content-type".to_string(), "application/json".to_string()),
661        ].iter().cloned().collect();
662
663        let success:&str = match success {
664            Some(data) => data,
665            None => ""
666        };
667
668        let failure:&str = match failure {
669            Some(data) => data,
670            None => ""
671        };
672
673        let scopes:&[&str] = match scopes {
674            Some(data) => data,
675            None => &[]
676        };
677
678        let  params: HashMap<String, ParamType> = [
679            ("success".to_string(), ParamType::String(success.to_string())),
680            ("failure".to_string(), ParamType::String(failure.to_string())),
681            ("scopes".to_string(), ParamType::Array(scopes.into_iter().map(|x| ParamType::String(x.to_string())).collect())),
682        ].iter().cloned().collect();
683
684        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
685
686        match response {
687            Ok(r) => {
688                let status_code = r.status();
689                if status_code == reqwest::StatusCode::NO_CONTENT {
690                    Ok(json!(true))
691                } else {
692                    Ok(serde_json::from_str(&r.text().unwrap()).unwrap())
693                }
694            }
695            Err(e) => {
696                Err(e)
697            }
698        }
699    }
700
701    /// Use this endpoint to get a logged in user's session using a Session ID.
702    /// Inputting 'current' will return the current session being used.
703    pub fn get_session(&self, session_id: &str) -> Result<models::Session, AppwriteException> {
704        let path = "/account/sessions/sessionId".replace("sessionId", &session_id);
705        let  headers: HashMap<String, String> = [
706            ("content-type".to_string(), "application/json".to_string()),
707        ].iter().cloned().collect();
708
709        let  params: HashMap<String, ParamType> = [
710        ].iter().cloned().collect();
711
712        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
713
714        let processedResponse:models::Session = match response {
715            Ok(r) => {
716                match r.json() {
717                    Ok(json) => json,
718                    Err(e) => {
719                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
720                    }
721                }
722            }
723            Err(e) => {
724                return Err(e);
725            }
726        };
727
728        Ok(processedResponse)
729    }
730
731    pub fn update_session(&self, session_id: &str) -> Result<models::Session, AppwriteException> {
732        let path = "/account/sessions/sessionId".replace("sessionId", &session_id);
733        let  headers: HashMap<String, String> = [
734            ("content-type".to_string(), "application/json".to_string()),
735        ].iter().cloned().collect();
736
737        let  params: HashMap<String, ParamType> = [
738        ].iter().cloned().collect();
739
740        let response = self.client.clone().call("PATCH", &path, Some(headers), Some(params) );
741
742        let processedResponse:models::Session = match response {
743            Ok(r) => {
744                match r.json() {
745                    Ok(json) => json,
746                    Err(e) => {
747                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
748                    }
749                }
750            }
751            Err(e) => {
752                return Err(e);
753            }
754        };
755
756        Ok(processedResponse)
757    }
758
759    /// Use this endpoint to log out the currently logged in user from all their
760    /// account sessions across all of their different devices. When using the
761    /// Session ID argument, only the unique session ID provided is deleted.
762    /// 
763    pub fn delete_session(&self, session_id: &str) -> Result<serde_json::value::Value, AppwriteException> {
764        let path = "/account/sessions/sessionId".replace("sessionId", &session_id);
765        let  headers: HashMap<String, String> = [
766            ("content-type".to_string(), "application/json".to_string()),
767        ].iter().cloned().collect();
768
769        let  params: HashMap<String, ParamType> = [
770        ].iter().cloned().collect();
771
772        let response = self.client.clone().call("DELETE", &path, Some(headers), Some(params) );
773
774        match response {
775            Ok(r) => {
776                let status_code = r.status();
777                if status_code == reqwest::StatusCode::NO_CONTENT {
778                    Ok(json!(true))
779                } else {
780                    Ok(serde_json::from_str(&r.text().unwrap()).unwrap())
781                }
782            }
783            Err(e) => {
784                Err(e)
785            }
786        }
787    }
788
789    /// Use this endpoint to send a verification message to your user email address
790    /// to confirm they are the valid owners of that address. Both the **userId**
791    /// and **secret** arguments will be passed as query parameters to the URL you
792    /// have provided to be attached to the verification email. The provided URL
793    /// should redirect the user back to your app and allow you to complete the
794    /// verification process by verifying both the **userId** and **secret**
795    /// parameters. Learn more about how to [complete the verification
796    /// process](/docs/client/account#accountUpdateVerification). The verification
797    /// link sent to the user's email address is valid for 7 days.
798    /// 
799    /// Please note that in order to avoid a [Redirect
800    /// Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md),
801    /// the only valid redirect URLs are the ones from domains you have set when
802    /// adding your platforms in the console interface.
803    /// 
804    pub fn create_verification(&self, url: &str) -> Result<models::Token, AppwriteException> {
805        let path = "/account/verification";
806        let  headers: HashMap<String, String> = [
807            ("content-type".to_string(), "application/json".to_string()),
808        ].iter().cloned().collect();
809
810        let  params: HashMap<String, ParamType> = [
811            ("url".to_string(), ParamType::String(url.to_string())),
812        ].iter().cloned().collect();
813
814        let response = self.client.clone().call("POST", &path, Some(headers), Some(params) );
815
816        let processedResponse:models::Token = match response {
817            Ok(r) => {
818                match r.json() {
819                    Ok(json) => json,
820                    Err(e) => {
821                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
822                    }
823                }
824            }
825            Err(e) => {
826                return Err(e);
827            }
828        };
829
830        Ok(processedResponse)
831    }
832
833    /// Use this endpoint to complete the user email verification process. Use both
834    /// the **userId** and **secret** parameters that were attached to your app URL
835    /// to verify the user email ownership. If confirmed this route will return a
836    /// 200 status code.
837    pub fn update_verification(&self, user_id: &str, secret: &str) -> Result<models::Token, AppwriteException> {
838        let path = "/account/verification";
839        let  headers: HashMap<String, String> = [
840            ("content-type".to_string(), "application/json".to_string()),
841        ].iter().cloned().collect();
842
843        let  params: HashMap<String, ParamType> = [
844            ("userId".to_string(), ParamType::String(user_id.to_string())),
845            ("secret".to_string(), ParamType::String(secret.to_string())),
846        ].iter().cloned().collect();
847
848        let response = self.client.clone().call("PUT", &path, Some(headers), Some(params) );
849
850        let processedResponse:models::Token = match response {
851            Ok(r) => {
852                match r.json() {
853                    Ok(json) => json,
854                    Err(e) => {
855                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
856                    }
857                }
858            }
859            Err(e) => {
860                return Err(e);
861            }
862        };
863
864        Ok(processedResponse)
865    }
866}