Skip to main content

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

1//! Get a Microsoft Graph event (`GET /me/events/{id}`).
2//!
3//! <https://learn.microsoft.com/en-us/graph/api/event-get>
4
5use alloc::format;
6
7use io_http::rfc6750::bearer::HttpAuthBearer;
8use log::{debug, trace};
9use url::Url;
10
11use crate::{
12    coroutine::*,
13    msgraph_try,
14    v1::{
15        rest::users::events::MsgraphEvent,
16        send::{
17            MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, path_segment,
18            user_path,
19        },
20    },
21};
22
23/// Gets a Microsoft Graph event.
24pub struct MsgraphEventGet {
25    send: MsgraphSend<MsgraphEvent>,
26}
27
28impl MsgraphEventGet {
29    /// Gets the event `id`, trimmed to the `$select`ed properties and
30    /// `$expand`ing the given navigation clause when either is passed.
31    ///
32    /// Extended properties come back only expanded, and a series'
33    /// `cancelledOccurrences` only selected.
34    pub fn new(
35        auth: &HttpAuthBearer,
36        user_id: &str,
37        id: &str,
38        select: Option<&str>,
39        expand: Option<&str>,
40    ) -> Result<Self, MsgraphSendError> {
41        debug!("prepare microsoft graph event retrieval");
42        trace!("id: {id:?}");
43        trace!("select: {select:?}, expand: {expand:?}");
44
45        let user = user_path(user_id)?;
46        let mut url =
47            Url::parse(MSGRAPH_API_BASE)?.join(&format!("{user}/events/{}", path_segment(id)?))?;
48
49        if let Some(select) = select {
50            url.query_pairs_mut().append_pair("$select", select);
51        }
52        if let Some(expand) = expand {
53            url.query_pairs_mut().append_pair("$expand", expand);
54        }
55
56        let send = MsgraphSend::get(auth, url);
57
58        Ok(Self { send })
59    }
60}
61
62impl MsgraphCoroutine for MsgraphEventGet {
63    type Yield = MsgraphYield;
64    type Return = Result<MsgraphSendOutput<MsgraphEvent>, MsgraphSendError>;
65
66    fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
67        let out = msgraph_try!(&mut self.send, arg);
68        debug!("event retrieved");
69        trace!("out: {out:?}");
70        MsgraphCoroutineState::Complete(Ok(out))
71    }
72}