diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/hubzilla-channel-stream.rs | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/examples/hubzilla-channel-stream.rs b/examples/hubzilla-channel-stream.rs index f0cab19..6820341 100644 --- a/examples/hubzilla-channel-stream.rs +++ b/examples/hubzilla-channel-stream.rs @@ -8,19 +8,31 @@ 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 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 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"]); + match client.channel_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); + } } }, - _ => { - println!("Expected an array, really..."); + Err(e) => { + println!("Error getting channel stream: {:?}", e); } } } |