Skip to main content

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

1//! List the child folders of a Microsoft Graph contact folder
2//! (`GET /me/contactFolders/{id}/childFolders`).
3//!
4//! <https://learn.microsoft.com/en-us/graph/api/contactfolder-list-childfolders>
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        query::to_query_pairs,
17        rest::users::contact_folders::list::{
18            MsgraphContactFoldersListParams, MsgraphContactFoldersListResponse,
19        },
20        send::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
21    },
22};
23
24/// Lists the child folders of a Microsoft Graph contact folder.
25pub struct MsgraphContactChildFoldersList {
26    send: MsgraphSend<MsgraphContactFoldersListResponse>,
27}
28
29impl MsgraphContactChildFoldersList {
30    /// Lists the child folders of the contact folder `id`, filtered by
31    /// the OData `params`.
32    pub fn new(
33        auth: &HttpAuthBearer,
34        user_id: &str,
35        id: &str,
36        params: &MsgraphContactFoldersListParams,
37    ) -> Result<Self, MsgraphSendError> {
38        debug!("prepare microsoft graph contact child folders listing");
39        trace!("id: {id:?}");
40        trace!("params: {params:?}");
41
42        let user = user_path(user_id);
43        let mut url = Url::parse(MSGRAPH_API_BASE)?
44            .join(&format!("{user}/contactFolders/{id}/childFolders"))?;
45        url.query_pairs_mut().extend_pairs(to_query_pairs(params));
46
47        let send = MsgraphSend::get(auth, url);
48
49        Ok(Self { send })
50    }
51}
52
53impl MsgraphCoroutine for MsgraphContactChildFoldersList {
54    type Yield = MsgraphYield;
55    type Return = Result<MsgraphSendOutput<MsgraphContactFoldersListResponse>, MsgraphSendError>;
56
57    fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
58        let out = msgraph_try!(&mut self.send, arg);
59        debug!("contact child folders listed");
60        trace!("out: {out:?}");
61        MsgraphCoroutineState::Complete(Ok(out))
62    }
63}