feat(nsconfig): basic config and basic integration in service
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use crate::services::service::Service;
|
||||
use crate::store::object::Obj;
|
||||
use crate::config::config::Config;
|
||||
|
||||
pub enum Props {
|
||||
CreationDate,
|
||||
@@ -39,12 +40,19 @@ pub struct ReqProps {
|
||||
|
||||
impl ReqProps {
|
||||
pub fn new(path: &str) -> Self {
|
||||
let mut service = Service::new();
|
||||
service.propfind(path.to_owned());
|
||||
ReqProps {
|
||||
service: Service::new(),
|
||||
service,
|
||||
properties: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_config(mut self, config: &Config) -> Self {
|
||||
self.service.set_config(config.clone());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn get_properties(mut self, properties: Vec<Props>) -> Self {
|
||||
self.properties.extend(properties);
|
||||
self
|
||||
@@ -66,16 +74,12 @@ impl ReqProps {
|
||||
}
|
||||
|
||||
pub fn send(&mut self) {
|
||||
self.service
|
||||
.propfind(String::from(
|
||||
"http://localhost:8080/remote.php/dav/files/admin/Documents",
|
||||
))
|
||||
.send();
|
||||
self.service.send();
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Obj> for ReqProps {
|
||||
fn from(obj: Obj) -> Self {
|
||||
ReqProps::new("")
|
||||
ReqProps::new(obj.get_obj_path().to_str().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use core::ops::{Deref, DerefMut};
|
||||
use reqwest::blocking::{Client, ClientBuilder, RequestBuilder};
|
||||
use reqwest::{header::HeaderMap, Method, Url};
|
||||
use crate::config::config::Config;
|
||||
use reqwest::blocking::{Client, ClientBuilder};
|
||||
use reqwest::{header::HeaderMap, Method, Url};
|
||||
|
||||
const USER_AGENT: &str = "Nextsync";
|
||||
|
||||
@@ -16,17 +16,27 @@ impl ClientConfig {
|
||||
}
|
||||
|
||||
pub fn default_headers(mut self, headers: HeaderMap) -> Self {
|
||||
self.client = Some(self.client.take().expect("Client was already built").default_headers(headers));
|
||||
self.client = Some(
|
||||
self.client
|
||||
.take()
|
||||
.expect("Client was already built")
|
||||
.default_headers(headers),
|
||||
);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(&mut self) -> Client {
|
||||
self.client.take().expect("Cannot build the client twice").build().unwrap()
|
||||
self.client
|
||||
.take()
|
||||
.expect("Cannot build the client twice")
|
||||
.build()
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Service {
|
||||
client: ClientConfig,
|
||||
config: Option<Config>,
|
||||
method: Option<Method>,
|
||||
url: Option<String>,
|
||||
headers: HeaderMap,
|
||||
@@ -37,6 +47,7 @@ impl Service {
|
||||
pub fn new() -> Self {
|
||||
Service {
|
||||
client: ClientConfig::new(),
|
||||
config: None,
|
||||
method: None,
|
||||
url: None,
|
||||
headers: HeaderMap::new(),
|
||||
@@ -44,6 +55,10 @@ impl Service {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_config(&mut self, config: Config) {
|
||||
self.config = Some(config);
|
||||
}
|
||||
|
||||
pub fn propfind(&mut self, url: String) -> &mut Self {
|
||||
self.method = Some(Method::from_bytes(b"PROPFIND").expect("Cannot be invalid"));
|
||||
self.url = Some(url);
|
||||
@@ -51,12 +66,19 @@ impl Service {
|
||||
}
|
||||
|
||||
pub fn send(&mut self) {
|
||||
dbg!(self.client
|
||||
let mut url = self
|
||||
.config.clone()
|
||||
.expect("A config must be provided to service")
|
||||
.get_nsconfig()
|
||||
.get_remote("origin")
|
||||
.url
|
||||
.expect("An url must be set on the remote");
|
||||
url.push_str(&self.url.clone().unwrap());
|
||||
|
||||
dbg!(self
|
||||
.client
|
||||
.build()
|
||||
.request(
|
||||
self.method.clone().expect("Method must be set"),
|
||||
self.url.clone().expect("Url must be set"),
|
||||
)
|
||||
.request(self.method.clone().expect("Method must be set"), url,)
|
||||
.bearer_auth("rK5ud2NmrR8p586Th7v272HRgUcZcEKIEluOGjzQQRj7gWMMAISFTiJcFnnmnNiu2VVlENks")
|
||||
.send());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user