Class: Tweetable::Search
- Inherits:
-
Persistable
- Object
- Ohm::Model
- Persistable
- Tweetable::Search
- Defined in:
- lib/tweetable/search.rb
Constant Summary collapse
- SEARCH_PER_PAGE_LIMIT =
100
- SEARCH_START_PAGE =
1
Instance Method Summary collapse
- #update_all(force = false) ⇒ Object
-
#update_messages(pages = 15) ⇒ Object
Perform the search and update messages if any new exist Do up to 15 requests to collect as many historical messages as possible Because search API is different than the resto f the Twitter API this needs to be custom (i.e. cannot use xxx_from_timeline methods).
Methods inherited from Persistable
#client, #config, find_or_create, #needs_update?
Instance Method Details
#update_all(force = false) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/tweetable/search.rb', line 12 def update_all(force = false) return unless needs_update?(force) self.updated_at = Time.now.utc.to_s self.save end |
#update_messages(pages = 15) ⇒ Object
Perform the search and update messages if any new exist Do up to 15 requests to collect as many historical messages as possible Because search API is different than the resto f the Twitter API this needs to be custom (i.e. cannot use xxx_from_timeline methods)
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/tweetable/search.rb', line 22 def (pages = 15) = self..first(:order => 'DESC', :by => :message_id) since_id = .nil? ? 0 : . = [] pages.times do |page| s = search(self.query, since_id, SEARCH_PER_PAGE_LIMIT, page+1) break if s.results.nil? += s.results break if s.results.size < 99 end .each do || m = Message.find_or_create(:message_id, .id) m.update( :message_id => .id, :favorited => .favorited, :photos_parsed => '0', :links_parsed => '0', :created_at => Time.now.utc.to_s, :sent_at => .created_at, :text => .text, :from_screen_name => .from_user) # we explicitly don't include the user_id provided by search since it's bullshit: http://code.google.com/p/twitter-api/issues/detail?id=214 next if !m.valid? # create the user for this message u = User.find_or_create(:screen_name, .from_user) u.update( :user_id => .from_user_id, :profile_image_url => .profile_image_url) self. << m unless self..include?(m) end .flatten end |