io_msgraph/v1/rest/users/contact_folders/
list.rs1use alloc::format;
7
8use io_http::rfc6750::bearer::HttpAuthBearer;
9use log::{debug, trace};
10use serde::Serialize;
11use url::Url;
12
13use crate::{
14 coroutine::*,
15 msgraph_try,
16 v1::{
17 page::MsgraphPage,
18 query::to_query_pairs,
19 rest::users::contact_folders::MsgraphContactFolder,
20 send::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
21 },
22};
23
24pub type MsgraphContactFoldersListResponse = MsgraphPage<MsgraphContactFolder>;
26
27#[derive(Debug, Clone, Default, Serialize, Eq, PartialEq)]
29pub struct MsgraphContactFoldersListParams<'a> {
30 #[serde(rename = "$top")]
32 pub top: Option<u32>,
33 #[serde(rename = "$skip")]
35 pub skip: Option<u32>,
36 #[serde(rename = "$select")]
38 pub select: Option<&'a str>,
39}
40
41pub struct MsgraphContactFoldersList {
43 send: MsgraphSend<MsgraphContactFoldersListResponse>,
44}
45
46impl MsgraphContactFoldersList {
47 pub fn new(
50 auth: &HttpAuthBearer,
51 user_id: &str,
52 params: &MsgraphContactFoldersListParams,
53 ) -> Result<Self, MsgraphSendError> {
54 debug!("prepare microsoft graph contact folders listing");
55 trace!("params: {params:?}");
56
57 let user = user_path(user_id)?;
58 let mut url = Url::parse(MSGRAPH_API_BASE)?.join(&format!("{user}/contactFolders"))?;
59 url.query_pairs_mut().extend_pairs(to_query_pairs(params));
60
61 let send = MsgraphSend::get(auth, url);
62
63 Ok(Self { send })
64 }
65}
66
67impl MsgraphCoroutine for MsgraphContactFoldersList {
68 type Yield = MsgraphYield;
69 type Return = Result<MsgraphSendOutput<MsgraphContactFoldersListResponse>, MsgraphSendError>;
70
71 fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
72 let out = msgraph_try!(&mut self.send, arg);
73 debug!("contact folders listed");
74 trace!("out: {out:?}");
75 MsgraphCoroutineState::Complete(Ok(out))
76 }
77}