Skip to main content

agentmail/client/
lists.rs

1use crate::client::NoBody;
2use crate::{Client, Error, Page, types::*, util::urlish};
3
4impl Client {
5    /// GET /v0/lists/{direction}/{kind} (first page; see
6    /// [`Client::list_list_entries_page`]).
7    pub async fn list_list_entries(
8        &self,
9        direction: ListDirection,
10        kind: ListKind,
11    ) -> Result<ListEntries, Error> {
12        self.list_list_entries_page(direction, kind, Page::default())
13            .await
14    }
15
16    /// GET /v0/lists/{direction}/{kind} with pagination. Feed
17    /// [`ListEntries::next_page_token`] back in as [`Page::page_token`] until it
18    /// comes back `None`.
19    pub async fn list_list_entries_page(
20        &self,
21        direction: ListDirection,
22        kind: ListKind,
23        page: Page,
24    ) -> Result<ListEntries, Error> {
25        self.request(
26            reqwest::Method::GET,
27            &format!("/v0/lists/{}/{}", direction.as_path(), kind.as_path()),
28            &page.query(),
29            None::<&NoBody>,
30        )
31        .await
32    }
33
34    /// POST /v0/lists/{direction}/{kind}, add an address or domain to the list.
35    pub async fn create_list_entry(
36        &self,
37        direction: ListDirection,
38        kind: ListKind,
39        entry: CreateListEntry,
40    ) -> Result<ListEntry, Error> {
41        self.request(
42            reqwest::Method::POST,
43            &format!("/v0/lists/{}/{}", direction.as_path(), kind.as_path()),
44            &[],
45            Some(&entry),
46        )
47        .await
48    }
49
50    /// GET /v0/lists/{direction}/{kind}/{entry}
51    pub async fn get_list_entry(
52        &self,
53        direction: ListDirection,
54        kind: ListKind,
55        entry: &str,
56    ) -> Result<ListEntry, Error> {
57        self.request(
58            reqwest::Method::GET,
59            &format!(
60                "/v0/lists/{}/{}/{}",
61                direction.as_path(),
62                kind.as_path(),
63                urlish(entry),
64            ),
65            &[],
66            None::<&NoBody>,
67        )
68        .await
69    }
70
71    /// DELETE /v0/lists/{direction}/{kind}/{entry}
72    pub async fn delete_list_entry(
73        &self,
74        direction: ListDirection,
75        kind: ListKind,
76        entry: &str,
77    ) -> Result<(), Error> {
78        self.request(
79            reqwest::Method::DELETE,
80            &format!(
81                "/v0/lists/{}/{}/{}",
82                direction.as_path(),
83                kind.as_path(),
84                urlish(entry),
85            ),
86            &[],
87            None::<&NoBody>,
88        )
89        .await
90    }
91}