io_gmail/v1/rest/settings/send_as/
get.rs1use alloc::format;
6
7use io_http::rfc6750::bearer::HttpAuthBearer;
8use log::{debug, trace};
9use url::Url;
10
11use crate::{
12 coroutine::*,
13 gmail_try,
14 v1::{
15 rest::settings::send_as::GmailSendAs,
16 send::{GMAIL_API_BASE, GmailSend, GmailSendError, GmailSendOutput},
17 },
18};
19
20pub struct GmailSendAsGet {
23 send: GmailSend<GmailSendAs>,
24}
25
26impl GmailSendAsGet {
27 pub fn new(
29 auth: &HttpAuthBearer,
30 user_id: &str,
31 send_as_email: &str,
32 ) -> Result<Self, GmailSendError> {
33 debug!("prepare gmail send-as alias retrieval");
34 trace!("send_as_email: {send_as_email:?}");
35
36 let url = Url::parse(GMAIL_API_BASE)?
37 .join(&format!("users/{user_id}/settings/sendAs/{send_as_email}"))?;
38 let send = GmailSend::get(auth, url);
39
40 Ok(Self { send })
41 }
42}
43
44impl GmailCoroutine for GmailSendAsGet {
45 type Yield = GmailYield;
46 type Return = Result<GmailSendOutput<GmailSendAs>, GmailSendError>;
47
48 fn resume(&mut self, arg: Option<&[u8]>) -> GmailCoroutineState<Self::Yield, Self::Return> {
49 let out = gmail_try!(&mut self.send, arg);
50 debug!("send-as alias retrieved");
51 trace!("out: {out:?}");
52 GmailCoroutineState::Complete(Ok(out))
53 }
54}