From 96425724b0e435c33876f4dd9685aed2bbdea1fd Mon Sep 17 00:00:00 2001 From: iximeow Date: Wed, 1 Nov 2017 04:31:43 -0700 Subject: move more logging to be through DisplayInfo statuses move DisplayInfo into ... display flush output, duh --- src/tw/tweet.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/tw/tweet.rs') diff --git a/src/tw/tweet.rs b/src/tw/tweet.rs index a3fdde3..dc89774 100644 --- a/src/tw/tweet.rs +++ b/src/tw/tweet.rs @@ -38,14 +38,17 @@ impl Tweet { .collect() } - pub fn from_api_json(json: serde_json::Value) -> Option<(Tweet, User)> { + pub fn from_api_json(json: serde_json::Value) -> Result<(Tweet, User), String> { Tweet::from_json(json.clone()).and_then(|tw| { - json.get("user").and_then(|user_json| - User::from_json(user_json.to_owned()).map(|u| (tw, u)) - ) + match json.get("user") { + Some(user_json) => + User::from_json(user_json.to_owned()).map(|u| (tw, u)), + None => + Err("No user json".to_owned()) + } }) } - pub fn from_json(json: serde_json::Value) -> Option { + pub fn from_json(json: serde_json::Value) -> Result { if let serde_json::Value::Object(json_map) = json { let text = ::tw::full_twete_text(&json_map); let rt_twete = json_map.get("retweeted_status") @@ -67,7 +70,7 @@ impl Tweet { json_map["user"]["id_str"].as_str(), json_map["created_at"].as_str() ) { - return Some(Tweet { + return Ok(Tweet { id: id_str.to_owned(), author_id: author_id.to_owned(), text: text, @@ -82,6 +85,6 @@ impl Tweet { } } } - None + Err("Invalid tweet json".to_owned()) } } -- cgit v1.1