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