aboutsummaryrefslogtreecommitdiff
path: root/src/tw/tweet.rs
diff options
context:
space:
mode:
authorAndy Wortman <ixineeringeverywhere@gmail.com>2017-11-01 04:31:43 -0700
committerAndy Wortman <ixineeringeverywhere@gmail.com>2017-11-01 04:31:43 -0700
commit41f6535a480bb9b0ff085e0144852827633f2305 (patch)
treedd48118f712344d5dcea278148f3c82996f74021 /src/tw/tweet.rs
parentbf7f5d32a7f05bb0a7bc19dcb443d3df439243ba (diff)
move more logging to be through DisplayInfo statuses
move DisplayInfo into ... display flush output, duh
Diffstat (limited to 'src/tw/tweet.rs')
-rw-r--r--src/tw/tweet.rs17
1 files changed, 10 insertions, 7 deletions
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<Tweet> {
+ pub fn from_json(json: serde_json::Value) -> Result<Tweet, String> {
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())
}
}