io_msgraph/v1/rest/users/contacts/
delta.rs1use alloc::{format, string::String};
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 page::{MsgraphPage, link_url},
24 rest::users::contacts::MsgraphContact,
25 send::{
26 MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, path_segment,
27 user_path,
28 },
29 },
30};
31
32pub type MsgraphContactsDeltaResponse = MsgraphPage<MsgraphContactDelta>;
37
38#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
41pub struct MsgraphContactDelta {
42 #[serde(flatten)]
44 pub contact: MsgraphContact,
45 #[serde(default, rename = "@removed", skip_serializing_if = "Option::is_none")]
47 pub removed: Option<MsgraphRemoved>,
48}
49
50#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
54pub struct MsgraphRemoved {
55 #[serde(default)]
58 pub reason: String,
59}
60
61pub struct MsgraphContactsDelta {
65 send: MsgraphSend<MsgraphContactsDeltaResponse>,
66}
67
68impl MsgraphContactsDelta {
69 pub fn new(
75 auth: &HttpAuthBearer,
76 user_id: &str,
77 folder: Option<&str>,
78 select: Option<&str>,
79 ) -> Result<Self, MsgraphSendError> {
80 debug!("prepare microsoft graph contacts delta");
81 trace!("folder: {folder:?}");
82
83 let user = user_path(user_id)?;
84 let path = match folder {
85 Some(folder) => format!(
86 "{user}/contactFolders/{}/contacts/delta",
87 path_segment(folder)?
88 ),
89 None => format!("{user}/contacts/delta"),
90 };
91 let mut url = Url::parse(MSGRAPH_API_BASE)?.join(&path)?;
92 if let Some(select) = select {
93 url.query_pairs_mut().append_pair("$select", select);
94 }
95
96 let send = MsgraphSend::get(auth, url);
97
98 Ok(Self { send })
99 }
100
101 pub fn from_link(auth: &HttpAuthBearer, link: &str) -> Result<Self, MsgraphSendError> {
108 debug!("prepare microsoft graph contacts delta from link");
109 trace!("link: {link:?}");
110
111 let url = link_url(link)?;
112 let send = MsgraphSend::get(auth, url);
113
114 Ok(Self { send })
115 }
116
117 pub fn max_page_size(mut self, size: u32) -> Self {
123 self.send = self.send.max_page_size(size);
124 self
125 }
126}
127
128impl MsgraphCoroutine for MsgraphContactsDelta {
129 type Yield = MsgraphYield;
130 type Return = Result<MsgraphSendOutput<MsgraphContactsDeltaResponse>, MsgraphSendError>;
131
132 fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
133 let out = msgraph_try!(&mut self.send, arg);
134 debug!("contacts delta page received");
135 trace!("out: {out:?}");
136 MsgraphCoroutineState::Complete(Ok(out))
137 }
138}