io_gmail/v1/rest/labels/
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::labels::GmailLabel,
16 send::{GMAIL_API_BASE, GmailSend, GmailSendError, GmailSendOutput},
17 },
18};
19
20pub struct GmailLabelGet {
22 send: GmailSend<GmailLabel>,
23}
24
25impl GmailLabelGet {
26 pub fn new(auth: &HttpAuthBearer, user_id: &str, id: &str) -> Result<Self, GmailSendError> {
28 debug!("prepare gmail label retrieval");
29 trace!("id: {id:?}");
30
31 let url = Url::parse(GMAIL_API_BASE)?.join(&format!("users/{user_id}/labels/{id}"))?;
32 let send = GmailSend::get(auth, url);
33
34 Ok(Self { send })
35 }
36}
37
38impl GmailCoroutine for GmailLabelGet {
39 type Yield = GmailYield;
40 type Return = Result<GmailSendOutput<GmailLabel>, GmailSendError>;
41
42 fn resume(&mut self, arg: Option<&[u8]>) -> GmailCoroutineState<Self::Yield, Self::Return> {
43 let out = gmail_try!(&mut self.send, arg);
44 debug!("label retrieved");
45 trace!("out: {out:?}");
46 GmailCoroutineState::Complete(Ok(out))
47 }
48}