Class: Gazouillis::Stream
- Inherits:
-
Object
- Object
- Gazouillis::Stream
- Includes:
- Celluloid::IO
- Defined in:
- lib/gazouillis/stream.rb
Overview
This class concern is to handle stream connections.
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(path, opts) ⇒ Stream
constructor
A new instance of Stream.
- #on_message(message) ⇒ Object
- #open ⇒ Object
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 = .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 = @http_parser.on_headers_complete = on_headers_complete end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
7 8 9 |
# File 'lib/gazouillis/stream.rb', line 7 def host @host end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
7 8 9 |
# File 'lib/gazouillis/stream.rb', line 7 def method @method end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/gazouillis/stream.rb', line 7 def path @path end |
Instance Method Details
#close ⇒ Object
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 () # Hook method. To be override. end |
#open ⇒ Object
28 29 30 31 |
# File 'lib/gazouillis/stream.rb', line 28 def open @stream.write request handle_connection end |