aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/zot/zot/item.rs
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2023-03-29 13:08:09 +0200
committerHarald Eilertsen <haraldei@anduin.net>2023-03-29 13:08:09 +0200
commit8100cff32bf0c87dc19fba78f3faac8090f863da (patch)
tree7c6315dbb83162b8d91aae53b920c2e7f20a4268 /src/bin/zot/zot/item.rs
parenta4b9520f430ce188ba9165dcabd3320763ff2e16 (diff)
downloadrust-zotapi-8100cff32bf0c87dc19fba78f3faac8090f863da.tar.gz
rust-zotapi-8100cff32bf0c87dc19fba78f3faac8090f863da.tar.bz2
rust-zotapi-8100cff32bf0c87dc19fba78f3faac8090f863da.zip
Another reqrite...
Third time must be where it sits I hope. I felt the API was getting a bit too distracted by unnecessary constructs and abstractions, so I'm trying to simplify it by making it more straight forward. The idea now is to have one main API class (ZotApi), and all the various remote API's as public methods on this basic class. Iow, the ZotApi class is mainly based on the existing `Client` class, which is then being phased out. And instead of having each API tied to the data type they return, I'm just adding methods that will return the respective data types. This should reduce coupling between the returned data, and the API calls themselves.
Diffstat (limited to 'src/bin/zot/zot/item.rs')
-rw-r--r--src/bin/zot/zot/item.rs57
1 files changed, 0 insertions, 57 deletions
diff --git a/src/bin/zot/zot/item.rs b/src/bin/zot/zot/item.rs
deleted file mode 100644
index dbb39ba..0000000
--- a/src/bin/zot/zot/item.rs
+++ /dev/null
@@ -1,57 +0,0 @@
-/* Example Zot API command line utility, part of zotapi.
- * Copyright (C) 2018 Harald Eilertsen <haraldei@anduin.net>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-use clap::ArgMatches;
-use zotapi;
-
-pub async fn post(client: &zotapi::Client, args: &ArgMatches<'_>) {
- let mut msg = zotapi::item();
- let body: String;
-
- if let Some(file) = dbg!(args.value_of("FILE")) {
- let buf = std::fs::read(file).expect("Invalid file name");
- body = String::from_utf8(buf).expect("File contained invalid char data.");
- msg.body(&body);
- }
-
- if let Some(title) = dbg!(args.value_of("TITLE")) {
- msg.title(title);
- }
-
- if let Some(file) = dbg!(args.value_of("ATTACH")) {
- msg.file(file);
- }
-
- if let Some(groups) = dbg!(args.value_of("GROUP")) {
- for g in groups.split(",") {
- msg.group_allow(g);
- }
- }
-
- match msg.create(&client).await {
- Ok(res) => {
- if res.success {
- println!("New item with id {} posted successfully!", res.item_id);
- } else {
- println!("The item could not be posted.");
- }
- }
- Err(e) => {
- println!("Error posting message: {:?}", e);
- }
- }
-}