cloudflare/endpoints/
user.rs1use surf::http::Method;
2
3use crate::framework::endpoint::Endpoint;
4use crate::framework::ApiResultTraits;
5
6use chrono::{DateTime, Utc};
7
8#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
13pub struct Organization {
14 id: String,
15 name: String,
16 status: String, permissions: Vec<String>, roles: Vec<String>, }
20
21#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
22pub struct UserDetails {
23 pub organizations: Vec<Organization>,
24 #[serde(default)]
25 pub betas: Vec<String>,
26 pub telephone: Option<String>,
27 pub zipcode: Option<String>,
28 pub last_name: Option<String>,
29 pub modified_on: DateTime<Utc>,
30 pub username: String,
31 pub created_on: DateTime<Utc>,
32 pub country: Option<String>,
33 pub two_factor_authentication_enabled: bool,
34 pub first_name: Option<String>,
35 pub id: String,
36 pub suspended: bool,
37 pub email: String,
38}
39impl ApiResultTraits for UserDetails {}
40
41#[test]
42fn handles_empty_betas_field() {
43 const JSON_RESPONSE: &str = r#"
45 {
46 "id": "1234567890abcdef",
47 "email": "user@example.com",
48 "username": "user",
49 "first_name": null,
50 "last_name": null,
51 "telephone": null,
52 "country": null,
53 "zipcode": null,
54 "two_factor_authentication_enabled": false,
55 "two_factor_authentication_locked": false,
56 "created_on": "2015-02-24T13:03:05.255956Z",
57 "modified_on": "2018-06-10T23:50:04.029596Z",
58 "organizations": [],
59 "has_pro_zones": false,
60 "has_business_zones": false,
61 "has_enterprise_zones": false,
62 "suspended": false
63 }"#;
64
65 let user_details: UserDetails = serde_json::from_str(JSON_RESPONSE).unwrap();
66 assert!(user_details.betas.is_empty());
67}
68
69#[derive(Debug)]
70pub struct GetUserDetails {}
71
72impl<'a> Endpoint<UserDetails, (), ()> for GetUserDetails {
73 fn method(&self) -> Method {
74 Method::Get
75 }
76 fn path(&self) -> String {
77 "user".to_string()
78 }
79}
80
81#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
86pub struct UserTokenStatus {
87 pub id: String,
88 pub status: String,
89}
90impl ApiResultTraits for UserTokenStatus {}
91
92#[derive(Debug)]
93pub struct GetUserTokenStatus {}
94
95impl<'a> Endpoint<UserTokenStatus, (), ()> for GetUserTokenStatus {
96 fn method(&self) -> Method {
97 Method::Get
98 }
99 fn path(&self) -> String {
100 "user/tokens/verify".to_string()
101 }
102}