Skip to main content

io_msgraph/v1/rest/users/calendars/
delete.rs

1//! Delete a Microsoft Graph calendar (`DELETE /me/calendars/{id}`).
2//!
3//! <https://learn.microsoft.com/en-us/graph/api/calendar-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    msgraph_try,
14    v1::send::{
15        MSGRAPH_API_BASE, MsgraphNoResponse, MsgraphSend, MsgraphSendError, MsgraphSendOutput,
16        path_segment, user_path,
17    },
18};
19
20/// Deletes a Microsoft Graph calendar.
21pub struct MsgraphCalendarDelete {
22    send: MsgraphSend<MsgraphNoResponse>,
23}
24
25impl MsgraphCalendarDelete {
26    /// Deletes the calendar `id`.
27    pub fn new(auth: &HttpAuthBearer, user_id: &str, id: &str) -> Result<Self, MsgraphSendError> {
28        debug!("prepare microsoft graph calendar deletion");
29        trace!("id: {id:?}");
30
31        let user = user_path(user_id)?;
32        let url = Url::parse(MSGRAPH_API_BASE)?
33            .join(&format!("{user}/calendars/{}", path_segment(id)?))?;
34        let send = MsgraphSend::delete(auth, url);
35
36        Ok(Self { send })
37    }
38}
39
40impl MsgraphCoroutine for MsgraphCalendarDelete {
41    type Yield = MsgraphYield;
42    type Return = Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphSendError>;
43
44    fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
45        let out = msgraph_try!(&mut self.send, arg);
46        debug!("calendar deleted");
47        trace!("out: {out:?}");
48        MsgraphCoroutineState::Complete(Ok(out))
49    }
50}