Skip to main content

io_msgraph/v1/rest/users/events/
calendar_view.rs

1//! List the Microsoft Graph calendar view (`GET /me/calendarView` or
2//! `GET /me/calendars/{id}/calendarView`).
3//!
4//! Every lone event, occurrence and exception within a window, series
5//! expanded.
6//!
7//! <https://learn.microsoft.com/en-us/graph/api/user-list-calendarview>
8
9use 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::{
22            MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, path_segment,
23            user_path,
24        },
25    },
26};
27
28/// Lists a Microsoft Graph calendar view.
29pub struct MsgraphCalendarView {
30    send: MsgraphSend<MsgraphEventsListResponse>,
31}
32
33impl MsgraphCalendarView {
34    /// Lists the view of the default calendar, or of `calendar` when given,
35    /// between `start` and `end`, ISO 8601 date-times.
36    pub fn new(
37        auth: &HttpAuthBearer,
38        user_id: &str,
39        calendar: Option<&str>,
40        start: &str,
41        end: &str,
42        params: &MsgraphEventsListParams,
43    ) -> Result<Self, MsgraphSendError> {
44        debug!("prepare microsoft graph calendar view");
45        trace!("calendar: {calendar:?}, start: {start}, end: {end}");
46
47        let user = user_path(user_id)?;
48        let path = match calendar {
49            Some(calendar) => format!("{user}/calendars/{}/calendarView", path_segment(calendar)?),
50            None => format!("{user}/calendarView"),
51        };
52        let mut url = Url::parse(MSGRAPH_API_BASE)?.join(&path)?;
53        url.query_pairs_mut()
54            .append_pair("startDateTime", start)
55            .append_pair("endDateTime", end)
56            .extend_pairs(to_query_pairs(params));
57
58        let send = MsgraphSend::get(auth, url);
59
60        Ok(Self { send })
61    }
62}
63
64impl MsgraphCoroutine for MsgraphCalendarView {
65    type Yield = MsgraphYield;
66    type Return = Result<MsgraphSendOutput<MsgraphEventsListResponse>, MsgraphSendError>;
67
68    fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
69        let out = msgraph_try!(&mut self.send, arg);
70        debug!("calendar view listed");
71        trace!("out: {out:?}");
72        MsgraphCoroutineState::Complete(Ok(out))
73    }
74}