io_msgraph/v1/rest/users/contacts/
delta.rs1use alloc::{format, string::String, vec::Vec};
13
14use io_http::rfc6750::bearer::HttpAuthBearer;
15use log::{debug, trace};
16use serde::{Deserialize, Serialize};
17use url::Url;
18
19use crate::{
20 coroutine::*,
21 msgraph_try,
22 v1::{
23 rest::users::contacts::MsgraphContact,
24 send::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
25 },
26};
27
28#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
33pub struct MsgraphContactsDeltaResponse {
34 #[serde(default)]
36 pub value: Vec<MsgraphContactDelta>,
37 #[serde(default, rename = "@odata.nextLink")]
39 pub next_link: Option<String>,
40 #[serde(default, rename = "@odata.deltaLink")]
42 pub delta_link: Option<String>,
43}
44
45#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
48pub struct MsgraphContactDelta {
49 #[serde(flatten)]
51 pub contact: MsgraphContact,
52 #[serde(default, rename = "@removed", skip_serializing_if = "Option::is_none")]
54 pub removed: Option<MsgraphRemoved>,
55}
56
57#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
61pub struct MsgraphRemoved {
62 #[serde(default)]
65 pub reason: String,
66}
67
68pub struct MsgraphContactsDelta {
71 send: MsgraphSend<MsgraphContactsDeltaResponse>,
72}
73
74impl MsgraphContactsDelta {
75 pub fn new(
81 auth: &HttpAuthBearer,
82 user_id: &str,
83 folder: Option<&str>,
84 select: Option<&str>,
85 ) -> Result<Self, MsgraphSendError> {
86 debug!("prepare microsoft graph contacts delta");
87 trace!("folder: {folder:?}");
88
89 let user = user_path(user_id);
90 let path = match folder {
91 Some(folder) => format!("{user}/contactFolders/{folder}/contacts/delta"),
92 None => format!("{user}/contacts/delta"),
93 };
94 let mut url = Url::parse(MSGRAPH_API_BASE)?.join(&path)?;
95 if let Some(select) = select {
96 url.query_pairs_mut().append_pair("$select", select);
97 }
98
99 let send = MsgraphSend::get(auth, url);
100
101 Ok(Self { send })
102 }
103}
104
105impl MsgraphCoroutine for MsgraphContactsDelta {
106 type Yield = MsgraphYield;
107 type Return = Result<MsgraphSendOutput<MsgraphContactsDeltaResponse>, MsgraphSendError>;
108
109 fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
110 let out = msgraph_try!(&mut self.send, arg);
111 debug!("contacts delta page received");
112 trace!("out: {out:?}");
113 MsgraphCoroutineState::Complete(Ok(out))
114 }
115}