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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
use crate::client::NoBody;
use crate::{Client, Error, Page, types::*, util::urlish};
impl Client {
/// GET /v0/inboxes/{inbox_id}/threads (first page; see
/// [`Client::list_threads_page`]).
pub async fn list_threads(&self, inbox_id: &str) -> Result<ThreadList, Error> {
self.list_threads_page(inbox_id, Page::default()).await
}
/// GET /v0/inboxes/{inbox_id}/threads with pagination. Feed
/// [`ThreadList::next_page_token`] back in as [`Page::page_token`] until it
/// comes back `None`.
pub async fn list_threads_page(&self, inbox_id: &str, page: Page) -> Result<ThreadList, Error> {
self.request(
reqwest::Method::GET,
&format!("/v0/inboxes/{}/threads", urlish(inbox_id)),
&page.query(),
None::<&NoBody>,
)
.await
}
/// GET /v0/inboxes/{inbox_id}/threads with filters and pagination. Pass
/// [`ThreadListFilters`] with any fields set to narrow results.
pub async fn list_threads_filtered(
&self,
inbox_id: &str,
filters: ThreadListFilters,
) -> Result<ThreadList, Error> {
self.request(
reqwest::Method::GET,
&format!("/v0/inboxes/{}/threads", urlish(inbox_id)),
&filters.query(),
None::<&NoBody>,
)
.await
}
/// GET /v0/inboxes/{inbox_id}/threads/search, full-text search over the
/// inbox's threads. The matched fragments come back in
/// [`Thread::highlights`].
pub async fn search_threads(&self, inbox_id: &str, query: &str) -> Result<ThreadList, Error> {
self.search_threads_page(inbox_id, query, ThreadListFilters::default())
.await
}
/// GET /v0/inboxes/{inbox_id}/threads/search with filters and pagination.
pub async fn search_threads_page(
&self,
inbox_id: &str,
query: &str,
filters: ThreadListFilters,
) -> Result<ThreadList, Error> {
let mut q = filters.query();
q.push(("q", query.to_string()));
self.request(
reqwest::Method::GET,
&format!("/v0/inboxes/{}/threads/search", urlish(inbox_id)),
&q,
None::<&NoBody>,
)
.await
}
/// GET /v0/inboxes/{inbox_id}/threads/{thread_id}, the full thread with its
/// messages.
pub async fn get_thread(&self, inbox_id: &str, thread_id: &str) -> Result<Thread, Error> {
self.request(
reqwest::Method::GET,
&format!(
"/v0/inboxes/{}/threads/{}",
urlish(inbox_id),
urlish(thread_id),
),
&[],
None::<&NoBody>,
)
.await
}
/// PATCH /v0/inboxes/{inbox_id}/threads/{thread_id}, add and/or remove
/// labels across the thread. Returns the thread id and its labels after the
/// change.
pub async fn update_thread(
&self,
inbox_id: &str,
thread_id: &str,
update: UpdateThread,
) -> Result<UpdatedThread, Error> {
self.request(
reqwest::Method::PATCH,
&format!(
"/v0/inboxes/{}/threads/{}",
urlish(inbox_id),
urlish(thread_id),
),
&[],
Some(&update),
)
.await
}
/// DELETE /v0/inboxes/{inbox_id}/threads/{thread_id}.
pub async fn delete_thread(&self, inbox_id: &str, thread_id: &str) -> Result<(), Error> {
self.request(
reqwest::Method::DELETE,
&format!(
"/v0/inboxes/{}/threads/{}",
urlish(inbox_id),
urlish(thread_id),
),
&[],
None::<&NoBody>,
)
.await
}
}