aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2018-08-07 23:56:13 +0200
committerHarald Eilertsen <haraldei@anduin.net>2018-08-07 23:56:13 +0200
commit035fb7fd9ed8528a8076730f0aeab025fbc29f12 (patch)
tree60574fc55ec1c8bc76c805ee81aafe00f29a5df4
parent2a05b5a40a822f52ffcd1377aad9285d15da4d9f (diff)
downloadrust-zotapi-035fb7fd9ed8528a8076730f0aeab025fbc29f12.tar.gz
rust-zotapi-035fb7fd9ed8528a8076730f0aeab025fbc29f12.tar.bz2
rust-zotapi-035fb7fd9ed8528a8076730f0aeab025fbc29f12.zip
Add example of using the channel stream api.
-rw-r--r--Cargo.toml2
-rw-r--r--examples/hubzilla-channel-stream.rs26
2 files changed, 28 insertions, 0 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 1c2f542..88e8ba7 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,4 +7,6 @@ authors = ["haraldei"]
reqwest = "0.8"
[dev-dependencies]
+dotenv = "0.13"
mockito = "0.12"
+serde_json = "1.0"
diff --git a/examples/hubzilla-channel-stream.rs b/examples/hubzilla-channel-stream.rs
new file mode 100644
index 0000000..f0cab19
--- /dev/null
+++ b/examples/hubzilla-channel-stream.rs
@@ -0,0 +1,26 @@
+extern crate zotapi;
+extern crate dotenv;
+extern crate serde_json;
+
+use dotenv::dotenv;
+use serde_json::Value;
+use std::env;
+
+fn main() {
+ dotenv().ok();
+ let site = env::var("SITE").unwrap();
+ let user = env::var("USER").unwrap();
+ let password = env::var("PASSWORD").unwrap();
+ let client = zotapi::client(&site, &user, &password);
+
+ match serde_json::from_str(&client.channel_stream()).unwrap() {
+ Value::Array(v) => {
+ for item in v.into_iter() {
+ println!("{} {} {}", item["title"], item["type"], item["author"]["name"]);
+ }
+ },
+ _ => {
+ println!("Expected an array, really...");
+ }
+ }
+}