aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 9d22679..7520475 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -17,7 +17,7 @@
extern crate reqwest;
use reqwest::{
- header::{Accept, qitem},
+ header::{Accept, ContentType, qitem},
mime,
StatusCode,
};
@@ -25,6 +25,7 @@ use std::io::Read;
const ZOTAPI_CHANNEL_STREAM_PATH : &str = "/api/z/1.0/channel/stream";
const ZOTAPI_NETWORK_STREAM_PATH : &str = "/api/z/1.0/network/stream";
+const ZOTAPI_ITEM_UPDATE_PATH : &str = "/api/z/1.0/item/update";
#[derive(Debug)]
pub enum Error {
@@ -62,6 +63,26 @@ impl Client {
self.fetch_stream(ZOTAPI_NETWORK_STREAM_PATH)
}
+ pub fn create_item(&self, body: &str) -> Result<String, Error> {
+ let url = self.url(ZOTAPI_ITEM_UPDATE_PATH);
+ let mut res = self.inner.post(&url)
+ .header(Accept(vec![qitem(mime::APPLICATION_JSON)]))
+ .header(ContentType::form_url_encoded())
+ .basic_auth(self.user.clone(), Some(self.pw.clone()))
+ .form(&[("body", body)])
+ .send()?;
+
+ match res.status() {
+ StatusCode::Unauthorized => Err(Error::Unauthorized),
+ StatusCode::Ok => {
+ let mut body = String::new();
+ res.read_to_string(&mut body)?;
+ Ok(body)
+ },
+ _ => Err(Error::Unknown)
+ }
+ }
+
fn url(&self, path: &str) -> String {
self.base_url.clone() + path
}