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