diff --git a/earthquake.gemspec b/earthquake.gemspec index 8479a0c..6196488 100644 --- a/earthquake.gemspec +++ b/earthquake.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |s| s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] - s.add_runtime_dependency "twitter-stream" + s.add_runtime_dependency "twitter-stream", "~> 0.1.16" s.add_runtime_dependency "notify" s.add_runtime_dependency "i18n" s.add_runtime_dependency "activesupport" diff --git a/lib/earthquake/commands.rb b/lib/earthquake/commands.rb index 36773b5..a827225 100644 --- a/lib/earthquake/commands.rb +++ b/lib/earthquake/commands.rb @@ -264,7 +264,7 @@ def self._eval_as_ruby_string(text) default_stream = { method: "POST", host: "userstream.twitter.com", - path: "/2/user.json", + path: "/1.1/user.json", ssl: true, } diff --git a/lib/earthquake/core.rb b/lib/earthquake/core.rb index cc5dc03..9511f18 100644 --- a/lib/earthquake/core.rb +++ b/lib/earthquake/core.rb @@ -68,11 +68,10 @@ def default_config secure: true, output_interval: 1, history_size: 1000, - api: { :host => 'userstream.twitter.com', :path => '/2/user.json', :ssl => true }, + api: { :host => 'userstream.twitter.com', :path => '/1.1/user.json', :ssl => true }, confirm_type: :y, expand_url: false, thread_indent: " ", - no_data_timeout: 30 } end @@ -144,27 +143,17 @@ def start(options = {}) end EM.add_periodic_timer(config[:output_interval]) do - if @last_data_received_at && Time.now - @last_data_received_at > config[:no_data_timeout] - reconnect - end if Readline.line_buffer.nil? || Readline.line_buffer.empty? sync { output } end end - reconnect unless options[:'no-stream'] == true + start_stream(config[:api]) unless options[:'no-stream'] == true trap('INT') { stop } end end - def reconnect - item_queue.clear - start_stream(config[:api]) - rescue EventMachine::ConnectionError => e - # ignore - end - def start_stream(options) stop_stream @@ -178,7 +167,6 @@ def start_stream(options) @stream = ::Twitter::JSONStream.connect(options) @stream.each_item do |item| - @last_data_received_at = Time.now # for reconnect when no data item_queue << JSON.parse(item) end diff --git a/lib/earthquake/ext.rb b/lib/earthquake/ext.rb index 79614ac..05d21b1 100644 --- a/lib/earthquake/ext.rb +++ b/lib/earthquake/ext.rb @@ -1,24 +1,3 @@ -module Twitter - class JSONStream - protected - def reconnect_after timeout - @reconnect_callback.call(timeout, @reconnect_retries) if @reconnect_callback - - if timeout == 0 - start_tls if @options[:ssl] - reconnect @options[:host], @options[:port] - else - EM.add_timer(timeout) do - start_tls if @options[:ssl] - reconnect @options[:host], @options[:port] - end - end - rescue EventMachine::ConnectionError => e - # ignore - end - end -end - class String def c(*codes) codes = codes.flatten.map { |code|