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::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
17 },
18};
19
20pub struct MsgraphContactGet {
22 send: MsgraphSend<MsgraphContact>,
23}
24
25impl MsgraphContactGet {
26 pub fn new(
33 auth: &HttpAuthBearer,
34 user_id: &str,
35 id: &str,
36 expand: Option<&str>,
37 ) -> Result<Self, MsgraphSendError> {
38 debug!("prepare microsoft graph contact retrieval");
39 trace!("id: {id:?}");
40 trace!("expand: {expand:?}");
41
42 let user = user_path(user_id);
43 let mut url = Url::parse(MSGRAPH_API_BASE)?.join(&format!("{user}/contacts/{id}"))?;
44
45 if let Some(expand) = expand {
46 url.query_pairs_mut().append_pair("$expand", expand);
47 }
48
49 let send = MsgraphSend::get(auth, url);
50
51 Ok(Self { send })
52 }
53}
54
55impl MsgraphCoroutine for MsgraphContactGet {
56 type Yield = MsgraphYield;
57 type Return = Result<MsgraphSendOutput<MsgraphContact>, MsgraphSendError>;
58
59 fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
60 let out = msgraph_try!(&mut self.send, arg);
61 debug!("contact retrieved");
62 trace!("out: {out:?}");
63 MsgraphCoroutineState::Complete(Ok(out))
64 }
65}