class Twitter::Streaming::Response
Public Class Methods
new(&block)
click to toggle source
Initializes a new Response
object
@return [Twitter::Streaming::Response]
# File lib/twitter/streaming/response.rb, line 12 def initialize(&block) @block = block @parser = Http::Parser.new(self) @tokenizer = BufferedTokenizer.new("\r\n") end
Public Instance Methods
<<(data)
click to toggle source
# File lib/twitter/streaming/response.rb, line 18 def <<(data) @parser << data end
on_body(data)
click to toggle source
# File lib/twitter/streaming/response.rb, line 27 def on_body(data) @tokenizer.extract(data).each do |line| next if line.empty? @block.call(JSON.parse(line, symbolize_names: true)) end end
on_headers_complete(_headers)
click to toggle source
# File lib/twitter/streaming/response.rb, line 22 def on_headers_complete(_headers) error = Twitter::Error::ERRORS[@parser.status_code] raise error if error end