aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client.rs18
-rw-r--r--src/item.rs14
2 files changed, 31 insertions, 1 deletions
diff --git a/src/client.rs b/src/client.rs
index bce4d08..374cfb2 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -132,4 +132,22 @@ impl Client {
_ => Err(Error::Unknown)
}
}
+
+ pub fn post_multipart<T>(&self, path: &str, _data: &T, _files: &Vec<&str>) -> Result<String, Error>
+ where T: Serialize,
+ {
+ let url = self.url(path, &());
+ let f = reqwest::multipart::Form::new()
+ .text("balle", "klorin");
+
+ let res = self.inner.post(&url)
+ .basic_auth(self.user.clone(), Some(self.pw.clone()))
+ .header(CONTENT_TYPE, "multipart/form-data")
+ .multipart(f)
+ .send()?;
+
+ match res.status() {
+ _ => Err(Error::Unknown)
+ }
+ }
}
diff --git a/src/item.rs b/src/item.rs
index 3440fd5..326e4e8 100644
--- a/src/item.rs
+++ b/src/item.rs
@@ -21,6 +21,7 @@ use std::collections::BTreeMap;
pub struct ItemBuilder<'a> {
client : &'a Client,
data : BTreeMap<&'a str, &'a str>,
+ files: Vec<&'a str>,
}
impl<'a> ItemBuilder<'a> {
@@ -28,6 +29,7 @@ impl<'a> ItemBuilder<'a> {
ItemBuilder {
client: client,
data: BTreeMap::new(),
+ files: vec![],
}
}
@@ -41,7 +43,17 @@ impl<'a> ItemBuilder<'a> {
self
}
+ pub fn file(&mut self, fname: &'a str) -> &mut ItemBuilder<'a> {
+ self.files.push(fname);
+ self
+ }
+
pub fn create(&self) -> Result<String, Error> {
- self.client.post_data(client::ZOTAPI_ITEM_UPDATE_PATH, &self.data)
+ if self.files.is_empty() {
+ self.client.post_data(client::ZOTAPI_ITEM_UPDATE_PATH, &self.data)
+ }
+ else {
+ self.client.post_multipart(client::ZOTAPI_ITEM_UPDATE_PATH, &self.data, &self.files)
+ }
}
}