Class: Nervion::StreamHandler

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

Instance Method Summary collapse

Constructor Details

#initialize(callbacks, stream_parser = StreamParser.new) ⇒ StreamHandler

Returns a new instance of StreamHandler.



5
6
7
8
# File 'lib/nervion/stream_handler.rb', line 5

def initialize(callbacks, stream_parser = StreamParser.new)
  @callbacks, @stream_parser = callbacks, stream_parser
  @stream_parser.on_json_parsed = @callbacks[:message]
end

Instance Method Details

#<<(data) ⇒ Object



10
11
12
# File 'lib/nervion/stream_handler.rb', line 10

def <<(data)
  @stream_parser << data
end

#handle_http_error(error) ⇒ Object



14
15
16
17
# File 'lib/nervion/stream_handler.rb', line 14

def handle_http_error(error)
  @stream_parser.reset!
  @callbacks[:http_error].call(error.status, error.body)
end

#handle_network_errorObject



19
20
21
22
# File 'lib/nervion/stream_handler.rb', line 19

def handle_network_error
  @stream_parser.reset!
  @callbacks[:network_error].call
end