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
use crate::{endpoints::handle_response, Result};
use chrono::{DateTime, Utc};
use serde::Deserialize;
#[derive(Deserialize, Debug)]
struct Accounts {
accounts: Vec<Account>,
}
#[derive(Deserialize, Debug)]
pub struct Account {
pub id: String,
closed: bool,
pub created: DateTime<Utc>,
pub description: String,
r#type: String,
currency: String,
country_code: String,
owners: Vec<Owner>,
account_number: String,
sort_code: String,
}
#[derive(Deserialize, Debug)]
struct Owner {
user_id: String,
preferred_name: String,
preferred_first_name: String,
}
pub struct ListAccounts {
request_builder: reqwest::RequestBuilder,
}
impl ListAccounts {
pub(crate) fn new(http_client: &reqwest::Client, access_token: impl AsRef<str>) -> Self {
let request_builder = http_client
.get("https://api.monzo.com/accounts")
.bearer_auth(access_token.as_ref());
Self { request_builder }
}
pub async fn send(self) -> Result<Vec<Account>> {
handle_response(self.request_builder)
.await
.map(|accounts: Accounts| accounts.accounts)
}
}