Sha256: 68ca5255776e4c8d49a8226b15cd56be10034cf3867a6938e9fb6c1bc1febbac

Contents?: true

Size: 495 Bytes

Versions: 8

Compression:

Stored size: 495 Bytes

Contents

require 'faraday'
require 'multi_json'

module Twitter
  module Response
    class ParseJson < Faraday::Response::Middleware

      def parse(body)
        case body
        when /\A^\s*$\z/, nil
          nil
        else
          MultiJson.decode(body, :symbolize_keys => true)
        end
      end

      def on_complete(env)
        if respond_to?(:parse)
          env[:body] = parse(env[:body]) unless [204, 301, 302, 304].include?(env[:status])
        end
      end

    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
twitter-4.8.1 lib/twitter/response/parse_json.rb
twitter-4.8.0 lib/twitter/response/parse_json.rb
twitter-4.7.0 lib/twitter/response/parse_json.rb
twitter-4.6.2 lib/twitter/response/parse_json.rb
twitter-4.6.1 lib/twitter/response/parse_json.rb
twitter-4.6.0 lib/twitter/response/parse_json.rb
twitter-4.5.0 lib/twitter/response/parse_json.rb
twitter-4.4.4 lib/twitter/response/parse_json.rb