Class: X::StreamParser
- Inherits:
-
Object
- Object
- X::StreamParser
- Defined in:
- lib/x/stream_parser.rb
Overview
Handles streaming responses from the X API
Constant Summary collapse
- LINE_DELIMITER =
Line delimiter for streaming responses
"\r\n".freeze
Instance Method Summary collapse
-
#process(response:, response_parser:, array_class: nil, object_class: nil) {|Hash, Array| ... } ⇒ void
Process a streaming response and yield parsed JSON objects.
Instance Method Details
#process(response:, response_parser:, array_class: nil, object_class: nil) {|Hash, Array| ... } ⇒ void
This method returns an undefined value.
Process a streaming response and yield parsed JSON objects
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/x/stream_parser.rb', line 24 def process(response:, response_parser:, array_class: nil, object_class: nil, &block) response_parser.parse(response:) unless response.is_a?(Net::HTTPSuccess) buffer = +"" response.read_body do |chunk| buffer << chunk process_buffer(buffer:, array_class:, object_class:, &block) end process_remaining(buffer:, array_class:, object_class:, &block) end |