aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2023-04-01 20:28:27 +0200
committerHarald Eilertsen <haraldei@anduin.net>2023-04-01 20:28:27 +0200
commitd9375da4ebf466b6cbcac3b919b7226f0617a9c7 (patch)
treecb07c2dd798c7a34ac6daf62fd64382cc6548230
parentcca150aff45557c5149a12638cf9da7cc4e028b5 (diff)
downloadrust-zotapi-d9375da4ebf466b6cbcac3b919b7226f0617a9c7.tar.gz
rust-zotapi-d9375da4ebf466b6cbcac3b919b7226f0617a9c7.tar.bz2
rust-zotapi-d9375da4ebf466b6cbcac3b919b7226f0617a9c7.zip
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.
-rw-r--r--src/bin/zot/main.rs35
-rw-r--r--src/zotapi.rs25
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<Vec<String>, Box<dyn std::error::Error>> {
+ 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<String, Box<dyn std::error::Error>> {
+ Ok(self.get("channel/stream").send().await?.text().await?)
+ }
+
+ /**
+ * Return all data from channel for export.
+ */
+ pub async fn channel_export(&self) -> Result<String, Box<dyn std::error::Error>> {
+ 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.