aboutsummaryrefslogtreecommitdiff
path: root/src/tw
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2017-10-25 04:07:32 -0700
committeriximeow <me@iximeow.net>2017-10-25 04:07:32 -0700
commit4a8d9db54cff6b45cb44712d851de0cbb3da37bf (patch)
tree8bb44e53dab2a9b5f94284ca0f390061032eb4f1 /src/tw
parent7f71f824801950b11ff6dcab9eb45549fbe4dce6 (diff)
begin removing unwrap()
Diffstat (limited to 'src/tw')
-rw-r--r--src/tw/mod.rs32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/tw/mod.rs b/src/tw/mod.rs
index 0341ec9..5f40c5e 100644
--- a/src/tw/mod.rs
+++ b/src/tw/mod.rs
@@ -232,7 +232,7 @@ impl Default for DisplayInfo {
}
impl DisplayInfo {
- fn status(&mut self, stat: String) {
+ pub fn status(&mut self, stat: String) {
self.log.push(stat);
}
@@ -501,14 +501,30 @@ impl TwitterCache {
pub fn retrieve_user(&self, user_id: &String) -> Option<&User> {
self.users.get(user_id)
}
- pub fn fetch_tweet(&mut self, tweet_id: &String, mut queryer: &mut ::Queryer) -> Option<&Tweet> {
- if !self.tweets.contains_key(tweet_id) {
- match self.look_up_tweet(tweet_id, &mut queryer) {
- Some(json) => self.cache_api_tweet(json),
- None => self.display_info.status(format!("Unable to retrieve tweet {}", tweet_id))
- };
+ pub fn fetch_tweet(&mut self, tweet_id: &TweetId, mut queryer: &mut ::Queryer) -> Option<&Tweet> {
+ match tweet_id {
+ &TweetId::Bare(ref id) => {
+ // we can do nothing but just try to get it
+ self.retrieve_tweet(tweet_id)
+ }
+ &TweetId::Today(ref id) => {
+ // we can do nothing but just try to get it
+ self.retrieve_tweet(tweet_id)
+ },
+ &TweetId::Dated(ref date, ref id) => {
+ // we can do nothing but just try to get it
+ self.retrieve_tweet(tweet_id)
+ },
+ &TweetId::Twitter(ref id) => {
+ if !self.tweets.contains_key(id) {
+ match self.look_up_tweet(id, &mut queryer) {
+ Some(json) => self.cache_api_tweet(json),
+ None => self.display_info.status(format!("Unable to retrieve tweet {}", id))
+ };
+ }
+ self.retrieve_tweet(tweet_id)
+ }
}
- self.tweets.get(tweet_id)
}
pub fn fetch_user(&mut self, user_id: &String, mut queryer: &mut ::Queryer) -> Option<&User> {
if !self.users.contains_key(user_id) {