io_gmail/v1/rest/settings/send_as/
patch.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 GmailSendAsPatch {
23 send: GmailSend<GmailSendAs>,
24}
25
26impl GmailSendAsPatch {
27 pub fn new(
29 auth: &HttpAuthBearer,
30 user_id: &str,
31 send_as_email: &str,
32 send_as: &GmailSendAs,
33 ) -> Result<Self, GmailSendError> {
34 debug!("prepare gmail send-as alias patch");
35 trace!("send_as: {send_as:?}");
36
37 let url = Url::parse(GMAIL_API_BASE)?
38 .join(&format!("users/{user_id}/settings/sendAs/{send_as_email}"))?;
39 let send = GmailSend::patch_json(auth, url, send_as)?;
40
41 Ok(Self { send })
42 }
43}
44
45impl GmailCoroutine for GmailSendAsPatch {
46 type Yield = GmailYield;
47 type Return = Result<GmailSendOutput<GmailSendAs>, GmailSendError>;
48
49 fn resume(&mut self, arg: Option<&[u8]>) -> GmailCoroutineState<Self::Yield, Self::Return> {
50 let out = gmail_try!(&mut self.send, arg);
51 debug!("send-as alias patched");
52 trace!("out: {out:?}");
53 GmailCoroutineState::Complete(Ok(out))
54 }
55}