io_msgraph/v1/rest/users/events/
calendar_view.rs1use alloc::format;
10
11use io_http::rfc6750::bearer::HttpAuthBearer;
12use log::{debug, trace};
13use url::Url;
14
15use crate::{
16 coroutine::*,
17 msgraph_try,
18 v1::{
19 query::to_query_pairs,
20 rest::users::events::list::{MsgraphEventsListParams, MsgraphEventsListResponse},
21 send::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
22 },
23};
24
25pub struct MsgraphCalendarView {
27 send: MsgraphSend<MsgraphEventsListResponse>,
28}
29
30impl MsgraphCalendarView {
31 pub fn new(
34 auth: &HttpAuthBearer,
35 user_id: &str,
36 calendar: Option<&str>,
37 start: &str,
38 end: &str,
39 params: &MsgraphEventsListParams,
40 ) -> Result<Self, MsgraphSendError> {
41 debug!("prepare microsoft graph calendar view");
42 trace!("calendar: {calendar:?}, start: {start}, end: {end}");
43
44 let user = user_path(user_id);
45 let path = match calendar {
46 Some(calendar) => format!("{user}/calendars/{calendar}/calendarView"),
47 None => format!("{user}/calendarView"),
48 };
49 let mut url = Url::parse(MSGRAPH_API_BASE)?.join(&path)?;
50 url.query_pairs_mut()
51 .append_pair("startDateTime", start)
52 .append_pair("endDateTime", end)
53 .extend_pairs(to_query_pairs(params));
54
55 let send = MsgraphSend::get(auth, url);
56
57 Ok(Self { send })
58 }
59}
60
61impl MsgraphCoroutine for MsgraphCalendarView {
62 type Yield = MsgraphYield;
63 type Return = Result<MsgraphSendOutput<MsgraphEventsListResponse>, MsgraphSendError>;
64
65 fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
66 let out = msgraph_try!(&mut self.send, arg);
67 debug!("calendar view listed");
68 trace!("out: {out:?}");
69 MsgraphCoroutineState::Complete(Ok(out))
70 }
71}