io_msgraph/v1/rest/users/todo/tasks/
delta.rs1use alloc::format;
15
16use io_http::rfc6750::bearer::HttpAuthBearer;
17use log::{debug, trace};
18use serde::{Deserialize, Serialize};
19use url::Url;
20
21use crate::{
22 coroutine::*,
23 msgraph_try,
24 v1::{
25 page::{MsgraphPage, link_url},
26 rest::users::{contacts::delta::MsgraphRemoved, todo::tasks::MsgraphTodoTask},
27 send::{
28 MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, path_segment,
29 user_path,
30 },
31 },
32};
33
34pub type MsgraphTodoTasksDeltaResponse = MsgraphPage<MsgraphTodoTaskDelta>;
39
40#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
43pub struct MsgraphTodoTaskDelta {
44 #[serde(flatten)]
46 pub task: MsgraphTodoTask,
47 #[serde(default, rename = "@removed", skip_serializing_if = "Option::is_none")]
49 pub removed: Option<MsgraphRemoved>,
50}
51
52pub struct MsgraphTodoTasksDelta {
56 send: MsgraphSend<MsgraphTodoTasksDeltaResponse>,
57}
58
59impl MsgraphTodoTasksDelta {
60 pub fn new(
65 auth: &HttpAuthBearer,
66 user_id: &str,
67 list_id: &str,
68 select: Option<&str>,
69 ) -> Result<Self, MsgraphSendError> {
70 debug!("prepare microsoft graph to do tasks delta");
71 trace!("list: {list_id:?}, select: {select:?}");
72
73 let user = user_path(user_id)?;
74 let path = format!("{user}/todo/lists/{}/tasks/delta", path_segment(list_id)?);
75 let mut url = Url::parse(MSGRAPH_API_BASE)?.join(&path)?;
76 if let Some(select) = select {
77 url.query_pairs_mut().append_pair("$select", select);
78 }
79
80 let send = MsgraphSend::get(auth, url);
81
82 Ok(Self { send })
83 }
84
85 pub fn from_link(auth: &HttpAuthBearer, link: &str) -> Result<Self, MsgraphSendError> {
89 debug!("prepare microsoft graph to do tasks delta from link");
90 trace!("link: {link}");
91
92 let url = link_url(link)?;
93 let send = MsgraphSend::get(auth, url);
94
95 Ok(Self { send })
96 }
97
98 pub fn max_page_size(mut self, size: u32) -> Self {
104 self.send = self.send.max_page_size(size);
105 self
106 }
107}
108
109impl MsgraphCoroutine for MsgraphTodoTasksDelta {
110 type Yield = MsgraphYield;
111 type Return = Result<MsgraphSendOutput<MsgraphTodoTasksDeltaResponse>, MsgraphSendError>;
112
113 fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
114 let out = msgraph_try!(&mut self.send, arg);
115 debug!("to do tasks delta page received");
116 trace!("out: {out:?}");
117 MsgraphCoroutineState::Complete(Ok(out))
118 }
119}