Skip to main content

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

1//! List the instances of a Microsoft Graph series
2//! (`GET /me/events/{id}/instances`).
3//!
4//! The occurrences and exceptions of a series master within a window,
5//! cancelled occurrences left out.
6//!
7//! <https://learn.microsoft.com/en-us/graph/api/event-list-instances>
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 the instances of a Microsoft Graph series.
29pub struct MsgraphEventInstances {
30    send: MsgraphSend<MsgraphEventsListResponse>,
31}
32
33impl MsgraphEventInstances {
34    /// Lists the instances of the series master `id` between `start` and
35    /// `end`, ISO 8601 date-times.
36    pub fn new(
37        auth: &HttpAuthBearer,
38        user_id: &str,
39        id: &str,
40        start: &str,
41        end: &str,
42        params: &MsgraphEventsListParams,
43    ) -> Result<Self, MsgraphSendError> {
44        debug!("prepare microsoft graph event instances listing");
45        trace!("id: {id:?}, start: {start}, end: {end}");
46
47        let user = user_path(user_id)?;
48        let mut url = Url::parse(MSGRAPH_API_BASE)?
49            .join(&format!("{user}/events/{}/instances", path_segment(id)?))?;
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 MsgraphEventInstances {
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!("event instances listed");
68        trace!("out: {out:?}");
69        MsgraphCoroutineState::Complete(Ok(out))
70    }
71}