diff options
author | Rhenium <rhenium@rhe.jp> | 2014-02-23 00:37:08 +0900 |
---|---|---|
committer | Rhenium <rhenium@rhe.jp> | 2014-02-23 00:37:08 +0900 |
commit | 4ac6d101d90ed3dba3ee5b6db4ae605698fc02fc (patch) | |
tree | 8e050e86a5a645b6e6ed85289cabf2fd93467b8e /app/models/tweet.rb | |
parent | db2ba7a67890de9bd738cbd9a798193b3ccb5980 (diff) | |
download | aclog-4ac6d101d90ed3dba3ee5b6db4ae605698fc02fc.tar.gz |
add refresh button to tweets#show
Diffstat (limited to 'app/models/tweet.rb')
-rw-r--r-- | app/models/tweet.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/app/models/tweet.rb b/app/models/tweet.rb index 30d1370..be1df7c 100644 --- a/app/models/tweet.rb +++ b/app/models/tweet.rb @@ -101,6 +101,27 @@ class Tweet < ActiveRecord::Base end end + def self.import(id, account = nil) + account ||= Account.random + + tweet = self.from_twitter_object(account.client.status(id)) + + begin + nt = tweet + while !nt.in_reply_to && nt.in_reply_to_id + nt = self.from_twitter_object(account.client.status(nt.in_reply_to_id)) + end + rescue Twitter::Error + Rails.logger.warn($!) + return tweet + end + + tweet.reload + rescue Twitter::Error + Rails.logger.warn($!) + return nil + end + def self.filter_by_query(query) strings = [] query.gsub!(/"((?:\\"|[^"])*?)"/) {|m| strings << $1; "##{strings.size - 1}" } |