io_msgraph/v1/rest/users/todo/lists/
create.rs1use 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::lists::MsgraphTodoList,
16 send::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
17 },
18};
19
20pub struct MsgraphTodoListCreate {
22 send: MsgraphSend<MsgraphTodoList>,
23}
24
25impl MsgraphTodoListCreate {
26 pub fn new(
28 auth: &HttpAuthBearer,
29 user_id: &str,
30 list: &MsgraphTodoList,
31 ) -> Result<Self, MsgraphSendError> {
32 debug!("prepare microsoft graph to do list creation");
33 trace!("list: {list:?}");
34
35 let user = user_path(user_id)?;
36 let url = Url::parse(MSGRAPH_API_BASE)?.join(&format!("{user}/todo/lists"))?;
37 let send = MsgraphSend::post_json(auth, url, list)?;
38
39 Ok(Self { send })
40 }
41}
42
43impl MsgraphCoroutine for MsgraphTodoListCreate {
44 type Yield = MsgraphYield;
45 type Return = Result<MsgraphSendOutput<MsgraphTodoList>, MsgraphSendError>;
46
47 fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
48 let out = msgraph_try!(&mut self.send, arg);
49 debug!("to do list created");
50 trace!("out: {out:?}");
51 MsgraphCoroutineState::Complete(Ok(out))
52 }
53}