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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, opts) ⇒ Stream

Returns a new instance of Stream.



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

def initialize(path, opts)
  @options = default_options.merge(opts)
  @path = path
  @host = opts.fetch(:host, "stream.twitter.com")
  @method = opts.fetch(:method, "GET")

  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 Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



7
8
9
# File 'lib/gazouillis/stream.rb', line 7

def host
  @host
end

#methodObject (readonly)

Returns the value of attribute method.



7
8
9
# File 'lib/gazouillis/stream.rb', line 7

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/gazouillis/stream.rb', line 7

def path
  @path
end

Instance Method Details

#closeObject



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

def close
  @stream.to_io.close
end

#on_message(message) ⇒ Object



37
38
39
# File 'lib/gazouillis/stream.rb', line 37

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

#openObject



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

def open
  @stream.write request
  handle_connection
end