Sha256: e163be30e4cd57243952e983afd39169286ed3f04e793456e5c0dac15fe803a1

Contents?: true

Size: 645 Bytes

Versions: 5

Compression:

Stored size: 645 Bytes

Contents

module Faraday
  class Response
    class YajlResponse < Response
      attr_reader :body

      begin
        require 'yajl'

        def initialize(headers = nil, body = nil)
          super
          @parser = nil
        end

        def process(chunk)
          if !@parser
            @parser = Yajl::Parser.new
            @parser.on_parse_complete = method(:object_parsed)
          end
          @parser << chunk
        end

        def processed!
          @parser = nil
        end

        def object_parsed(obj)
          @body = obj
        end

      rescue LoadError => e
        self.load_error = e
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
faraday-0.1.2 lib/faraday/response/yajl_response.rb
faraday-0.1.1 lib/faraday/response/yajl_response.rb
faraday-0.1.0 lib/faraday/response/yajl_response.rb
faraday-0.0.2 lib/faraday/response/yajl_response.rb
faraday-0.0.1 lib/faraday/response/yajl_response.rb