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::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
22    },
23};
24
25/// Lists the instances of a Microsoft Graph series.
26pub struct MsgraphEventInstances {
27    send: MsgraphSend<MsgraphEventsListResponse>,
28}
29
30impl MsgraphEventInstances {
31    /// Lists the instances of the series master `id` between `start` and
32    /// `end`, ISO 8601 date-times.
33    pub fn new(
34        auth: &HttpAuthBearer,
35        user_id: &str,
36        id: &str,
37        start: &str,
38        end: &str,
39        params: &MsgraphEventsListParams,
40    ) -> Result<Self, MsgraphSendError> {
41        debug!("prepare microsoft graph event instances listing");
42        trace!("id: {id:?}, start: {start}, end: {end}");
43
44        let user = user_path(user_id);
45        let mut url =
46            Url::parse(MSGRAPH_API_BASE)?.join(&format!("{user}/events/{id}/instances"))?;
47        url.query_pairs_mut()
48            .append_pair("startDateTime", start)
49            .append_pair("endDateTime", end)
50            .extend_pairs(to_query_pairs(params));
51
52        let send = MsgraphSend::get(auth, url);
53
54        Ok(Self { send })
55    }
56}
57
58impl MsgraphCoroutine for MsgraphEventInstances {
59    type Yield = MsgraphYield;
60    type Return = Result<MsgraphSendOutput<MsgraphEventsListResponse>, MsgraphSendError>;
61
62    fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
63        let out = msgraph_try!(&mut self.send, arg);
64        debug!("event instances listed");
65        trace!("out: {out:?}");
66        MsgraphCoroutineState::Complete(Ok(out))
67    }
68}