Class: Nervion::StreamHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/nervion/stream_handler.rb

Instance Method Summary collapse

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_streamObject



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_errorObject



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

Returns:

  • (Boolean)


26
27
28
# File 'lib/nervion/stream_handler.rb', line 26

def stream_close_requested?
  @close_stream ||= false
end