Class: Twitter::Streaming::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter/streaming/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Connection



8
9
10
11
# File 'lib/twitter/streaming/connection.rb', line 8

def initialize(opts = {})
  @tcp_socket_class = opts.fetch(:tcp_socket_class) { TCPSocket }
  @ssl_socket_class = opts.fetch(:ssl_socket_class) { OpenSSL::SSL::SSLSocket }
end

Instance Attribute Details

#ssl_socket_classObject (readonly)

Returns the value of attribute ssl_socket_class



12
13
14
# File 'lib/twitter/streaming/connection.rb', line 12

def ssl_socket_class
  @ssl_socket_class
end

#tcp_socket_classObject (readonly)

Returns the value of attribute tcp_socket_class



12
13
14
# File 'lib/twitter/streaming/connection.rb', line 12

def tcp_socket_class
  @tcp_socket_class
end

Instance Method Details

#stream(request, response) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/twitter/streaming/connection.rb', line 14

def stream(request, response)
  client_context = OpenSSL::SSL::SSLContext.new
  client         = @tcp_socket_class.new(Resolv.getaddress(request.uri.host), request.uri.port)
  ssl_client     = @ssl_socket_class.new(client, client_context)

  ssl_client.connect
  request.stream(ssl_client)
  while body = ssl_client.readpartial(1024) # rubocop:disable AssignmentInCondition, WhileUntilModifier
    response << body
  end
end