diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/item.rs | 17 |
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) |