aboutsummaryrefslogtreecommitdiffstats
path: root/examples/hubzilla-network-stream.rs
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2018-08-19 19:32:49 +0200
committerHarald Eilertsen <haraldei@anduin.net>2018-08-19 19:32:49 +0200
commit9abac137c5282d3bd78776e9da3608c3a32cb49f (patch)
treed874eafbb19788326e4b9e7c29ddd0bce600cec1 /examples/hubzilla-network-stream.rs
parentf5bdd3f122138e6ea0a8eafedfaf900862070507 (diff)
downloadrust-zotapi-9abac137c5282d3bd78776e9da3608c3a32cb49f.tar.gz
rust-zotapi-9abac137c5282d3bd78776e9da3608c3a32cb49f.tar.bz2
rust-zotapi-9abac137c5282d3bd78776e9da3608c3a32cb49f.zip
Add method for fetching network stream.
Diffstat (limited to 'examples/hubzilla-network-stream.rs')
-rw-r--r--examples/hubzilla-network-stream.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/examples/hubzilla-network-stream.rs b/examples/hubzilla-network-stream.rs
new file mode 100644
index 0000000..29b6a28
--- /dev/null
+++ b/examples/hubzilla-network-stream.rs
@@ -0,0 +1,38 @@
+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").expect("SITE variable expected");
+ let user = env::var("USER").expect("USER variable expected");
+ let password = env::var("PASSWORD").expect("PASSWORD variable expected");
+ let client = zotapi::client(&site, &user, &password);
+
+ match client.network_stream() {
+ Ok(payload) => {
+ println!("Raw payload: {}", payload);
+
+ match serde_json::from_str(&payload) {
+ Ok(Value::Array(v)) => {
+ for item in v.into_iter() {
+ println!("{} {} {}", item["title"], item["type"], item["author"]["name"]);
+ }
+ },
+ Ok(_) => {
+ println!("Wrong type returned, expected an array.")
+ },
+ Err(e) => {
+ println!("Error: {}", e);
+ }
+ }
+ },
+ Err(e) => {
+ println!("Error getting channel stream: {:?}", e);
+ }
+ }
+}