io_gmail/v1/rest/history/
list.rs1use alloc::{format, string::String, vec::Vec};
6
7use io_http::rfc6750::bearer::HttpAuthBearer;
8use log::{debug, trace};
9use serde::{Deserialize, Serialize};
10use url::Url;
11
12use crate::{
13 coroutine::*,
14 gmail_try,
15 v1::{
16 query::to_query_pairs,
17 rest::history::{GmailHistory, GmailHistoryType},
18 send::{GMAIL_API_BASE, GmailSend, GmailSendError, GmailSendOutput},
19 },
20};
21
22#[derive(Debug, Clone, Default, Serialize, Eq, PartialEq)]
24#[serde(rename_all = "camelCase")]
25pub struct GmailHistoryListParams<'a> {
26 pub start_history_id: &'a str,
28 pub label_id: Option<&'a str>,
30 pub history_types: &'a [GmailHistoryType],
32 pub max_results: Option<u32>,
34 pub page_token: Option<&'a str>,
36}
37
38#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
40#[serde(rename_all = "camelCase")]
41pub struct GmailHistoryListResponse {
42 #[serde(default)]
44 pub history: Vec<GmailHistory>,
45 #[serde(default)]
47 pub next_page_token: Option<String>,
48 #[serde(default)]
50 pub history_id: Option<String>,
51}
52
53pub struct GmailHistoryList {
55 send: GmailSend<GmailHistoryListResponse>,
56}
57
58impl GmailHistoryList {
59 pub fn new(
62 auth: &HttpAuthBearer,
63 user_id: &str,
64 params: &GmailHistoryListParams,
65 ) -> Result<Self, GmailSendError> {
66 debug!("prepare gmail history listing");
67 trace!("params: {params:?}");
68
69 let mut url = Url::parse(GMAIL_API_BASE)?.join(&format!("users/{user_id}/history"))?;
70 url.query_pairs_mut().extend_pairs(to_query_pairs(params));
71
72 let send = GmailSend::get(auth, url);
73
74 Ok(Self { send })
75 }
76}
77
78impl GmailCoroutine for GmailHistoryList {
79 type Yield = GmailYield;
80 type Return = Result<GmailSendOutput<GmailHistoryListResponse>, GmailSendError>;
81
82 fn resume(&mut self, arg: Option<&[u8]>) -> GmailCoroutineState<Self::Yield, Self::Return> {
83 let out = gmail_try!(&mut self.send, arg);
84 debug!("history listed");
85 trace!("out: {out:?}");
86 GmailCoroutineState::Complete(Ok(out))
87 }
88}