io_msgraph/v1/rest/users/calendars/
list.rs1use alloc::format;
6
7use io_http::rfc6750::bearer::HttpAuthBearer;
8use log::{debug, trace};
9use serde::Serialize;
10use url::Url;
11
12use crate::{
13 coroutine::*,
14 msgraph_try,
15 v1::{
16 page::MsgraphPage,
17 query::to_query_pairs,
18 rest::users::calendars::MsgraphCalendar,
19 send::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
20 },
21};
22
23pub type MsgraphCalendarsListResponse = MsgraphPage<MsgraphCalendar>;
25
26#[derive(Debug, Clone, Default, Serialize, Eq, PartialEq)]
28pub struct MsgraphCalendarsListParams<'a> {
29 #[serde(rename = "$top")]
31 pub top: Option<u32>,
32 #[serde(rename = "$skip")]
34 pub skip: Option<u32>,
35 #[serde(rename = "$select")]
37 pub select: Option<&'a str>,
38 #[serde(rename = "$filter")]
40 pub filter: Option<&'a str>,
41}
42
43pub struct MsgraphCalendarsList {
45 send: MsgraphSend<MsgraphCalendarsListResponse>,
46}
47
48impl MsgraphCalendarsList {
49 pub fn new(
51 auth: &HttpAuthBearer,
52 user_id: &str,
53 params: &MsgraphCalendarsListParams,
54 ) -> Result<Self, MsgraphSendError> {
55 debug!("prepare microsoft graph calendars listing");
56 trace!("params: {params:?}");
57
58 let user = user_path(user_id)?;
59 let mut url = Url::parse(MSGRAPH_API_BASE)?.join(&format!("{user}/calendars"))?;
60 url.query_pairs_mut().extend_pairs(to_query_pairs(params));
61
62 let send = MsgraphSend::get(auth, url);
63
64 Ok(Self { send })
65 }
66}
67
68impl MsgraphCoroutine for MsgraphCalendarsList {
69 type Yield = MsgraphYield;
70 type Return = Result<MsgraphSendOutput<MsgraphCalendarsListResponse>, MsgraphSendError>;
71
72 fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
73 let out = msgraph_try!(&mut self.send, arg);
74 debug!("calendars listed");
75 trace!("out: {out:?}");
76 MsgraphCoroutineState::Complete(Ok(out))
77 }
78}