From 45bd81f8834c574300e7288f4459b7337c2dcf27 Mon Sep 17 00:00:00 2001 From: daladim Date: Sun, 21 Feb 2021 23:29:21 +0100 Subject: [PATCH] Placeholder for get_tasks --- src/data/client.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/data/client.rs b/src/data/client.rs index 7d6dd6b..c26f727 100644 --- a/src/data/client.rs +++ b/src/data/client.rs @@ -40,6 +40,28 @@ static CAL_BODY: &str = r#" "#; +static TASKS_BODY: &str = r#" + + + + + + + + + + + + + CANCELLED + + + + + +"#; + pub struct Client { url: Url, username: String, @@ -192,12 +214,38 @@ impl Client { self.calendars = Some(calendars.clone()); Ok(calendars) } + + async fn get_tasks(&mut self, calendar: &Url) -> Result<(), Box> { + let method = Method::from_bytes(b"REPORT") + .expect("cannot create REPORT method."); + + let res = reqwest::Client::new() + .request(method, calendar.as_str()) + .header("Depth", 1) + .header(CONTENT_TYPE, "application/xml") + .basic_auth(self.username.clone(), Some(self.password.clone())) + .body(TASKS_BODY) + .send() + .await?; + let text = res.text().await?; + + let el: Element = text.parse().unwrap(); + let responses = find_elems(&el, "response"); + + for response in responses { + crate::print_xml(response); + println!("\n"); + } + + Ok(()) + } } + #[cfg(test)] mod test { use super::*;