Skip to main content

io_gmail/v1/rest/settings/
get_pop.rs

1//! Get the Gmail POP settings (`users.settings.getPop`).
2//!
3//! <https://developers.google.com/gmail/api/reference/rest/v1/users.settings/getPop>
4
5use 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
20/// I/O-free coroutine getting the Gmail POP access settings
21/// (`users.settings.getPop`).
22pub struct GmailPopGet {
23    send: GmailSend<GmailPopSettings>,
24}
25
26impl GmailPopGet {
27    /// Builds the `users.settings.getPop` request for the given user.
28    pub fn new(auth: &HttpAuthBearer, user_id: &str) -> Result<Self, GmailSendError> {
29        debug!("prepare gmail pop settings retrieval");
30        trace!("user_id: {user_id:?}");
31
32        let url = Url::parse(GMAIL_API_BASE)?.join(&format!("users/{user_id}/settings/pop"))?;
33        let send = GmailSend::get(auth, url);
34
35        Ok(Self { send })
36    }
37}
38
39impl GmailCoroutine for GmailPopGet {
40    type Yield = GmailYield;
41    type Return = Result<GmailSendOutput<GmailPopSettings>, GmailSendError>;
42
43    fn resume(&mut self, arg: Option<&[u8]>) -> GmailCoroutineState<Self::Yield, Self::Return> {
44        let out = gmail_try!(&mut self.send, arg);
45        debug!("pop settings retrieved");
46        trace!("out: {out:?}");
47        GmailCoroutineState::Complete(Ok(out))
48    }
49}