Skip to main content

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

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