From 75dcb1e9dc2c554e7193daeb1a84157fbcd8603d Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sun, 28 Oct 2018 22:12:17 +0100 Subject: Move zot cli example modules into submodule. Also rename example from zot to zotcli to avoid name clash. --- examples/abook.rs | 52 ------------------- examples/channel_stream.rs | 109 ---------------------------------------- examples/network_stream.rs | 109 ---------------------------------------- examples/xchan.rs | 41 --------------- examples/zot.rs | 111 ----------------------------------------- examples/zot/abook.rs | 52 +++++++++++++++++++ examples/zot/channel_stream.rs | 109 ++++++++++++++++++++++++++++++++++++++++ examples/zot/mod.rs | 4 ++ examples/zot/network_stream.rs | 109 ++++++++++++++++++++++++++++++++++++++++ examples/zot/xchan.rs | 41 +++++++++++++++ examples/zotcli.rs | 108 +++++++++++++++++++++++++++++++++++++++ 11 files changed, 423 insertions(+), 422 deletions(-) delete mode 100644 examples/abook.rs delete mode 100644 examples/channel_stream.rs delete mode 100644 examples/network_stream.rs delete mode 100644 examples/xchan.rs delete mode 100644 examples/zot.rs create mode 100644 examples/zot/abook.rs create mode 100644 examples/zot/channel_stream.rs create mode 100644 examples/zot/mod.rs create mode 100644 examples/zot/network_stream.rs create mode 100644 examples/zot/xchan.rs create mode 100644 examples/zotcli.rs diff --git a/examples/abook.rs b/examples/abook.rs deleted file mode 100644 index bceaacc..0000000 --- a/examples/abook.rs +++ /dev/null @@ -1,52 +0,0 @@ -/* Example Zot API command line utility, part of zotapi. - * Copyright (C) 2018 Harald Eilertsen - * - * 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 . - */ - -extern crate zotapi; -extern crate serde_json; - -pub fn fetch(client: &zotapi::Client, raw: bool) { - match client.abook().fetch() { - Ok(payload) => { - if raw { - println!("{}", &payload); - } - else { - process(&payload); - } - }, - Err(e) => { - println!("{:?}", e); - } - } -} - -fn process(payload: &str) { - let data: serde_json::Value = serde_json::from_str(&payload).unwrap(); - match data { - serde_json::Value::Array(v) => { - for contact in v { - println!("{} ({}, {})", - contact["xchan_name"], - contact["xchan_addr"], - contact["xchan_network"]); - } - }, - _ => { - println!("Unexpected data:\n{}", payload); - } - }; -} diff --git a/examples/channel_stream.rs b/examples/channel_stream.rs deleted file mode 100644 index a278244..0000000 --- a/examples/channel_stream.rs +++ /dev/null @@ -1,109 +0,0 @@ -/* Example Zot API command line utility, part of zotapi. - * Copyright (C) 2018 Harald Eilertsen - * - * 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 . - */ - -use zotapi; - -use serde_json; -use std::iter::Iterator; - -pub fn fetch(client: &zotapi::Client, raw: bool) { - match client.channel_stream() { - Ok(payload) => { - if raw { - println!("{}", payload); - } - else { - list(&payload); - } - }, - Err(e) => { - println!("Error getting channel stream: {:?}", e); - } - } -} - -fn list(payload: &str) { - match serde_json::from_str(&payload) { - Ok(serde_json::Value::Array(v)) => { - for item in v.into_iter() { - print_item(&item); - println!("-----"); - } - }, - Ok(_) => { - println!("Wrong type returned, expected an array.") - }, - Err(e) => { - println!("Error: {}", e); - } - } -} - -fn get_str(v: &serde_json::Value) -> &str { - v.as_str().unwrap_or("") -} - -fn get_verb(item: &serde_json::Value) -> &str { - match get_str(&item["verb"]).split("/").last() { - Some("post") => "posted", - Some("like") => "liked", - Some("share") => "shared", - Some("dislike") => "disliked", - _ => "unknown verb", - } -} - -fn get_object_type(item: &serde_json::Value) -> &str { - get_str(&item["object_type"]) - .split("/") - .last() - .unwrap_or("unknown object") -} - -fn get_tags(item: &serde_json::Value) -> String { - match item["tags"] { - serde_json::Value::Array(ref v) => { - v.iter().map(|t| { - let prefix = match get_str(&t["type"]) { - "hashtag" => "#", - "forum" => "!", - "mention" => "@", - _ => "", - }; - format!("{}{}", prefix, get_str(&t["tag"])) - }).collect::>().join(", ") - }, - serde_json::Value::Null => { - String::new() - }, - _ => { - String::from("invalid tags, expected array...") - } - } -} - -fn print_item(item: &serde_json::Value) { - let author = &item["author"]; - print!("{} ", get_str(&item["created"])); - print!("{} ", get_str(&author["name"])); - println!("{} a {}", get_verb(&item), get_object_type(&item)); - println!("URL: {}", get_str(&author["url"])); - println!("Proto: {}", get_str(&author["network"])); - println!("Title: {}", get_str(&item["title"])); - println!("Tags : {}", get_tags(&item)); - println!("Message:\n{}", get_str(&item["body"])); -} diff --git a/examples/network_stream.rs b/examples/network_stream.rs deleted file mode 100644 index de3b12f..0000000 --- a/examples/network_stream.rs +++ /dev/null @@ -1,109 +0,0 @@ -/* Example Zot API command line utility, part of zotapi. - * Copyright (C) 2018 Harald Eilertsen - * - * 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 . - */ - -use zotapi; - -use serde_json; -use std::iter::Iterator; - -pub fn fetch(client: &zotapi::Client, raw: bool) { - match client.network_stream() { - Ok(payload) => { - if raw { - println!("{}", payload); - } - else { - list(&payload); - } - }, - Err(e) => { - println!("Error getting channel stream: {:?}", e); - } - } -} - -fn list(payload: &str) { - match serde_json::from_str(&payload) { - Ok(serde_json::Value::Array(v)) => { - for item in v.into_iter() { - print_item(&item); - println!("-----"); - } - }, - Ok(_) => { - println!("Wrong type returned, expected an array.") - }, - Err(e) => { - println!("Error: {}", e); - } - } -} - -fn get_str(v: &serde_json::Value) -> &str { - v.as_str().unwrap_or("") -} - -fn get_verb(item: &serde_json::Value) -> &str { - match get_str(&item["verb"]).split("/").last() { - Some("post") => "posted", - Some("like") => "liked", - Some("share") => "shared", - Some("dislike") => "disliked", - _ => "unknown verb", - } -} - -fn get_object_type(item: &serde_json::Value) -> &str { - get_str(&item["object_type"]) - .split("/") - .last() - .unwrap_or("unknown object") -} - -fn get_tags(item: &serde_json::Value) -> String { - match item["tags"] { - serde_json::Value::Array(ref v) => { - v.iter().map(|t| { - let prefix = match get_str(&t["type"]) { - "hashtag" => "#", - "forum" => "!", - "mention" => "@", - _ => "", - }; - format!("{}{}", prefix, get_str(&t["tag"])) - }).collect::>().join(", ") - }, - serde_json::Value::Null => { - String::new() - }, - _ => { - String::from("invalid tags, expected array...") - } - } -} - -fn print_item(item: &serde_json::Value) { - let author = &item["author"]; - print!("{} ", get_str(&item["created"])); - print!("{} ", get_str(&author["name"])); - println!("{} a {}", get_verb(&item), get_object_type(&item)); - println!("URL: {}", get_str(&author["url"])); - println!("Proto: {}", get_str(&author["network"])); - println!("Title: {}", get_str(&item["title"])); - println!("Tags : {}", get_tags(&item)); - println!("Message:\n{}", get_str(&item["body"])); -} diff --git a/examples/xchan.rs b/examples/xchan.rs deleted file mode 100644 index d37328d..0000000 --- a/examples/xchan.rs +++ /dev/null @@ -1,41 +0,0 @@ -/* Example Zot API command line utility, part of zotapi. - * Copyright (C) 2018 - * - * 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 . - */ - -use zotapi; - -pub enum Type { - Addr, - Hash, - GUID, -} - -pub fn fetch(client: &zotapi::Client, _raw: bool, t: Type, id: &str) { - let res = match t { - Type::Addr => client.xchan().by_address(&id).fetch(), - Type::Hash => client.xchan().by_hash(&id).fetch(), - Type::GUID => client.xchan().by_guid(&id).fetch(), - }; - - match res { - Ok(payload) => { - println!("{}", payload); - }, - Err(e) => { - println!("{:?}", e); - } - } -} diff --git a/examples/zot.rs b/examples/zot.rs deleted file mode 100644 index 3ad9bf0..0000000 --- a/examples/zot.rs +++ /dev/null @@ -1,111 +0,0 @@ -/* Example Zot API command line utility, part of zotapi. - * Copyright (C) 2018 Harald Eilertsen - * - * 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 . - */ - -extern crate zotapi; -extern crate dotenv; -#[macro_use] -extern crate clap; -extern crate serde_json; - -use clap::{Arg, SubCommand}; -use dotenv::dotenv; -use std::env; - -mod abook; -mod channel_stream; -mod network_stream; -mod xchan; - -fn main() { - dotenv().ok(); - let site = env::var("HZ_SITE").expect("SITE variable expected"); - let user = env::var("HZ_USER").expect("USER variable expected"); - let password = env::var("HZ_PASSWORD").expect("PASSWORD variable expected"); - - let matches = app_from_crate!() - .subcommand( - SubCommand::with_name("channel-stream") - .about("Fetch the channel stream") - .arg(Arg::with_name("raw") - .long("raw") - .help("Display raw json payload"))) - .subcommand( - SubCommand::with_name("network-stream") - .about("Fetch the network stream") - .arg(Arg::with_name("raw") - .long("raw") - .help("Display raw json payload"))) - .subcommand( - SubCommand::with_name("abook") - .about("Fetch address book/contact info") - .arg(Arg::with_name("raw") - .long("raw") - .help("Display raw json payload"))) - .subcommand( - SubCommand::with_name("xchan") - .about("Fetch xchan info") - .arg(Arg::with_name("raw") - .long("raw") - .help("Display raw json payload")) - .arg(Arg::with_name("addr") - .long("addr") - .help("ID is given as a webbie address (default)")) - .arg(Arg::with_name("hash") - .long("hash") - .help("ID is given as a xchan hash")) - .arg(Arg::with_name("guid") - .long("guid") - .help("ID is given as a GUID")) - .arg(Arg::with_name("ID") - .help("id (email, hash or GUID) of xchan to fetch") - .required(true))) - .get_matches(); - - let client = zotapi::client(&site, &user, &password); - - match matches.subcommand() { - ("channel-stream", Some(m)) => { - let raw = m.is_present("raw"); - channel_stream::fetch(&client, raw); - }, - ("network-stream", Some(m)) => { - let raw = m.is_present("raw"); - network_stream::fetch(&client, raw); - }, - ("abook", Some(m)) => { - let raw = m.is_present("raw"); - abook::fetch(&client, raw); - }, - ("xchan", Some(m)) => { - let raw = m.is_present("raw"); - let t = if m.is_present("guid") { - xchan::Type::GUID - } - else if m.is_present("hash") { - xchan::Type::Hash - } - else { - xchan::Type::Addr - }; - - xchan::fetch(&client, raw, t, m.value_of("ID").unwrap()); - }, - _ => { - println!("{}", matches.usage()); - }, - } -} diff --git a/examples/zot/abook.rs b/examples/zot/abook.rs new file mode 100644 index 0000000..bceaacc --- /dev/null +++ b/examples/zot/abook.rs @@ -0,0 +1,52 @@ +/* Example Zot API command line utility, part of zotapi. + * Copyright (C) 2018 Harald Eilertsen + * + * 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 . + */ + +extern crate zotapi; +extern crate serde_json; + +pub fn fetch(client: &zotapi::Client, raw: bool) { + match client.abook().fetch() { + Ok(payload) => { + if raw { + println!("{}", &payload); + } + else { + process(&payload); + } + }, + Err(e) => { + println!("{:?}", e); + } + } +} + +fn process(payload: &str) { + let data: serde_json::Value = serde_json::from_str(&payload).unwrap(); + match data { + serde_json::Value::Array(v) => { + for contact in v { + println!("{} ({}, {})", + contact["xchan_name"], + contact["xchan_addr"], + contact["xchan_network"]); + } + }, + _ => { + println!("Unexpected data:\n{}", payload); + } + }; +} diff --git a/examples/zot/channel_stream.rs b/examples/zot/channel_stream.rs new file mode 100644 index 0000000..a278244 --- /dev/null +++ b/examples/zot/channel_stream.rs @@ -0,0 +1,109 @@ +/* Example Zot API command line utility, part of zotapi. + * Copyright (C) 2018 Harald Eilertsen + * + * 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 . + */ + +use zotapi; + +use serde_json; +use std::iter::Iterator; + +pub fn fetch(client: &zotapi::Client, raw: bool) { + match client.channel_stream() { + Ok(payload) => { + if raw { + println!("{}", payload); + } + else { + list(&payload); + } + }, + Err(e) => { + println!("Error getting channel stream: {:?}", e); + } + } +} + +fn list(payload: &str) { + match serde_json::from_str(&payload) { + Ok(serde_json::Value::Array(v)) => { + for item in v.into_iter() { + print_item(&item); + println!("-----"); + } + }, + Ok(_) => { + println!("Wrong type returned, expected an array.") + }, + Err(e) => { + println!("Error: {}", e); + } + } +} + +fn get_str(v: &serde_json::Value) -> &str { + v.as_str().unwrap_or("") +} + +fn get_verb(item: &serde_json::Value) -> &str { + match get_str(&item["verb"]).split("/").last() { + Some("post") => "posted", + Some("like") => "liked", + Some("share") => "shared", + Some("dislike") => "disliked", + _ => "unknown verb", + } +} + +fn get_object_type(item: &serde_json::Value) -> &str { + get_str(&item["object_type"]) + .split("/") + .last() + .unwrap_or("unknown object") +} + +fn get_tags(item: &serde_json::Value) -> String { + match item["tags"] { + serde_json::Value::Array(ref v) => { + v.iter().map(|t| { + let prefix = match get_str(&t["type"]) { + "hashtag" => "#", + "forum" => "!", + "mention" => "@", + _ => "", + }; + format!("{}{}", prefix, get_str(&t["tag"])) + }).collect::>().join(", ") + }, + serde_json::Value::Null => { + String::new() + }, + _ => { + String::from("invalid tags, expected array...") + } + } +} + +fn print_item(item: &serde_json::Value) { + let author = &item["author"]; + print!("{} ", get_str(&item["created"])); + print!("{} ", get_str(&author["name"])); + println!("{} a {}", get_verb(&item), get_object_type(&item)); + println!("URL: {}", get_str(&author["url"])); + println!("Proto: {}", get_str(&author["network"])); + println!("Title: {}", get_str(&item["title"])); + println!("Tags : {}", get_tags(&item)); + println!("Message:\n{}", get_str(&item["body"])); +} diff --git a/examples/zot/mod.rs b/examples/zot/mod.rs new file mode 100644 index 0000000..089a4cb --- /dev/null +++ b/examples/zot/mod.rs @@ -0,0 +1,4 @@ +pub mod abook; +pub mod channel_stream; +pub mod network_stream; +pub mod xchan; diff --git a/examples/zot/network_stream.rs b/examples/zot/network_stream.rs new file mode 100644 index 0000000..de3b12f --- /dev/null +++ b/examples/zot/network_stream.rs @@ -0,0 +1,109 @@ +/* Example Zot API command line utility, part of zotapi. + * Copyright (C) 2018 Harald Eilertsen + * + * 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 . + */ + +use zotapi; + +use serde_json; +use std::iter::Iterator; + +pub fn fetch(client: &zotapi::Client, raw: bool) { + match client.network_stream() { + Ok(payload) => { + if raw { + println!("{}", payload); + } + else { + list(&payload); + } + }, + Err(e) => { + println!("Error getting channel stream: {:?}", e); + } + } +} + +fn list(payload: &str) { + match serde_json::from_str(&payload) { + Ok(serde_json::Value::Array(v)) => { + for item in v.into_iter() { + print_item(&item); + println!("-----"); + } + }, + Ok(_) => { + println!("Wrong type returned, expected an array.") + }, + Err(e) => { + println!("Error: {}", e); + } + } +} + +fn get_str(v: &serde_json::Value) -> &str { + v.as_str().unwrap_or("") +} + +fn get_verb(item: &serde_json::Value) -> &str { + match get_str(&item["verb"]).split("/").last() { + Some("post") => "posted", + Some("like") => "liked", + Some("share") => "shared", + Some("dislike") => "disliked", + _ => "unknown verb", + } +} + +fn get_object_type(item: &serde_json::Value) -> &str { + get_str(&item["object_type"]) + .split("/") + .last() + .unwrap_or("unknown object") +} + +fn get_tags(item: &serde_json::Value) -> String { + match item["tags"] { + serde_json::Value::Array(ref v) => { + v.iter().map(|t| { + let prefix = match get_str(&t["type"]) { + "hashtag" => "#", + "forum" => "!", + "mention" => "@", + _ => "", + }; + format!("{}{}", prefix, get_str(&t["tag"])) + }).collect::>().join(", ") + }, + serde_json::Value::Null => { + String::new() + }, + _ => { + String::from("invalid tags, expected array...") + } + } +} + +fn print_item(item: &serde_json::Value) { + let author = &item["author"]; + print!("{} ", get_str(&item["created"])); + print!("{} ", get_str(&author["name"])); + println!("{} a {}", get_verb(&item), get_object_type(&item)); + println!("URL: {}", get_str(&author["url"])); + println!("Proto: {}", get_str(&author["network"])); + println!("Title: {}", get_str(&item["title"])); + println!("Tags : {}", get_tags(&item)); + println!("Message:\n{}", get_str(&item["body"])); +} diff --git a/examples/zot/xchan.rs b/examples/zot/xchan.rs new file mode 100644 index 0000000..d37328d --- /dev/null +++ b/examples/zot/xchan.rs @@ -0,0 +1,41 @@ +/* Example Zot API command line utility, part of zotapi. + * Copyright (C) 2018 + * + * 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 . + */ + +use zotapi; + +pub enum Type { + Addr, + Hash, + GUID, +} + +pub fn fetch(client: &zotapi::Client, _raw: bool, t: Type, id: &str) { + let res = match t { + Type::Addr => client.xchan().by_address(&id).fetch(), + Type::Hash => client.xchan().by_hash(&id).fetch(), + Type::GUID => client.xchan().by_guid(&id).fetch(), + }; + + match res { + Ok(payload) => { + println!("{}", payload); + }, + Err(e) => { + println!("{:?}", e); + } + } +} diff --git a/examples/zotcli.rs b/examples/zotcli.rs new file mode 100644 index 0000000..2804754 --- /dev/null +++ b/examples/zotcli.rs @@ -0,0 +1,108 @@ +/* Example Zot API command line utility, part of zotapi. + * Copyright (C) 2018 Harald Eilertsen + * + * 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 . + */ + +extern crate zotapi; +extern crate dotenv; +#[macro_use] +extern crate clap; +extern crate serde_json; + +use clap::{Arg, SubCommand}; +use dotenv::dotenv; +use std::env; + +mod zot; + +fn main() { + dotenv().ok(); + let site = env::var("HZ_SITE").expect("SITE variable expected"); + let user = env::var("HZ_USER").expect("USER variable expected"); + let password = env::var("HZ_PASSWORD").expect("PASSWORD variable expected"); + + let matches = app_from_crate!() + .subcommand( + SubCommand::with_name("channel-stream") + .about("Fetch the channel stream") + .arg(Arg::with_name("raw") + .long("raw") + .help("Display raw json payload"))) + .subcommand( + SubCommand::with_name("network-stream") + .about("Fetch the network stream") + .arg(Arg::with_name("raw") + .long("raw") + .help("Display raw json payload"))) + .subcommand( + SubCommand::with_name("abook") + .about("Fetch address book/contact info") + .arg(Arg::with_name("raw") + .long("raw") + .help("Display raw json payload"))) + .subcommand( + SubCommand::with_name("xchan") + .about("Fetch xchan info") + .arg(Arg::with_name("raw") + .long("raw") + .help("Display raw json payload")) + .arg(Arg::with_name("addr") + .long("addr") + .help("ID is given as a webbie address (default)")) + .arg(Arg::with_name("hash") + .long("hash") + .help("ID is given as a xchan hash")) + .arg(Arg::with_name("guid") + .long("guid") + .help("ID is given as a GUID")) + .arg(Arg::with_name("ID") + .help("id (email, hash or GUID) of xchan to fetch") + .required(true))) + .get_matches(); + + let client = zotapi::client(&site, &user, &password); + + match matches.subcommand() { + ("channel-stream", Some(m)) => { + let raw = m.is_present("raw"); + zot::channel_stream::fetch(&client, raw); + }, + ("network-stream", Some(m)) => { + let raw = m.is_present("raw"); + zot::network_stream::fetch(&client, raw); + }, + ("abook", Some(m)) => { + let raw = m.is_present("raw"); + zot::abook::fetch(&client, raw); + }, + ("xchan", Some(m)) => { + let raw = m.is_present("raw"); + let t = if m.is_present("guid") { + zot::xchan::Type::GUID + } + else if m.is_present("hash") { + zot::xchan::Type::Hash + } + else { + zot::xchan::Type::Addr + }; + + zot::xchan::fetch(&client, raw, t, m.value_of("ID").unwrap()); + }, + _ => { + println!("{}", matches.usage()); + }, + } +} -- cgit v1.2.3