dnsimple/dnsimple/
identity.rs1use serde::{Deserialize, Serialize};
2
3use crate::dnsimple::{Client, DNSimpleResponse, Endpoint};
4use crate::errors::DNSimpleError;
5
6#[derive(Debug, Deserialize, Serialize)]
8pub struct User {
9 pub id: u64,
11 pub email: String,
13 pub created_at: String,
15 pub updated_at: String,
17}
18
19#[derive(Debug, Deserialize, Serialize)]
21pub struct Account {
22 pub id: u64,
24 pub email: String,
26 pub plan_identifier: String,
28 pub created_at: String,
30 pub updated_at: String,
32}
33
34#[derive(Debug, Deserialize, Serialize)]
36pub struct WhoamiData {
37 pub account: Option<Account>,
39 pub user: Option<User>,
41}
42
43struct IdentityEndpoint;
44
45impl Endpoint for IdentityEndpoint {
46 type Output = WhoamiData;
47}
48
49pub struct Identity<'a> {
53 pub client: &'a Client,
54}
55
56impl Identity<'_> {
57 pub fn whoami(&self) -> Result<DNSimpleResponse<WhoamiData>, DNSimpleError> {
70 self.client.get::<IdentityEndpoint>("/whoami", None)
71 }
72}
73
74#[cfg(test)]
75mod tests {
76 use crate::dnsimple::identity;
77
78 #[test]
79 fn user_fields() {
80 let user = identity::User {
81 id: 12,
82 email: String::from("testing@dnsimple.com"),
83 created_at: String::from("some_time_ago"),
84 updated_at: String::from("recently"),
85 };
86
87 assert_eq!("testing@dnsimple.com", user.email)
88 }
89
90 #[test]
91 fn account_fields() {
92 let account = identity::Account {
93 id: 14,
94 email: String::from("account@dnsimple.com"),
95 plan_identifier: String::from("testing_plan"),
96 created_at: String::from("some_time_ago"),
97 updated_at: String::from("recently"),
98 };
99
100 assert_eq!("testing_plan", account.plan_identifier)
101 }
102}