Skip to main content

io_gmail/v1/rest/settings/
get_auto_forwarding.rs

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