io_msgraph/v1/rest/users/contacts/
get.rs1use alloc::format;
6
7use io_http::rfc6750::bearer::HttpAuthBearer;
8use log::{debug, trace};
9use url::Url;
10
11use crate::{
12 coroutine::*,
13 msgraph_try,
14 v1::{
15 rest::users::contacts::MsgraphContact,
16 send::{
17 MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, path_segment,
18 user_path,
19 },
20 },
21};
22
23pub struct MsgraphContactGet {
25 send: MsgraphSend<MsgraphContact>,
26}
27
28impl MsgraphContactGet {
29 pub fn new(
36 auth: &HttpAuthBearer,
37 user_id: &str,
38 id: &str,
39 expand: Option<&str>,
40 ) -> Result<Self, MsgraphSendError> {
41 debug!("prepare microsoft graph contact retrieval");
42 trace!("id: {id:?}");
43 trace!("expand: {expand:?}");
44
45 let user = user_path(user_id)?;
46 let mut url = Url::parse(MSGRAPH_API_BASE)?
47 .join(&format!("{user}/contacts/{}", path_segment(id)?))?;
48
49 if let Some(expand) = expand {
50 url.query_pairs_mut().append_pair("$expand", expand);
51 }
52
53 let send = MsgraphSend::get(auth, url);
54
55 Ok(Self { send })
56 }
57}
58
59impl MsgraphCoroutine for MsgraphContactGet {
60 type Yield = MsgraphYield;
61 type Return = Result<MsgraphSendOutput<MsgraphContact>, MsgraphSendError>;
62
63 fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
64 let out = msgraph_try!(&mut self.send, arg);
65 debug!("contact retrieved");
66 trace!("out: {out:?}");
67 MsgraphCoroutineState::Complete(Ok(out))
68 }
69}