Sha256: 490900fc4ca145401a7413d4e510a280db3bd61491974307575e4a0f22a0d9d9

Contents?: true

Size: 689 Bytes

Versions: 12

Compression:

Stored size: 689 Bytes

Contents

module ZendeskAPI
  # @private
  module Middleware
    # @private
    module Request
      class EncodeJson < Faraday::Middleware
        CONTENT_TYPE = 'Content-Type'.freeze
        MIME_TYPE = 'application/json'.freeze

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

          if env[:body] && !(env[:body].respond_to?(:to_str) && env[:body].empty?) && (type.empty? || type == MIME_TYPE)
            env[:body] = JSON.dump(env[:body])
            env[:request_headers][CONTENT_TYPE] ||= MIME_TYPE
          end

          @app.call(env)
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
zendesk_api-3.1.1 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-3.1.0 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-3.0.5 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-3.0.4 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-3.0.2 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-3.0.1 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-3.0.0 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-3.0.0.rc1 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-2.0.1 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-2.0.0 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-1.38.0.rc2 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-1.38.0.rc1 lib/zendesk_api/middleware/request/encode_json.rb