aboutsummaryrefslogtreecommitdiffstats
path: root/src/item.rs
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2019-06-12 17:11:44 +0200
committerHarald Eilertsen <haraldei@anduin.net>2019-06-12 17:11:44 +0200
commit781cf76d54db703e19684251a64af17d87f127ef (patch)
tree3c294a6124cee53718ee238e3ae42d11cf8500ea /src/item.rs
parent7e0cf71fced55f9a213858fd1ab278a166e6e8b3 (diff)
downloadrust-zotapi-781cf76d54db703e19684251a64af17d87f127ef.tar.gz
rust-zotapi-781cf76d54db703e19684251a64af17d87f127ef.tar.bz2
rust-zotapi-781cf76d54db703e19684251a64af17d87f127ef.zip
Add a bit of doc to the ItemBuilder struct.
Diffstat (limited to 'src/item.rs')
-rw-r--r--src/item.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/item.rs b/src/item.rs
index 7ea8c18..510918f 100644
--- a/src/item.rs
+++ b/src/item.rs
@@ -20,6 +20,19 @@ use crate::{
};
use std::collections::BTreeMap;
+/// A structure to help you create an item in a declarative way.
+///
+/// Typical usage:
+///
+/// ```no_run
+/// let client = zotapi::Client::new("https://myhub.com", "mychannel", "mypw");
+/// let new_post = client.item()
+/// .title("A title")
+/// .body("The body of the post")
+/// .file("/my/photo.jpg")
+/// .create()?;
+/// # Ok::<(), zotapi::Error>(())
+/// ```
pub struct ItemBuilder<'a> {
client : &'a Client,
data : BTreeMap<&'a str, &'a str>,
@@ -35,21 +48,25 @@ impl<'a> ItemBuilder<'a> {
}
}
+ /// Add a title to the post
pub fn title(&mut self, text: &'a str) -> &mut ItemBuilder<'a> {
self.data.insert("title", text);
self
}
+ /// Add the body of the post
pub fn body(&mut self, text: &'a str) -> &mut ItemBuilder<'a> {
self.data.insert("body", text);
self
}
+ /// Add a file attachment to the post
pub fn file(&mut self, fname: &'a str) -> &mut ItemBuilder<'a> {
self.files.push(fname);
self
}
+ /// Create the item by poting it to the server
pub fn create(&self) -> Result<String, Error> {
if self.files.is_empty() {
self.client.post_data(client::ZOTAPI_ITEM_UPDATE_PATH, &self.data)