Class: Nervion::StreamHandler
- Inherits:
-
Object
- Object
- Nervion::StreamHandler
- Defined in:
- lib/nervion/stream_handler.rb
Instance Method Summary collapse
- #<<(data) ⇒ Object
- #close_stream ⇒ Object
- #handle_http_error(error) ⇒ Object
- #handle_network_error ⇒ Object
-
#initialize(callbacks) ⇒ StreamHandler
constructor
A new instance of StreamHandler.
- #stream_close_requested? ⇒ Boolean
Constructor Details
#initialize(callbacks) ⇒ StreamHandler
Returns a new instance of StreamHandler.
7 8 9 10 |
# File 'lib/nervion/stream_handler.rb', line 7 def initialize(callbacks) @callbacks = callbacks @http_parser = HttpParser.new(setup_json_parser) end |
Instance Method Details
#<<(data) ⇒ Object
12 13 14 |
# File 'lib/nervion/stream_handler.rb', line 12 def <<(data) @http_parser << data end |
#close_stream ⇒ Object
30 31 32 |
# File 'lib/nervion/stream_handler.rb', line 30 def close_stream @close_stream = true end |
#handle_http_error(error) ⇒ Object
16 17 18 19 |
# File 'lib/nervion/stream_handler.rb', line 16 def handle_http_error(error) @http_parser.reset! @callbacks[:http_error].call(error.status, error.body) end |
#handle_network_error ⇒ Object
21 22 23 24 |
# File 'lib/nervion/stream_handler.rb', line 21 def handle_network_error @http_parser.reset! @callbacks[:network_error].call end |
#stream_close_requested? ⇒ Boolean
26 27 28 |
# File 'lib/nervion/stream_handler.rb', line 26 def stream_close_requested? @close_stream ||= false end |