agentmail/client/
accounts.rs1use crate::client::NoBody;
2use crate::client::scope::Scoped;
3use crate::{Client, Error, Page, types::*, util::urlish};
4
5impl Client {
6 pub async fn list_accounts(&self, filters: AccountsListFilters) -> Result<AccountList, Error> {
8 self.request(
9 reqwest::Method::GET,
10 "/v0/accounts",
11 &filters.query(),
12 None::<&NoBody>,
13 )
14 .await
15 }
16
17 pub async fn list_all_accounts(&self) -> Result<Vec<Account>, Error> {
19 let mut out = Vec::new();
20 let mut token = None;
21 loop {
22 let resp = self
23 .list_accounts(AccountsListFilters {
24 limit: None,
25 page_token: token,
26 ascending: None,
27 })
28 .await?;
29 let next = resp.next_page_token;
30 out.extend(resp.accounts);
31 match next {
32 Some(t) => token = Some(t),
33 None => return Ok(out),
34 }
35 }
36 }
37
38 pub async fn get_account(&self, account_id: &str) -> Result<Account, Error> {
40 self.request(
41 reqwest::Method::GET,
42 &format!("/v0/accounts/{}", urlish(account_id)),
43 &[],
44 None::<&NoBody>,
45 )
46 .await
47 }
48
49 pub async fn update_account(
51 &self,
52 account_id: &str,
53 update: UpdateAccount,
54 ) -> Result<Account, Error> {
55 self.request(
56 reqwest::Method::PATCH,
57 &format!("/v0/accounts/{}/update", urlish(account_id)),
58 &[],
59 Some(&update),
60 )
61 .await
62 }
63}
64
65impl<S: private::AccountScopes> Scoped<'_, S> {
68 pub async fn list_accounts(&self, page: Page) -> Result<AccountList, Error> {
70 self.client
71 .request(
72 reqwest::Method::GET,
73 &format!("{}/accounts", self.base()),
74 &page.query(),
75 None::<&NoBody>,
76 )
77 .await
78 }
79
80 pub async fn get_account(&self, account_id: &str) -> Result<Account, Error> {
82 self.client
83 .request(
84 reqwest::Method::GET,
85 &format!("{}/accounts/{}", self.base(), urlish(account_id)),
86 &[],
87 None::<&NoBody>,
88 )
89 .await
90 }
91}
92
93mod private {
94 use crate::client::scope::{InboxScope, PodScope, Scope};
95
96 pub trait AccountScopes: Scope {}
97 impl AccountScopes for InboxScope<'_> {}
98 impl AccountScopes for PodScope<'_> {}
99}