class Gnip::GnipStream::Replay
Public Class Methods
new(client)
click to toggle source
Calls superclass method
# File lib/gnip/gnip-stream/replay.rb, line 4 def initialize(client) super # version is setted in the super case version when '1.0' @url = "https://stream.gnip.com:443/accounts/#{client.account}/publishers/#{client.publisher}/replay/track/#{client.replay_label}.json" when '2.0' @url = "https://gnip-stream.gnip.com/replay/powertrack/accounts/#{client.account}/publishers/#{client.publisher}/#{client.replay_label}.json" else raise Exception.new("version #{version} is not supported from this gem.") end end
Public Instance Methods
configure_handlers()
click to toggle source
# File lib/gnip/gnip-stream/replay.rb, line 16 def configure_handlers on_error { |error| @error_handler.attempt_to_reconnect("Gnip Connection Error. Reason was: #{error.inspect}") } on_connection_close { puts 'Gnip::GnipStream::Replay -> Connection closed' } end
connect(options)
click to toggle source
# File lib/gnip/gnip-stream/replay.rb, line 27 def connect(options) search_options = {} search_options[:fromDate] = Gnip.format_date(options[:date_from]) if options[:date_from] search_options[:toDate] = Gnip.format_date(options[:date_to]) if options[:date_to] stream_url = [url, search_options.to_query].join('?') EM.run do http = EM::HttpRequest.new(stream_url, inactivity_timeout: 45, connection_timeout: 75).get(head: @headers) http.stream { |chunk| process_chunk(chunk) } http.callback { handle_connection_close(http) EM.stop } http.errback { handle_error(http) EM.stop } end end
consume(options = {}, &block)
click to toggle source
# File lib/gnip/gnip-stream/replay.rb, line 21 def consume(options = {}, &block) @client_callback = block if block on_message(&@client_callback) connect(options) end