Sha256: fc5d81fbac4d53550c59812f0bc05acaf6578a8eadb24b39d0ccc6a7ab25dc26
Contents?: true
Size: 809 Bytes
Versions: 4
Compression:
Stored size: 809 Bytes
Contents
require "buftok" require "http" require "json" require "twitter/error" require "llhttp" module Twitter module Streaming class Response # Initializes a new Response object # # @return [Twitter::Streaming::Response] def initialize(&block) @block = block @parser = LLHttp::Parser.new(self, type: :response) @tokenizer = BufferedTokenizer.new("\r\n") end def <<(data) @parser << data end def on_body(data) @tokenizer.extract(data).each do |line| next if line.empty? @block.call(JSON.parse(line, symbolize_names: true)) end end def on_status(_status) error = Twitter::Error::ERRORS[@parser.status_code] raise error if error end end end end
Version data entries
4 entries across 4 versions & 1 rubygems