From 781cf76d54db703e19684251a64af17d87f127ef Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Wed, 12 Jun 2019 17:11:44 +0200 Subject: Add a bit of doc to the ItemBuilder struct. --- src/item.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 { if self.files.is_empty() { self.client.post_data(client::ZOTAPI_ITEM_UPDATE_PATH, &self.data) -- cgit v1.2.3