monzo/endpoints/
pots.rs

1//! endpoints for working with Monzo pots
2
3use chrono::{DateTime, Utc};
4use serde::Deserialize;
5
6use crate::endpoints::utils::empty_string_as_none;
7
8mod list;
9pub use list::Request as List;
10mod deposit;
11pub use deposit::Request as Deposit;
12mod withdraw;
13pub use withdraw::Request as Withdraw;
14
15/// Representation of a Monzo pot
16#[derive(Deserialize, Debug, Clone, PartialEq, Eq)]
17#[non_exhaustive]
18pub struct Pot {
19    /// Unique ID for this Monzo pot
20    pub id: String,
21
22    /// The human-readable name for this pot
23    pub name: String,
24
25    /// A reference to the built in Monzo image for this pot
26    #[serde(deserialize_with = "empty_string_as_none")]
27    pub style: Option<String>,
28
29    /// The pot balance, in the minor units of the specified currency
30    pub balance: i64,
31
32    /// Three letter code for the pot's currency
33    pub currency: String,
34
35    /// The goal balance for this pot, if set
36    #[serde(default)]
37    pub goal_amount: Option<i64>,
38
39    /// The unique ID of the account associated with this pot
40    pub current_account_id: String,
41
42    /// The datetime that the pot was created
43    pub created: DateTime<Utc>,
44
45    /// The datetime that the pot was last modified
46    pub updated: DateTime<Utc>,
47
48    /// true if the pot has been deleted
49    ///
50    /// *Note that in future the API will simply not return pots which have been
51    /// deleted*
52    pub deleted: bool,
53}
54
55#[cfg(test)]
56mod tests {
57
58    use super::Pot;
59
60    #[test]
61    fn deserialise() {
62        let raw = r#"
63        {
64            "id": "pot_1234",
65            "name": "Savings",
66            "style": "teal",
67            "balance": 10,
68            "currency": "GBP",
69            "goal_amount": 1000000,
70            "type": "flexible_savings",
71            "product_id": "XXX",
72            "current_account_id": "acc_1234",
73            "cover_image_url": "",
74            "isa_wrapper": "ISA",
75            "round_up": false,
76            "round_up_multiplier": null,
77            "is_tax_pot": false,
78            "created": "2019-04-28T06:36:54.318Z",
79            "updated": "2019-05-11T00:31:04.256Z",
80            "deleted": false,
81            "locked": false,
82            "charity_id": "",
83            "available_for_bills": false
84        }
85        "#;
86
87        serde_json::from_str::<Pot>(raw).expect("couldn't decode Pot from json");
88    }
89}