Sha256: 1f08c1bbab48170e18bf067f87a557bdfd0bf9bd45c0de4b998b0262b62687f9

Contents?: true

Size: 715 Bytes

Versions: 80

Compression:

Stored size: 715 Bytes

Contents

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

        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

80 entries across 80 versions & 2 rubygems

Version Path
zendesk_api-1.37.0 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-1.36.0 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-1.35.0 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-1.34.0 lib/zendesk_api/middleware/request/encode_json.rb
discourse_zendesk_api-1.0.1 lib/zendesk_api/middleware/request/encode_json.rb
discourse_zendesk_api-1.0.0 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-1.33.0 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-1.32.0 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-1.31.0 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-1.30.0 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-1.29.0 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-1.28.0 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-1.27.0 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-1.26.0 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-1.25.0 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-1.24.0 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-1.23.0 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-1.22.0 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-1.21.0 lib/zendesk_api/middleware/request/encode_json.rb
zendesk_api-1.20.0 lib/zendesk_api/middleware/request/encode_json.rb