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 {
72 send: MsgraphSend<MsgraphContactsDeltaResponse>,
73}
74
75impl MsgraphContactsDelta {
76 pub fn new(
82 auth: &HttpAuthBearer,
83 user_id: &str,
84 folder: Option<&str>,
85 select: Option<&str>,
86 ) -> Result<Self, MsgraphSendError> {
87 debug!("prepare microsoft graph contacts delta");
88 trace!("folder: {folder:?}");
89
90 let user = user_path(user_id);
91 let path = match folder {
92 Some(folder) => format!("{user}/contactFolders/{folder}/contacts/delta"),
93 None => format!("{user}/contacts/delta"),
94 };
95 let mut url = Url::parse(MSGRAPH_API_BASE)?.join(&path)?;
96 if let Some(select) = select {
97 url.query_pairs_mut().append_pair("$select", select);
98 }
99
100 let send = MsgraphSend::get(auth, url);
101
102 Ok(Self { send })
103 }
104
105 pub fn from_link(auth: &HttpAuthBearer, link: &str) -> Result<Self, MsgraphSendError> {
111 debug!("prepare microsoft graph contacts delta from link");
112 trace!("link: {link:?}");
113
114 let url = Url::parse(link)?;
115 let send = MsgraphSend::get(auth, url);
116
117 Ok(Self { send })
118 }
119
120 pub fn max_page_size(mut self, size: u32) -> Self {
126 self.send = self.send.max_page_size(size);
127 self
128 }
129}
130
131impl MsgraphCoroutine for MsgraphContactsDelta {
132 type Yield = MsgraphYield;
133 type Return = Result<MsgraphSendOutput<MsgraphContactsDeltaResponse>, MsgraphSendError>;
134
135 fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
136 let out = msgraph_try!(&mut self.send, arg);
137 debug!("contacts delta page received");
138 trace!("out: {out:?}");
139 MsgraphCoroutineState::Complete(Ok(out))
140 }
141}