diff --git a/src/services/api.rs b/src/services/api.rs index 887e8a9..8998fef 100644 --- a/src/services/api.rs +++ b/src/services/api.rs @@ -28,6 +28,18 @@ impl ApiBuilder { self } + pub fn build_request(&mut self, method: Method, path: &str) -> &mut ApiBuilder { + dotenv().ok(); + let host = env::var("HOST").unwrap(); + let username = env::var("USERNAME").unwrap(); + let mut url = String::from(host); + url.push_str("/remote.php/dav/files/"); + url.push_str(&username); + url.push_str(path); + self.request = Some(self.client.request(method, url)); + self + } + fn set_auth(&mut self) -> &mut ApiBuilder { // todo if not exist dotenv().ok(); diff --git a/src/services/req_props.rs b/src/services/req_props.rs index 4cf1169..0213eb8 100644 --- a/src/services/req_props.rs +++ b/src/services/req_props.rs @@ -10,15 +10,19 @@ pub struct ReqProps { } impl ReqProps { - pub fn new(url: U) -> Self { + pub fn new() -> Self { ReqProps { - api_builder: ApiBuilder::new() - .set_request(Method::from_bytes(b"PROPFIND").unwrap(), url), + api_builder: ApiBuilder::new(), xml_list: vec![], xml_payload: String::new(), } } + pub fn set_url(&mut self, url: &str) -> &mut ReqProps { + self.api_builder.build_request(Method::from_bytes(b"PROPFIND").unwrap(), url); + self + } + pub fn getlastmodified(&mut self) -> &mut ReqProps { self.xml_list.push(String::from("getlastmodified")); self.xml_payload.push_str(r#""#); @@ -90,6 +94,7 @@ impl ReqProps { vec![] } Err(ApiError::RequestError(err)) => { + dbg!("req erro"); eprintln!("fatal: {}", err); std::process::exit(1); }