Sha256: 97a2cfc84b0e2f6a33a77e764265934bdf8a4e3c22aa48dc5f2c5abf8e700699

Contents?: true

Size: 626 Bytes

Versions: 12

Compression:

Stored size: 626 Bytes

Contents

module ZendeskAPI
  # @private
  module Middleware
    # @private
    module Response
      class ParseJson < Faraday::Response::Middleware
        CONTENT_TYPE = 'Content-Type'.freeze
        dependency 'json'

        def on_complete(env)
          type = env[:response_headers][CONTENT_TYPE].to_s
          type = type.split(';', 2).first if type.index(';')
          type

          if type == 'application/json' && env[:body].respond_to?(:to_str) && !env[:body].strip.empty?
            env[:body] = JSON.parse(env[:body])
          else
            env[:body] = nil
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
zendesk_api-1.4.0 lib/zendesk_api/middleware/response/parse_json.rb
zendesk_api-1.3.9 lib/zendesk_api/middleware/response/parse_json.rb
zendesk_api-1.3.8 lib/zendesk_api/middleware/response/parse_json.rb
zendesk_api-1.3.7 lib/zendesk_api/middleware/response/parse_json.rb
zendesk_api-1.3.5 lib/zendesk_api/middleware/response/parse_json.rb
zendesk_api-1.3.4 lib/zendesk_api/middleware/response/parse_json.rb
zendesk_api-1.3.2 lib/zendesk_api/middleware/response/parse_json.rb
zendesk_api-1.3.1 lib/zendesk_api/middleware/response/parse_json.rb
zendesk_api-1.3.0 lib/zendesk_api/middleware/response/parse_json.rb
zendesk_api-1.3.0.rc3 lib/zendesk_api/middleware/response/parse_json.rb
zendesk_api-1.3.0.rc2 lib/zendesk_api/middleware/response/parse_json.rb
zendesk_api-1.3.0.rc1 lib/zendesk_api/middleware/response/parse_json.rb