aboutsummaryrefslogtreecommitdiff
path: root/src/tw
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2017-10-16 23:23:42 -0700
committeriximeow <me@iximeow.net>2017-10-16 23:23:42 -0700
commit8609668e319db209120a0e0e144fbb0b9ad4be8b (patch)
tree8ac8a2949de1182a534b4e48cfb49d1736d733dc /src/tw
parentf272a41cf8c4a550e3a4352c478579974a5f4d91 (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
Diffstat (limited to 'src/tw')
-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)
}