add url builder

This commit is contained in:
grimhilt 2023-06-15 14:54:46 +02:00
parent 80ef41970f
commit 12a332dac2
2 changed files with 20 additions and 3 deletions

View File

@ -28,6 +28,18 @@ impl ApiBuilder {
self 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 { fn set_auth(&mut self) -> &mut ApiBuilder {
// todo if not exist // todo if not exist
dotenv().ok(); dotenv().ok();

View File

@ -10,15 +10,19 @@ pub struct ReqProps {
} }
impl ReqProps { impl ReqProps {
pub fn new<U: IntoUrl>(url: U) -> Self { pub fn new() -> Self {
ReqProps { ReqProps {
api_builder: ApiBuilder::new() api_builder: ApiBuilder::new(),
.set_request(Method::from_bytes(b"PROPFIND").unwrap(), url),
xml_list: vec![], xml_list: vec![],
xml_payload: String::new(), 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 { pub fn getlastmodified(&mut self) -> &mut ReqProps {
self.xml_list.push(String::from("getlastmodified")); self.xml_list.push(String::from("getlastmodified"));
self.xml_payload.push_str(r#"<d:getlastmodified/>"#); self.xml_payload.push_str(r#"<d:getlastmodified/>"#);
@ -90,6 +94,7 @@ impl ReqProps {
vec![] vec![]
} }
Err(ApiError::RequestError(err)) => { Err(ApiError::RequestError(err)) => {
dbg!("req erro");
eprintln!("fatal: {}", err); eprintln!("fatal: {}", err);
std::process::exit(1); std::process::exit(1);
} }