io_msgraph/v1/rest/users/contacts/
update.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 MsgraphContactUpdate {
25 send: MsgraphSend<MsgraphContact>,
26}
27
28impl MsgraphContactUpdate {
29 pub fn new(
32 auth: &HttpAuthBearer,
33 user_id: &str,
34 id: &str,
35 contact: &MsgraphContact,
36 ) -> Result<Self, MsgraphSendError> {
37 debug!("prepare microsoft graph contact update");
38 trace!("id: {id:?}");
39 trace!("contact: {contact:?}");
40
41 let user = user_path(user_id)?;
42 let url = Url::parse(MSGRAPH_API_BASE)?
43 .join(&format!("{user}/contacts/{}", path_segment(id)?))?;
44 let send = MsgraphSend::patch_json(auth, url, contact)?;
45
46 Ok(Self { send })
47 }
48}
49
50impl MsgraphCoroutine for MsgraphContactUpdate {
51 type Yield = MsgraphYield;
52 type Return = Result<MsgraphSendOutput<MsgraphContact>, MsgraphSendError>;
53
54 fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
55 let out = msgraph_try!(&mut self.send, arg);
56 debug!("contact updated");
57 trace!("out: {out:?}");
58 MsgraphCoroutineState::Complete(Ok(out))
59 }
60}