Class: Twitter::Streaming::Response
- Inherits:
-
Object
- Object
- Twitter::Streaming::Response
- Defined in:
- lib/twitter/streaming/response.rb
Instance Method Summary collapse
- #<<(data) ⇒ Object
-
#initialize(&block) ⇒ Twitter::Streaming::Response
constructor
Initializes a new Response object.
- #on_body(data) ⇒ Object
- #on_status(_status) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Twitter::Streaming::Response
Initializes a new Response object
13 14 15 16 17 |
# File 'lib/twitter/streaming/response.rb', line 13 def initialize(&block) @block = block @parser = LLHttp::Parser.new(self, type: :response) @tokenizer = BufferedTokenizer.new("\r\n") end |
Instance Method Details
#<<(data) ⇒ Object
19 20 21 |
# File 'lib/twitter/streaming/response.rb', line 19 def <<(data) @parser << data end |
#on_body(data) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/twitter/streaming/response.rb', line 23 def on_body(data) @tokenizer.extract(data).each do |line| next if line.empty? @block.call(JSON.parse(line, symbolize_names: true)) end end |