io_msgraph/v1/rest/users/contacts/
list.rs1use alloc::{format, string::String, vec::Vec};
7
8use io_http::rfc6750::bearer::HttpAuthBearer;
9use log::{debug, trace};
10use serde::{Deserialize, Serialize};
11use url::Url;
12
13use crate::{
14 coroutine::*,
15 msgraph_try,
16 v1::{
17 query::to_query_pairs,
18 rest::users::contacts::MsgraphContact,
19 send::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
20 },
21};
22
23#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
25pub struct MsgraphContactsListResponse {
26 #[serde(default)]
28 pub value: Vec<MsgraphContact>,
29 #[serde(default, rename = "@odata.nextLink")]
31 pub next_link: Option<String>,
32}
33
34#[derive(Debug, Clone, Default, Serialize, Eq, PartialEq)]
36pub struct MsgraphContactsListParams<'a> {
37 #[serde(rename = "$top")]
39 pub top: Option<u32>,
40 #[serde(rename = "$skip")]
42 pub skip: Option<u32>,
43 #[serde(rename = "$select")]
45 pub select: Option<&'a str>,
46 #[serde(rename = "$filter")]
48 pub filter: Option<&'a str>,
49 #[serde(rename = "$orderby")]
51 pub orderby: Option<&'a str>,
52 #[serde(rename = "$expand")]
54 pub expand: Option<&'a str>,
55 #[serde(rename = "$count")]
57 pub count: Option<bool>,
58}
59
60pub struct MsgraphContactsList {
62 send: MsgraphSend<MsgraphContactsListResponse>,
63}
64
65impl MsgraphContactsList {
66 pub fn new(
69 auth: &HttpAuthBearer,
70 user_id: &str,
71 folder: Option<&str>,
72 params: &MsgraphContactsListParams,
73 ) -> Result<Self, MsgraphSendError> {
74 debug!("prepare microsoft graph contacts listing");
75 trace!("folder: {folder:?}");
76 trace!("params: {params:?}");
77
78 let user = user_path(user_id);
79 let path = match folder {
80 Some(folder) => format!("{user}/contactFolders/{folder}/contacts"),
81 None => format!("{user}/contacts"),
82 };
83 let mut url = Url::parse(MSGRAPH_API_BASE)?.join(&path)?;
84 url.query_pairs_mut().extend_pairs(to_query_pairs(params));
85
86 let send = MsgraphSend::get(auth, url);
87
88 Ok(Self { send })
89 }
90}
91
92impl MsgraphCoroutine for MsgraphContactsList {
93 type Yield = MsgraphYield;
94 type Return = Result<MsgraphSendOutput<MsgraphContactsListResponse>, MsgraphSendError>;
95
96 fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
97 let out = msgraph_try!(&mut self.send, arg);
98 debug!("contacts listed");
99 trace!("out: {out:?}");
100 MsgraphCoroutineState::Complete(Ok(out))
101 }
102}