Permalink
Browse files

Added some documentation, changed method names, added a return boolea…

…n for update
  • Loading branch information...
1 parent e4442e8 commit caf6ed7eab2b25e8631a1c79bccd13e39382698d @englishmace committed Jun 21, 2011
Showing with 13 additions and 3 deletions.
  1. +13 −3 app/models/city.rb
View
16 app/models/city.rb
@@ -3,18 +3,27 @@ class City
has_many :tweets
has_many :tweeters
- def get_tweets
+ # pulls all tweets tweeted since we last checked
+ def update_tweets
+ updated = false
+
self.tweeters.each do |tweeter|
new_tweets = Twitter.user_timeline(tweeter.user, :since_id => tweeter.latest_tweet, :trim_user => true)
+
+ if tweeter.latest_tweet != new_tweets.first.id
+ updated = true
tweeter.latest_tweet = new_tweets.first.id
tweeter.save
+
for item in new_tweets do
Tweet.new(:data => item, :city_id => self.id, :user => tweeter.id).save
end
end
+ return updated
end
- def get_init_tweets(tweeter)
+ # pulls all backdated tweets for a new tweeter; initializes their twit_id & latest
+ def init_tweets(tweeter)
all_tweets = Twitter.user_timeline(tweeter.user, :trim_user => true, :count => 200)
tweeter.latest_tweet = all_tweets.first.id
tweeter.twit_id = all_tweets.first.user.id
@@ -23,6 +32,7 @@ def get_init_tweets(tweeter)
end
end
+ # initializes a new tweeter & calls init_tweets
def add_tweeter(username)
tweeter = Tweeter.new(:user => username, :city_id => self.id)
get_init_tweets(tweeter)
@@ -33,7 +43,7 @@ def add_tweeter(username)
-
+ # test method
def get_first_tweet(tweeter)
temp = Twitter.user_timeline(tweeter.user).first
Tweet.new(:city_id => self.id, :user => tweeter.id, :data => temp).save

0 comments on commit caf6ed7

Please sign in to comment.