io_gmail/v1/rest/settings/
update_imap.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::GmailImapSettings,
16 send::{GMAIL_API_BASE, GmailSend, GmailSendError, GmailSendOutput},
17 },
18};
19
20pub struct GmailImapUpdate {
23 send: GmailSend<GmailImapSettings>,
24}
25
26impl GmailImapUpdate {
27 pub fn new(
30 auth: &HttpAuthBearer,
31 user_id: &str,
32 settings: GmailImapSettings,
33 ) -> Result<Self, GmailSendError> {
34 debug!("prepare gmail imap settings update");
35 trace!("settings: {settings:?}");
36
37 let url = Url::parse(GMAIL_API_BASE)?.join(&format!("users/{user_id}/settings/imap"))?;
38 let send = GmailSend::put_json(auth, url, &settings)?;
39
40 Ok(Self { send })
41 }
42}
43
44impl GmailCoroutine for GmailImapUpdate {
45 type Yield = GmailYield;
46 type Return = Result<GmailSendOutput<GmailImapSettings>, 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!("imap settings updated");
51 trace!("out: {out:?}");
52 GmailCoroutineState::Complete(Ok(out))
53 }
54}