io_gmail/v1/rest/users/
get_profile.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::users::GmailProfile,
16 send::{GMAIL_API_BASE, GmailSend, GmailSendError, GmailSendOutput},
17 },
18};
19
20pub struct GmailProfileGet {
22 send: GmailSend<GmailProfile>,
23}
24
25impl GmailProfileGet {
26 pub fn new(auth: &HttpAuthBearer, user_id: &str) -> Result<Self, GmailSendError> {
29 debug!("prepare gmail profile retrieval");
30 trace!("user_id: {user_id:?}");
31
32 let url = Url::parse(GMAIL_API_BASE)?.join(&format!("users/{user_id}/profile"))?;
33 let send = GmailSend::get(auth, url);
34
35 Ok(Self { send })
36 }
37}
38
39impl GmailCoroutine for GmailProfileGet {
40 type Yield = GmailYield;
41 type Return = Result<GmailSendOutput<GmailProfile>, 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!("profile retrieved");
46 trace!("out: {out:?}");
47 GmailCoroutineState::Complete(Ok(out))
48 }
49}