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::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
17    },
18};
19
20/// Gets a Microsoft Graph event.
21pub struct MsgraphEventGet {
22    send: MsgraphSend<MsgraphEvent>,
23}
24
25impl MsgraphEventGet {
26    /// Gets the event `id`, trimmed to the `$select`ed properties and
27    /// `$expand`ing the given navigation clause when either is passed.
28    ///
29    /// Extended properties come back only expanded, and a series'
30    /// `cancelledOccurrences` only selected.
31    pub fn new(
32        auth: &HttpAuthBearer,
33        user_id: &str,
34        id: &str,
35        select: Option<&str>,
36        expand: Option<&str>,
37    ) -> Result<Self, MsgraphSendError> {
38        debug!("prepare microsoft graph event retrieval");
39        trace!("id: {id:?}");
40        trace!("select: {select:?}, expand: {expand:?}");
41
42        let user = user_path(user_id);
43        let mut url = Url::parse(MSGRAPH_API_BASE)?.join(&format!("{user}/events/{id}"))?;
44
45        if let Some(select) = select {
46            url.query_pairs_mut().append_pair("$select", select);
47        }
48        if let Some(expand) = expand {
49            url.query_pairs_mut().append_pair("$expand", expand);
50        }
51
52        let send = MsgraphSend::get(auth, url);
53
54        Ok(Self { send })
55    }
56}
57
58impl MsgraphCoroutine for MsgraphEventGet {
59    type Yield = MsgraphYield;
60    type Return = Result<MsgraphSendOutput<MsgraphEvent>, 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 retrieved");
65        trace!("out: {out:?}");
66        MsgraphCoroutineState::Complete(Ok(out))
67    }
68}