diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2023-03-26 14:14:52 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2023-03-26 14:14:52 +0200 |
commit | 3cc87b45f70ae32fe8ca69b3cd185dd8d56d94dd (patch) | |
tree | cbc0b84d6668de545c623834727665cbb08902ba /src/bin | |
parent | d08138ea633da76d9ca390e4f9e3c5489aee23d1 (diff) | |
download | rust-zotapi-3cc87b45f70ae32fe8ca69b3cd185dd8d56d94dd.tar.gz rust-zotapi-3cc87b45f70ae32fe8ca69b3cd185dd8d56d94dd.tar.bz2 rust-zotapi-3cc87b45f70ae32fe8ca69b3cd185dd8d56d94dd.zip |
Fetch abook and xchan directly from api.
We don't really need the intermediate layer in the binary module.
Diffstat (limited to 'src/bin')
-rw-r--r-- | src/bin/zot/main.rs | 27 | ||||
-rw-r--r-- | src/bin/zot/zot/abook.rs | 29 | ||||
-rw-r--r-- | src/bin/zot/zot/mod.rs | 2 | ||||
-rw-r--r-- | src/bin/zot/zot/xchan.rs | 41 |
4 files changed, 19 insertions, 80 deletions
diff --git a/src/bin/zot/main.rs b/src/bin/zot/main.rs index 09fdd61..f2caac4 100644 --- a/src/bin/zot/main.rs +++ b/src/bin/zot/main.rs @@ -90,8 +90,13 @@ async fn main() { zot::abconfig::fetch(&client).await; } ("abook", Some(m)) => { - let raw = m.is_present("raw"); - zot::abook::fetch(&client, raw).await; + let r = zotapi::Abook::z(); + + if m.is_present("raw") { + println!("{}", r.fetch_raw(&client).await.unwrap()); + } else { + println!("{:?}", r.fetch(&client).await); + } } ("group", Some(m)) => { if let Some(id) = m.value_of("ID") { @@ -129,16 +134,22 @@ async fn main() { } } ("xchan", Some(m)) => { - let raw = m.is_present("raw"); - let t = if m.is_present("guid") { - zot::xchan::Type::GUID + let mut r = zotapi::XChan::z(); + let id = m.value_of("ID").expect("No xchan provided."); + + if m.is_present("guid") { + r.by_guid(id) } else if m.is_present("hash") { - zot::xchan::Type::Hash + r.by_hash(id) } else { - zot::xchan::Type::Addr + r.by_address(id) }; - zot::xchan::fetch(&client, raw, t, m.value_of("ID").unwrap()).await; + if m.is_present("raw") { + println!("{}", r.fetch_raw(&client).await.unwrap()); + } else { + println!("{:?}", r.fetch(&client).await); + } } ("post", Some(m)) => { zot::item::post(&client, m).await; diff --git a/src/bin/zot/zot/abook.rs b/src/bin/zot/zot/abook.rs deleted file mode 100644 index 6c33757..0000000 --- a/src/bin/zot/zot/abook.rs +++ /dev/null @@ -1,29 +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/>. - */ - -pub async fn fetch(client: &zotapi::Client, _raw: bool) { - match zotapi::Abook::z().fetch(&client).await { - Ok(abooks) => { - for b in abooks { - println!("{:?}", b); - } - } - Err(e) => { - println!("{:?}", e); - } - } -} diff --git a/src/bin/zot/zot/mod.rs b/src/bin/zot/zot/mod.rs index 706f496..23e25ec 100644 --- a/src/bin/zot/zot/mod.rs +++ b/src/bin/zot/zot/mod.rs @@ -1,7 +1,5 @@ pub mod abconfig; -pub mod abook; pub mod channel_stream; pub mod group; pub mod item; pub mod network_stream; -pub mod xchan; diff --git a/src/bin/zot/zot/xchan.rs b/src/bin/zot/zot/xchan.rs deleted file mode 100644 index 146b2ab..0000000 --- a/src/bin/zot/zot/xchan.rs +++ /dev/null @@ -1,41 +0,0 @@ -/* Example Zot API command line utility, part of zotapi. - * Copyright (C) 2018 <name of copyright holder> - * - * 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 zotapi; - -pub enum Type { - Addr, - Hash, - GUID, -} - -pub async fn fetch(client: &zotapi::Client, _raw: bool, t: Type, id: &str) { - let res = match t { - Type::Addr => zotapi::XChan::z().by_address(&id).fetch(&client).await, - Type::Hash => zotapi::XChan::z().by_hash(&id).fetch(&client).await, - Type::GUID => zotapi::XChan::z().by_guid(&id).fetch(&client).await, - }; - - match res { - Ok(payload) => { - println!("{:?}", payload); - } - Err(e) => { - println!("{:?}", e); - } - } -} |