seamapi_rs/
connect_accounts.rs1use anyhow::{bail, Context, Result};
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4
5pub struct ConnectedAccounts(pub String, pub String);
6
7#[derive(Deserialize, Serialize, Debug)]
8pub struct ConnectedAccount {
9 connected_accunt_id: String,
10 created_at: String,
11 user_identifier: UserIdentifier,
12 account_type: String,
13 errors: Vec<Value>,
14}
15
16#[derive(Serialize, Deserialize, Debug)]
17pub struct UserIdentifier {
18 pub email: String,
19}
20
21impl ConnectedAccounts {
22 pub fn list(self) -> Result<Vec<ConnectedAccount>> {
23 let url = format!("{}/connected_accounts/list", self.1);
24 let header = format!("Bearer {}", self.0);
25
26 let req = reqwest::blocking::Client::new()
27 .get(url)
28 .header("Authorization", header)
29 .send()
30 .context("Failed to send get request")?;
31
32 if req.status() != reqwest::StatusCode::OK {
33 bail!("{}", req.text().context("Really bad API error")?);
34 }
35
36 let json: crate::Response = req.json().context("Failed to deserialize JSON")?;
37 Ok(json.connected_accounts.unwrap())
38 }
39
40 pub fn get(self, connected_account_id: String) -> Result<ConnectedAccount> {
41 let url = format!(
42 "{}/connected_accounts/get?connected_account_id={}",
43 self.1, connected_account_id
44 );
45 let header = format!("Bearer {}", self.0);
46
47 let req = reqwest::blocking::Client::new()
48 .get(url)
49 .header("Authorization", header)
50 .send()
51 .context("Failed to send get request")?;
52
53 if req.status() != reqwest::StatusCode::OK {
54 bail!("{}", req.text().context("Really bad API error")?);
55 }
56
57 let json: crate::Response = req.json().context("Failed to deserialize JSON")?;
58 Ok(json.connected_account.unwrap())
59 }
60}