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