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
- #grack_to_hash(grack) ⇒ Object
-
#initialize(user, password, post_arg_hash = {}) ⇒ PollingSearch
constructor
A new instance of PollingSearch.
- #query_hash ⇒ Object
- #send_query ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(user, password, post_arg_hash = {}) ⇒ PollingSearch
Returns a new instance of PollingSearch.
10 11 12 13 14 15 |
# File 'lib/twroute/polling_search.rb', line 10 def initialize(user, password, post_arg_hash = {}) @user = user @password = password @post_arg_hash = post_arg_hash @grackle_client = Grackle::Client.new(:auth=>{:type=>:basic,:username=>@user,:password=>@password}) end |
Instance Attribute Details
#since_id ⇒ Object
Returns the value of attribute since_id.
8 9 10 |
# File 'lib/twroute/polling_search.rb', line 8 def since_id @since_id end |
Instance Method Details
#grack_to_hash(grack) ⇒ Object
22 23 24 25 26 |
# File 'lib/twroute/polling_search.rb', line 22 def grack_to_hash(grack) res = grack.marshal_dump res[:id] = grack.id res end |
#query_hash ⇒ Object
17 18 19 20 |
# File 'lib/twroute/polling_search.rb', line 17 def query_hash @post_arg_hash['since_id'] = @since_id if @since_id @post_arg_hash end |
#send_query ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/twroute/polling_search.rb', line 35 def send_query results = @grackle_client[:search].search? query_hash results = results.results || [] results.reverse! return if results.empty? @since_id = results.last.id results.each do |tweet| changed notify_observers( grack_to_hash tweet ) end end |
#start ⇒ Object
28 29 30 31 32 33 |
# File 'lib/twroute/polling_search.rb', line 28 def start loop do send_query sleep 30 end end |