Class: Twroute::PollingSearch
- Inherits:
-
Object
- Object
- Twroute::PollingSearch
- Includes:
- Observable
- Defined in:
- lib/twroute/polling_search.rb
Instance Attribute Summary collapse
-
#since_id ⇒ Object
Returns the value of attribute since_id.
Instance Method Summary collapse
-
#initialize(user, password, post_arg_hash = {}) ⇒ PollingSearch
constructor
A new instance of PollingSearch.
- #query_string ⇒ Object
- #send_query ⇒ Object
- #start ⇒ Object
- #twitter_search_uri ⇒ Object
Constructor Details
#initialize(user, password, post_arg_hash = {}) ⇒ PollingSearch
Returns a new instance of PollingSearch.
11 12 13 14 15 |
# File 'lib/twroute/polling_search.rb', line 11 def initialize(user, password, post_arg_hash = {}) @user = user @password = password @post_arg_hash = post_arg_hash end |
Instance Attribute Details
#since_id ⇒ Object
Returns the value of attribute since_id.
9 10 11 |
# File 'lib/twroute/polling_search.rb', line 9 def since_id @since_id end |
Instance Method Details
#query_string ⇒ Object
21 22 23 24 25 26 |
# File 'lib/twroute/polling_search.rb', line 21 def query_string @post_arg_hash['since_id'] = @since_id if @since_id @post_arg_hash.keys.collect do |key| "#{key}=#{URI.escape(@post_arg_hash[key].to_s)}" end.sort_by { |x| x }.join('&') end |
#send_query ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/twroute/polling_search.rb', line 36 def send_query results = Yajl::HttpStream.get( twitter_search_uri, :symbolize_keys => true) results = results[:results] || [] results.reverse! return if results.empty? @since_id = results.last[:id] results.each do |tweet| changed notify_observers( tweet ) end end |
#start ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/twroute/polling_search.rb', line 28 def start puts twitter_search_uri.to_s loop do send_query sleep 30 end end |
#twitter_search_uri ⇒ Object
17 18 19 |
# File 'lib/twroute/polling_search.rb', line 17 def twitter_search_uri URI.parse("http://#{@user}:#{@password}@search.twitter.com/search.json?#{self.query_string}") end |