Skip to main content

io_gmail/v1/rest/threads/
delete.rs

1//! Delete a Gmail thread (`users.threads.delete`).
2//!
3//! <https://developers.google.com/gmail/api/reference/rest/v1/users.threads/delete>
4
5use 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::send::{GMAIL_API_BASE, GmailNoResponse, GmailSend, GmailSendError, GmailSendOutput},
15};
16
17/// Gmail REST thread permanent deletion, yielding no response body.
18pub struct GmailThreadDelete {
19    send: GmailSend<GmailNoResponse>,
20}
21
22impl GmailThreadDelete {
23    /// Builds the `users.threads.delete` request for the given thread id.
24    pub fn new(auth: &HttpAuthBearer, user_id: &str, id: &str) -> Result<Self, GmailSendError> {
25        debug!("prepare gmail thread deletion");
26        trace!("id: {id:?}");
27
28        let url = Url::parse(GMAIL_API_BASE)?.join(&format!("users/{user_id}/threads/{id}"))?;
29        let send = GmailSend::delete(auth, url);
30
31        Ok(Self { send })
32    }
33}
34
35impl GmailCoroutine for GmailThreadDelete {
36    type Yield = GmailYield;
37    type Return = Result<GmailSendOutput<GmailNoResponse>, GmailSendError>;
38
39    fn resume(&mut self, arg: Option<&[u8]>) -> GmailCoroutineState<Self::Yield, Self::Return> {
40        let out = gmail_try!(&mut self.send, arg);
41        debug!("thread deleted");
42        trace!("out: {out:?}");
43        GmailCoroutineState::Complete(Ok(out))
44    }
45}