class Termtter::UserStreamReceiver
Constants
- ENDPOINT
Public Class Methods
repack_error(error, chunk)
click to toggle source
# File lib/plugins/user_stream.rb, line 15 def self.repack_error(error, chunk) new_error = error.class.new("#{error.message} (#{JSON.parse(chunk).inspect})") error.instance_variables.each{ |v| new_error.instance_variable_set(v, error.instance_variable_get(v)) } new_error rescue error end
Public Instance Methods
run(&block)
click to toggle source
# File lib/plugins/user_stream.rb, line 4 def run(&block) loop { begin self.process &block rescue => error Termtter::Client.handle_error error sleep 10 end } end
Protected Instance Methods
process() { |chunk| ... }
click to toggle source
# File lib/plugins/user_stream.rb, line 28 def process(&block) Termtter::Client.logger.info("connecting to UserStream") https = Net::HTTP.new(ENDPOINT.host, ENDPOINT.port) https.use_ssl = true https.verify_mode = OpenSSL::SSL::VERIFY_NONE https.start{ |https| request = Net::HTTP::Get.new(ENDPOINT.request_uri) request.oauth!(https, Termtter::API.twitter.access_token.consumer, Termtter::API.twitter.access_token) https.request(request){ |response| raise StandardError, response.code.to_i unless response.code.to_i == 200 raise StandardError, 'Response is not chuncked' unless response.chunked? Termtter::Client.logger.info("connected to UserStream") response.read_body{ |chunk| Termtter::Client.logger.debug("received: #{chunk}") yield chunk } } } end