aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wortman <ixineeringeverywhere@gmail.com>2017-10-16 23:23:42 -0700
committerAndy Wortman <ixineeringeverywhere@gmail.com>2017-10-16 23:23:42 -0700
commitf7ff23e6ac9b1e43e40da57302ad88768156d780 (patch)
tree8ac8a2949de1182a534b4e48cfb49d1736d733dc
parente6a43f3d79ded5d284c42239cca77214f177f63e (diff)
fix use of extended tweet mode after twitter api changes
extended mode now puts text in full_text, not in extended_tweet, an inner object
-rw-r--r--src/tw/mod.rs32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/tw/mod.rs b/src/tw/mod.rs
index eff38e7..9433e45 100644
--- a/src/tw/mod.rs
+++ b/src/tw/mod.rs
@@ -27,9 +27,35 @@ pub fn full_twete_text(twete: &serde_json::map::Map<String, serde_json::Value>)
}
let mut twete_text: String;
twete_text = if twete["truncated"].as_bool().unwrap() {
- twete["extended_tweet"]["full_text"].as_str().unwrap().to_string()
+ let extended = twete.get("extended_tweet");
+ match extended {
+ Some(extended_tweet) => {
+ let full_text = extended_tweet.get("full_text");
+ match full_text {
+ Some(text) => {
+ return text.as_str().unwrap().to_string()
+ }
+ None => {
+ println!("Missing extended_tweet text. Full extended_tweet json: {:?}", full_text);
+ }
+ }
+ },
+ None => {
+ println!("Missing extended text. Full tweet json: {:?}", twete);
+ }
+ }
+ panic!("API bug? changed?");
} else {
- twete["text"].as_str().unwrap().to_string()
+ match twete.get("text") {
+ Some(text) => text.as_str().unwrap().to_string(),
+ None => {
+ // fall back to it maybe being at full_text...
+ match twete.get("full_text") {
+ Some(text) => text.as_str().unwrap().to_string(),
+ None => panic!("api bug? text not present? text: {:?}", twete)
+ }
+ }
+ }
};
let quoted_tweet_id = twete.get("quoted_tweet_id_str").and_then(|x| x.as_str());
@@ -346,7 +372,7 @@ impl TwitterCache {
}
fn look_up_tweet(&mut self, id: &str, queryer: &mut ::Queryer) -> Option<serde_json::Value> {
- let url = &format!("{}?id={}", ::TWEET_LOOKUP_URL, id);
+ let url = &format!("{}&id={}", ::TWEET_LOOKUP_URL, id);
queryer.do_api_get(url)
}