Class: Twitter::Streaming::Response
- Inherits:
-
Object
- Object
- Twitter::Streaming::Response
- Defined in:
- lib/twitter/streaming/response.rb
Overview
Handles streaming response parsing
Instance Method Summary collapse
-
#<<(data) ⇒ void
Appends data to the parser.
-
#initialize(&block) ⇒ Twitter::Streaming::Response
constructor
Initializes a new Response object.
-
#on_body(data) ⇒ void
Handles body data from the response.
-
#on_status(_status) ⇒ void
Handles status code from the response.
Constructor Details
#initialize(&block) ⇒ Twitter::Streaming::Response
Initializes a new Response object
18 19 20 21 22 |
# File 'lib/twitter/streaming/response.rb', line 18 def initialize(&block) @block = block @parser = LLHttp::Parser.new(self, type: :response) # steep:ignore UnknownConstant @tokenizer = BufferedTokenizer.new("\r\n") # steep:ignore UnknownConstant end |
Instance Method Details
#<<(data) ⇒ void
This method returns an undefined value.
Appends data to the parser
31 32 33 |
# File 'lib/twitter/streaming/response.rb', line 31 def <<(data) @parser << data end |
#on_body(data) ⇒ void
This method returns an undefined value.
Handles body data from the response
42 43 44 45 46 47 48 |
# File 'lib/twitter/streaming/response.rb', line 42 def on_body(data) @tokenizer.extract(data).each do |line| next if line.empty? @block.call(JSON.parse(line, symbolize_names: true)) # steep:ignore UnknownConstant end end |
#on_status(_status) ⇒ void
This method returns an undefined value.
Handles status code from the response
57 58 59 60 |
# File 'lib/twitter/streaming/response.rb', line 57 def on_status(_status) error = Twitter::Error::ERRORS[@parser.status_code] raise error if error end |