From 035fb7fd9ed8528a8076730f0aeab025fbc29f12 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Tue, 7 Aug 2018 23:56:13 +0200 Subject: Add example of using the channel stream api. --- Cargo.toml | 2 ++ examples/hubzilla-channel-stream.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 examples/hubzilla-channel-stream.rs 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..."); + } + } +} -- cgit v1.2.3