diff options
Diffstat (limited to 'src/item.rs')
-rw-r--r-- | src/item.rs | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/src/item.rs b/src/item.rs index 532ac16..52492aa 100644 --- a/src/item.rs +++ b/src/item.rs @@ -75,29 +75,27 @@ fn convert_itemdata_list_with_one_member_to_a_string() { /// /// ```no_run /// let client = zotapi::Client::new("https://myhub.com", "mychannel", "mypw"); -/// let new_post = client.item() +/// let new_post = zotapi::item() /// .title("A title") /// .body("The body of the post") /// .file("/my/photo.jpg") -/// .create()?; +/// .create(&client)?; /// # Ok::<(), zotapi::Error>(()) /// ``` #[derive(Debug)] pub struct ItemBuilder<'a> { - client: &'a Client, data: BTreeMap<&'a str, ItemData<'a>>, files: Vec<&'a str>, } -impl<'a> ItemBuilder<'a> { - pub fn new(client: &'a Client) -> ItemBuilder<'a> { - ItemBuilder { - client: client, - data: BTreeMap::new(), - files: vec![], - } +pub fn item<'a>() -> ItemBuilder<'a> { + ItemBuilder { + data: BTreeMap::new(), + files: vec![], } +} +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", ItemData::Value(text)); @@ -128,22 +126,19 @@ impl<'a> ItemBuilder<'a> { } /// Create the item by poting it to the server - pub fn create(&self) -> Result<String, Error> { + pub fn create(&self, client: &Client) -> Result<String, Error> { dbg!(self); if self.files.is_empty() { - self.client - .post_data("item/update", &self.data) + client.post_data("item/update", &self.data) } else { - self.client - .post_multipart("item/update", &self.data, &self.files) + client.post_multipart("item/update", &self.data, &self.files) } } } #[test] fn add_group_to_list_of_groups_allowed() { - let client = Client::new("https://test.com", "test", "test1234"); - let mut item = ItemBuilder::new(&client); + let mut item = item(); item.group_allow("test"); match item.data.get("groups_allow") { Some(ItemData::List(v)) => assert_eq!(v.len(), 1), |