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