blob: 6820341abdb15ec3d9928aa52edc1b488f501579 (
plain) (
tree)
|
|
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.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);
}
}
},
Err(e) => {
println!("Error getting channel stream: {:?}", e);
}
}
}
|