Skip to main content

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

1//! Get a Microsoft Graph contact folder
2//! (`GET /me/contactFolders/{id}`).
3//!
4//! <https://learn.microsoft.com/en-us/graph/api/contactfolder-get>
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::{
16        rest::users::contact_folders::MsgraphContactFolder,
17        send::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
18    },
19};
20
21/// Gets a Microsoft Graph contact folder.
22pub struct MsgraphContactFolderGet {
23    send: MsgraphSend<MsgraphContactFolder>,
24}
25
26impl MsgraphContactFolderGet {
27    /// Gets 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 retrieval");
30        trace!("id: {id:?}");
31
32        let user = user_path(user_id);
33        let url = Url::parse(MSGRAPH_API_BASE)?.join(&format!("{user}/contactFolders/{id}"))?;
34        let send = MsgraphSend::get(auth, url);
35
36        Ok(Self { send })
37    }
38}
39
40impl MsgraphCoroutine for MsgraphContactFolderGet {
41    type Yield = MsgraphYield;
42    type Return = Result<MsgraphSendOutput<MsgraphContactFolder>, 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!("contact folder retrieved");
47        trace!("out: {out:?}");
48        MsgraphCoroutineState::Complete(Ok(out))
49    }
50}