io_gmail/v1/rest/users/
get_profile.rs1use alloc::{format, string::String};
6
7use io_http::rfc6750::bearer::HttpAuthBearer;
8use log::{debug, trace};
9use serde::{Deserialize, Serialize};
10use url::Url;
11
12use crate::{
13 coroutine::*,
14 gmail_try,
15 v1::send::{GMAIL_API_BASE, GmailSend, GmailSendError, GmailSendOutput},
16};
17
18#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
20#[serde(rename_all = "camelCase")]
21pub struct GmailProfile {
22 pub email_address: String,
24 #[serde(default)]
26 pub messages_total: Option<u64>,
27 #[serde(default)]
29 pub threads_total: Option<u64>,
30 #[serde(default)]
32 pub history_id: Option<String>,
33}
34
35pub struct GmailProfileGet {
37 send: GmailSend<GmailProfile>,
38}
39
40impl GmailProfileGet {
41 pub fn new(auth: &HttpAuthBearer, user_id: &str) -> Result<Self, GmailSendError> {
44 debug!("prepare gmail profile retrieval");
45 trace!("user_id: {user_id:?}");
46
47 let url = Url::parse(GMAIL_API_BASE)?.join(&format!("users/{user_id}/profile"))?;
48 let send = GmailSend::get(auth, url);
49
50 Ok(Self { send })
51 }
52}
53
54impl GmailCoroutine for GmailProfileGet {
55 type Yield = GmailYield;
56 type Return = Result<GmailSendOutput<GmailProfile>, GmailSendError>;
57
58 fn resume(&mut self, arg: Option<&[u8]>) -> GmailCoroutineState<Self::Yield, Self::Return> {
59 let out = gmail_try!(&mut self.send, arg);
60 debug!("profile retrieved");
61 trace!("out: {out:?}");
62 GmailCoroutineState::Complete(Ok(out))
63 }
64}