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