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