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