Skip to main content

io_msgraph/v1/rest/users/todo/tasks/
get.rs

1//! Get a Microsoft To Do task (`GET /me/todo/lists/{id}/tasks/{id}`).
2//!
3//! <https://learn.microsoft.com/en-us/graph/api/todotask-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::todo::tasks::MsgraphTodoTask,
16        send::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
17    },
18};
19
20/// Gets a Microsoft To Do task.
21pub struct MsgraphTodoTaskGet {
22    send: MsgraphSend<MsgraphTodoTask>,
23}
24
25impl MsgraphTodoTaskGet {
26    /// Gets the task `id` of the list `list_id`, trimmed to the
27    /// `$select`ed properties and `$expand`ing the given navigation
28    /// clause when either is passed.
29    ///
30    /// Extended properties and checklist items come back only expanded.
31    pub fn new(
32        auth: &HttpAuthBearer,
33        user_id: &str,
34        list_id: &str,
35        id: &str,
36        select: Option<&str>,
37        expand: Option<&str>,
38    ) -> Result<Self, MsgraphSendError> {
39        debug!("prepare microsoft graph to do task retrieval");
40        trace!("list: {list_id:?}, id: {id:?}");
41        trace!("select: {select:?}, expand: {expand:?}");
42
43        let user = user_path(user_id);
44        let path = format!("{user}/todo/lists/{list_id}/tasks/{id}");
45        let mut url = Url::parse(MSGRAPH_API_BASE)?.join(&path)?;
46
47        if let Some(select) = select {
48            url.query_pairs_mut().append_pair("$select", select);
49        }
50        if let Some(expand) = expand {
51            url.query_pairs_mut().append_pair("$expand", expand);
52        }
53
54        let send = MsgraphSend::get(auth, url);
55
56        Ok(Self { send })
57    }
58}
59
60impl MsgraphCoroutine for MsgraphTodoTaskGet {
61    type Yield = MsgraphYield;
62    type Return = Result<MsgraphSendOutput<MsgraphTodoTask>, MsgraphSendError>;
63
64    fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
65        let out = msgraph_try!(&mut self.send, arg);
66        debug!("to do task retrieved");
67        trace!("out: {out:?}");
68        MsgraphCoroutineState::Complete(Ok(out))
69    }
70}