io_msgraph/v1/rest/users/events/
delta.rs1use alloc::{format, string::String, vec::Vec};
11
12use io_http::rfc6750::bearer::HttpAuthBearer;
13use log::{debug, trace};
14use serde::{Deserialize, Serialize};
15use url::Url;
16
17use crate::{
18 coroutine::*,
19 msgraph_try,
20 v1::{
21 rest::users::{contacts::delta::MsgraphRemoved, events::MsgraphEvent},
22 send::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
23 },
24};
25
26#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
31pub struct MsgraphEventsDeltaResponse {
32 #[serde(default)]
34 pub value: Vec<MsgraphEventDelta>,
35 #[serde(default, rename = "@odata.nextLink")]
37 pub next_link: Option<String>,
38 #[serde(default, rename = "@odata.deltaLink")]
40 pub delta_link: Option<String>,
41}
42
43#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
46pub struct MsgraphEventDelta {
47 #[serde(flatten)]
49 pub event: MsgraphEvent,
50 #[serde(default, rename = "@removed", skip_serializing_if = "Option::is_none")]
52 pub removed: Option<MsgraphRemoved>,
53}
54
55pub struct MsgraphEventsDelta {
59 send: MsgraphSend<MsgraphEventsDeltaResponse>,
60}
61
62impl MsgraphEventsDelta {
63 pub fn new(
67 auth: &HttpAuthBearer,
68 user_id: &str,
69 calendar: Option<&str>,
70 start: &str,
71 end: &str,
72 ) -> Result<Self, MsgraphSendError> {
73 debug!("prepare microsoft graph calendar view delta");
74 trace!("calendar: {calendar:?}, start: {start}, end: {end}");
75
76 let user = user_path(user_id);
77 let path = match calendar {
78 Some(calendar) => format!("{user}/calendars/{calendar}/calendarView/delta"),
79 None => format!("{user}/calendarView/delta"),
80 };
81 let mut url = Url::parse(MSGRAPH_API_BASE)?.join(&path)?;
82 url.query_pairs_mut()
83 .append_pair("startDateTime", start)
84 .append_pair("endDateTime", end);
85
86 let send = MsgraphSend::get(auth, url);
87
88 Ok(Self { send })
89 }
90
91 pub fn from_link(auth: &HttpAuthBearer, link: &str) -> Result<Self, MsgraphSendError> {
94 debug!("prepare microsoft graph calendar view delta from link");
95 trace!("link: {link}");
96
97 let url = Url::parse(link)?;
98 let send = MsgraphSend::get(auth, url);
99
100 Ok(Self { send })
101 }
102}
103
104impl MsgraphCoroutine for MsgraphEventsDelta {
105 type Yield = MsgraphYield;
106 type Return = Result<MsgraphSendOutput<MsgraphEventsDeltaResponse>, MsgraphSendError>;
107
108 fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
109 let out = msgraph_try!(&mut self.send, arg);
110 debug!("calendar view delta received");
111 trace!("out: {out:?}");
112 MsgraphCoroutineState::Complete(Ok(out))
113 }
114}