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