diff --git a/examples/reader.rb b/examples/reader.rb index b168b9c..0247bda 100644 --- a/examples/reader.rb +++ b/examples/reader.rb @@ -9,7 +9,11 @@ :path => '/1/statuses/filter.json', :auth => 'LOGIN:PASSWORD', :method => 'POST', - :content => 'track=basketball,football,baseball,footy,soccer' + :params => { + :track => 'basketball,football,baseball,footy,soccer', + :locations => '-122.75,36.8,-121.75,37.8,-74,40,-73,41', + :follow => '12,13,15,16,20,87' + } ) stream.each_item do |item| diff --git a/lib/twitter/json_stream.rb b/lib/twitter/json_stream.rb index 27f4b4d..0e26699 100644 --- a/lib/twitter/json_stream.rb +++ b/lib/twitter/json_stream.rb @@ -26,7 +26,6 @@ class JSONStream < EventMachine::Connection :method => 'GET', :path => '/', :content_type => "application/x-www-form-urlencoded", - :content => '', :path => '/1/statuses/filter.json', :host => 'stream.twitter.com', :port => 443, @@ -36,7 +35,6 @@ class JSONStream < EventMachine::Connection :proxy => ENV['HTTP_PROXY'], :auth => nil, :oauth => {}, - :filters => [], :params => {}, :auto_reconnect => true } @@ -90,8 +88,6 @@ def on_reconnect &block @reconnect_callback = block end - # Called when no data has been received for NO_DATA_TIMEOUT seconds. - # Reconnecting is probably in order as per the Twitter recommendations def on_no_data &block @no_data_callback = block end @@ -127,7 +123,7 @@ def unbind # Receives raw data from the HTTP connection and pushes it into the # HTTP parser which then drives subsequent callbacks. def receive_data(data) - @last_data_received_at = Time.now + @last_data_received_at = Time.now if !data.strip.empty? @parser << data end @@ -246,7 +242,7 @@ def send_request request_uri = "#{uri_base}:#{@options[:port]}#{request_uri}" end - content = @options[:content] + content = '' unless (q = query).empty? if @options[:method].to_s.upcase == 'GET' @@ -346,13 +342,7 @@ def uri_base # Normalized query hash of escaped string keys and escaped string values # nil values are skipped def params - flat = {} - @options[:params].merge( :track => @options[:filters] ).each do |param, val| - next if val.to_s.empty? || (val.respond_to?(:empty?) && val.empty?) - val = val.join(",") if val.respond_to?(:join) - flat[param.to_s] = val.to_s - end - flat + @options[:params] end def query @@ -360,7 +350,7 @@ def query end def escape str - URI.escape(str.to_s, /[^a-zA-Z0-9\-\.\_\~]/) + URI.escape(str.to_s) end end end diff --git a/spec/twitter/json_stream_spec.rb b/spec/twitter/json_stream_spec.rb index bc66a32..c353221 100644 --- a/spec/twitter/json_stream_spec.rb +++ b/spec/twitter/json_stream_spec.rb @@ -238,7 +238,7 @@ def receive_data data end it "should call no data callback after no data received for 90 seconds" do - connect_stream :stop_in => 6 do + connect_stream(stop_in: 6, ssl: false) do stream.last_data_received_at = Time.now - 88 stream.should_receive(:no_data).once end @@ -246,6 +246,20 @@ def receive_data data end + context "on empty data received" do + attr_reader :stream + before :each do + $data_to_send = "\n\r" + $close_connection = false + end + it "should call no data callback after empty data received for 90 seconds" do + connect_stream(stop_in: 6, ssl: false) do + stream.last_data_received_at = Time.now - 88 + stream.should_receive(:no_data).once + end + end + end + context "on server unavailable" do attr_reader :stream