feat(reqprops): deserialize response
This commit is contained in:
parent
61531f664b
commit
3af7a00b0f
@ -18,9 +18,12 @@ pub fn exec(args: TestArgs, config: Config) {
|
||||
// println!("{:?}", config);
|
||||
|
||||
// Ok(())
|
||||
let req = ReqProps::new("")
|
||||
tokio::runtime::Runtime::new().unwrap().block_on(async {
|
||||
|
||||
let mut req = ReqProps::new("")
|
||||
.set_config(&config)
|
||||
.get_properties(vec![Props::CreationDate, Props::GetLastModified])
|
||||
.send();
|
||||
dbg!(req);
|
||||
.get_properties(vec![Props::CreationDate, Props::LastModified]);
|
||||
req.send().await;
|
||||
});
|
||||
// dbg!(req);
|
||||
}
|
||||
|
@ -1,15 +1,17 @@
|
||||
use crate::services::service::Service;
|
||||
use crate::store::object::Obj;
|
||||
use crate::config::config::Config;
|
||||
use serde::Deserialize;
|
||||
use serde_xml_rs::from_str;
|
||||
|
||||
pub enum Props {
|
||||
CreationDate,
|
||||
GetLastModified,
|
||||
GetETag,
|
||||
GetContentType,
|
||||
LastModified,
|
||||
ETag,
|
||||
ContentType,
|
||||
RessourceType,
|
||||
GetContentLength,
|
||||
GetContentLanguage,
|
||||
ContentLength,
|
||||
ContentLanguage,
|
||||
DisplayName,
|
||||
FileId,
|
||||
Permissions,
|
||||
@ -23,11 +25,41 @@ pub enum Props {
|
||||
ContainedFileCountm,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Propstat {
|
||||
#[serde(rename = "prop")]
|
||||
prop: Prop,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Prop {
|
||||
#[serde(rename = "getlastmodified")]
|
||||
last_modified: Option<String>,
|
||||
#[serde(rename = "getcontentlength")]
|
||||
content_length: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Response {
|
||||
#[serde(rename = "href")]
|
||||
href: String,
|
||||
#[serde(rename = "propstat")]
|
||||
propstat: Propstat,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Multistatus {
|
||||
#[serde(rename = "response")]
|
||||
responses: Vec<Response>,
|
||||
}
|
||||
|
||||
|
||||
impl From<&Props> for &str {
|
||||
fn from(variant: &Props) -> Self {
|
||||
match variant {
|
||||
Props::CreationDate => "<d:creationdate />",
|
||||
Props::GetLastModified => "<d:getlastmodified />",
|
||||
Props::LastModified => "<d:getlastmodified />",
|
||||
_ => todo!("Props conversion not implemented"),
|
||||
}
|
||||
}
|
||||
@ -73,8 +105,18 @@ impl ReqProps {
|
||||
xml
|
||||
}
|
||||
|
||||
pub fn send(&mut self) {
|
||||
self.service.send();
|
||||
pub async fn send(&mut self) {
|
||||
dbg!("send");
|
||||
let res = self.service.send().await;
|
||||
dbg!("Sent");
|
||||
let text = res.unwrap().text().await.unwrap();
|
||||
self.parse(&text);
|
||||
}
|
||||
|
||||
fn parse (&self, xml: &str) {
|
||||
dbg!("Parsing");
|
||||
let multistatus: Multistatus = from_str(&xml).unwrap();
|
||||
dbg!(multistatus);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::config::config::Config;
|
||||
use reqwest::blocking::{Client, ClientBuilder};
|
||||
use reqwest::{Client, ClientBuilder};
|
||||
use reqwest::{header::HeaderMap, Method, Url};
|
||||
|
||||
const USER_AGENT: &str = "Nextsync";
|
||||
@ -65,9 +65,10 @@ impl Service {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn send(&mut self) {
|
||||
pub async fn send(&mut self) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let mut url = self
|
||||
.config.clone()
|
||||
.config
|
||||
.clone()
|
||||
.expect("A config must be provided to service")
|
||||
.get_nsconfig()
|
||||
.get_remote("origin")
|
||||
@ -75,11 +76,11 @@ impl Service {
|
||||
.expect("An url must be set on the remote");
|
||||
url.push_str(&self.url.clone().unwrap());
|
||||
|
||||
dbg!(self
|
||||
.client
|
||||
self.client
|
||||
.build()
|
||||
.request(self.method.clone().expect("Method must be set"), url,)
|
||||
.request(self.method.clone().expect("Method must be set"), url)
|
||||
.bearer_auth("rK5ud2NmrR8p586Th7v272HRgUcZcEKIEluOGjzQQRj7gWMMAISFTiJcFnnmnNiu2VVlENks")
|
||||
.send());
|
||||
.send()
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user