Skip to main content

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

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