Skip to main content

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

1//! Get a Microsoft Graph calendar (`GET /me/calendars/{id}`).
2//!
3//! <https://learn.microsoft.com/en-us/graph/api/calendar-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::calendars::MsgraphCalendar,
16        send::{
17            MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, path_segment,
18            user_path,
19        },
20    },
21};
22
23/// Gets a Microsoft Graph calendar.
24pub struct MsgraphCalendarGet {
25    send: MsgraphSend<MsgraphCalendar>,
26}
27
28impl MsgraphCalendarGet {
29    /// Gets the calendar `id`.
30    pub fn new(auth: &HttpAuthBearer, user_id: &str, id: &str) -> Result<Self, MsgraphSendError> {
31        debug!("prepare microsoft graph calendar retrieval");
32        trace!("id: {id:?}");
33
34        let user = user_path(user_id)?;
35        let url = Url::parse(MSGRAPH_API_BASE)?
36            .join(&format!("{user}/calendars/{}", path_segment(id)?))?;
37        let send = MsgraphSend::get(auth, url);
38
39        Ok(Self { send })
40    }
41}
42
43impl MsgraphCoroutine for MsgraphCalendarGet {
44    type Yield = MsgraphYield;
45    type Return = Result<MsgraphSendOutput<MsgraphCalendar>, MsgraphSendError>;
46
47    fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
48        let out = msgraph_try!(&mut self.send, arg);
49        debug!("calendar retrieved");
50        trace!("out: {out:?}");
51        MsgraphCoroutineState::Complete(Ok(out))
52    }
53}