Skip to content

Commit

Permalink
remove rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sahil Shah committed Dec 6, 2011
1 parent 6ae7953 commit 16900ee
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions app/models/tweet.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
class Tweet < ActiveRecord::Base

def self.check_for_new_tweets
response = "NO"
last_tweet = self.first || self.create!(:tweet_id => "144138727650889728", :last_check_at => 1.day.ago)
unless last_tweet.last_check_at > 1.minute.ago
tweets = JSON.parse(
Tweet.access_token.request(
:get,
"https://api.twitter.com/1/statuses/mentions.json?trim_user=t"
).body
)
new_last_check_time = Time.now.utc
new_max_tweet_id = tweets.map { |tweet| tweet["id_str"] }.max
if tweets.select { |tweet|
tweet["id_str"] > last_tweet.tweet_id
}.any? { |tweet|
tweet["text"].match(/^.*(love|<3).*$/im)
}
response = "YES"
end
last_tweet.update_attributes(:tweet_id => new_max_tweet_id, :last_check_at => new_last_check_time)
response = "NO"
last_tweet = self.first || self.create!(:tweet_id => "144138727650889728", :last_check_at => 1.day.ago)
tweets = JSON.parse(
Tweet.access_token.request(
:get,
"https://api.twitter.com/1/statuses/mentions.json?trim_user=t"
).body
)
new_last_check_time = Time.now.utc
new_max_tweet_id = tweets.map { |tweet| tweet["id_str"] }.max
if tweets.select { |tweet|
tweet["id_str"] > last_tweet.tweet_id
}.any? { |tweet|
tweet["text"].match(/^.*(love|<3).*$/im)
}
response = "YES"
end
last_tweet.update_attributes(:tweet_id => new_max_tweet_id, :last_check_at => new_last_check_time)
response
end

Expand Down

0 comments on commit 16900ee

Please sign in to comment.