digitalocean_api/api/
account.rs

1use super::{HasResponse, HasValue};
2use crate::method::Get;
3use crate::request::AccountRequest;
4use crate::request::Request;
5use crate::{ROOT_URL, STATIC_URL_ERROR};
6use getset::{Getters, Setters};
7use serde::Deserialize;
8use serde::Serialize;
9
10const ACCOUNT_SEGMENT: &str = "account";
11
12/// The user account.
13///
14/// [Digital Ocean Documentation.](https://developers.digitalocean.com/documentation/v2/#account)
15#[derive(Deserialize, Serialize, Debug, Clone, Getters, Setters)]
16#[get = "pub"]
17pub struct Account {
18    /// The total number of droplets the user may have.
19    droplet_limit: usize,
20
21    /// The total number of floating IPs the user may have.
22    floating_ip_limit: usize,
23
24    /// The email the user has registered for Digital Ocean with.
25    email: String,
26
27    /// The universal identifier for this user.
28    uuid: String,
29
30    /// If true, the user has verified their account via email. False otherwise.
31    email_verified: bool,
32
33    /// This value is one of "active", "warning" or "locked".
34    status: String,
35
36    /// A human-readable message giving more details about the status of the
37    /// account.
38    status_message: String,
39}
40
41impl Account {
42    /// [Digital Ocean Documentation.](https://developers.digitalocean.com/documentation/v2/#get-user-information)
43    pub fn get() -> AccountRequest<Get, Account> {
44        let mut url = ROOT_URL.clone();
45        url.path_segments_mut()
46            .expect(STATIC_URL_ERROR)
47            .push(ACCOUNT_SEGMENT);
48
49        Request::new(url)
50    }
51}
52
53/// Response type returned from Digital Ocean.
54#[derive(Deserialize, Serialize, Debug, Clone)]
55pub struct AccountResponse {
56    account: Account,
57}
58
59impl HasResponse for Account {
60    type Response = AccountResponse;
61}
62
63impl HasValue for AccountResponse {
64    type Value = Account;
65
66    fn value(self) -> Account {
67        self.account
68    }
69}