From d9375da4ebf466b6cbcac3b919b7226f0617a9c7 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 1 Apr 2023 20:28:27 +0200 Subject: Implement channel API's. These just output the result as json for now, that's not what we want in the end, but it's where we start. --- src/bin/zot/main.rs | 35 ++++++++++++++++++++++++++++++----- src/zotapi.rs | 25 +++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/bin/zot/main.rs b/src/bin/zot/main.rs index 7f49eb4..63b4557 100644 --- a/src/bin/zot/main.rs +++ b/src/bin/zot/main.rs @@ -36,13 +36,22 @@ async fn main() -> Result<(), Box<(dyn std::error::Error + 'static)>> { (@arg channel: --channel "The channel to connect as.") (@arg password: --password "The password.") (@subcommand verify => - (about: "Verify") + (about: "Fetch the channel object of the logged in channel.") ) (@subcommand version => (about: "Return the version of a server.") ) (@subcommand channel => - (about: "Fetch the channel stream") + (about: "Work with channels") + (@subcommand list => + (about: "List channels for the logged in account.") + ) + (@subcommand stream => + (about: "Fetch the channel stream.") + ) + (@subcommand export => + (about: "Export the channel.") + ) ) (@subcommand network => (about: "Fetch the network stream") @@ -97,11 +106,27 @@ async fn main() -> Result<(), Box<(dyn std::error::Error + 'static)>> { ("version", Some(_)) => { println!("{}", z.version().await?); } - /* + ("channel", Some(m)) => { - let raw = m.is_present("raw"); - zot::channel_stream::fetch(&client, raw).await; + match m.subcommand() { + ("list", Some(_)) => { + for ch in z.channel_list().await? { + println!("{}", ch); + } + } + ("stream", Some(_)) => { + println!("{}", z.channel_stream().await?); + } + ("export", Some(_)) => { + println!("{}", z.channel_export().await?); + } + _ => { + println!("Not a known subcommand for `channel`, or it's not implemented yet."); + println!("{}", m.usage()); + } + } } + /* ("network", Some(m)) => { let raw = m.is_present("raw"); zot::network_stream::fetch(&client, raw).await; diff --git a/src/zotapi.rs b/src/zotapi.rs index 2d50ef3..5a2f5cc 100644 --- a/src/zotapi.rs +++ b/src/zotapi.rs @@ -60,6 +60,31 @@ impl ZotApi { Ok(self.get("version").send().await?.text().await?) } + /** + * Returns the list of channels for this account. + */ + pub async fn channel_list(&self) -> Result, Box> { + let json = self.get("channel/list") + .send().await? + .text().await?; + Ok(serde_json::from_str(&json)?) + } + + /** + * Return the channel stream as json. + */ + pub async fn channel_stream(&self) -> Result> { + Ok(self.get("channel/stream").send().await?.text().await?) + } + + /** + * Return all data from channel for export. + */ + pub async fn channel_export(&self) -> Result> { + Ok(self.get("channel/export/basic").send().await?.text().await?) + } + + /// Return a RequestBuilder object that's set up with the correct /// path and headers for performing a zot api request. -- cgit v1.2.3