diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/hubzilla-network-stream.rs | 38 |
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); + } + } +} |