io_gmail/v1/rest/settings/send_as/
list.rs1use alloc::{format, 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 rest::settings::send_as::GmailSendAs,
17 send::{GMAIL_API_BASE, GmailSend, GmailSendError, GmailSendOutput},
18 },
19};
20
21#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
23#[serde(rename_all = "camelCase")]
24pub struct GmailSendAsListResponse {
25 #[serde(default)]
27 pub send_as: Vec<GmailSendAs>,
28}
29
30pub struct GmailSendAsList {
33 send: GmailSend<GmailSendAsListResponse>,
34}
35
36impl GmailSendAsList {
37 pub fn new(auth: &HttpAuthBearer, user_id: &str) -> Result<Self, GmailSendError> {
39 debug!("prepare gmail send-as aliases listing");
40 trace!("user_id: {user_id:?}");
41
42 let url = Url::parse(GMAIL_API_BASE)?.join(&format!("users/{user_id}/settings/sendAs"))?;
43 let send = GmailSend::get(auth, url);
44
45 Ok(Self { send })
46 }
47}
48
49impl GmailCoroutine for GmailSendAsList {
50 type Yield = GmailYield;
51 type Return = Result<GmailSendOutput<GmailSendAsListResponse>, GmailSendError>;
52
53 fn resume(&mut self, arg: Option<&[u8]>) -> GmailCoroutineState<Self::Yield, Self::Return> {
54 let out = gmail_try!(&mut self.send, arg);
55 debug!("send-as aliases listed");
56 trace!("out: {out:?}");
57 GmailCoroutineState::Complete(Ok(out))
58 }
59}