Class: Gazouillis::Stream

Inherits:
Object
  • Object
show all
Includes:
Celluloid::IO
Defined in:
lib/gazouillis/stream.rb

Overview

This class concern is to handle stream connections.

Instance Method Summary collapse

Constructor Details

#initialize(path, opts) ⇒ Stream

Returns a new instance of Stream.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gazouillis/stream.rb', line 8

def initialize(path, opts)
  @options = default_options.merge(opts).merge(path: path)

  socket = TCPSocket.new "stream.twitter.com", 443
  ssl = OpenSSL::SSL::SSLSocket.new(socket.to_io, OpenSSL::SSL::SSLContext.new)
  ssl.sync = true
  ssl.connect

  @stream = ssl

  @http_parser = Http::Parser.new

  @http_parser.on_body = on_message_callback
  @http_parser.on_headers_complete = on_headers_complete
end

Instance Method Details

#closeObject



29
30
31
# File 'lib/gazouillis/stream.rb', line 29

def close
  @stream.to_io.close
end

#on_message(message) ⇒ Object



33
34
35
# File 'lib/gazouillis/stream.rb', line 33

def on_message(message)
  # Hook method. To be override.
end

#openObject



24
25
26
27
# File 'lib/gazouillis/stream.rb', line 24

def open
  @stream.write request
  handle_connection
end