Sha256: 3405ddb0f240f4bf6c899523299cef53c485d7202ffbd51fedbb9eb62e6a2a6a

Contents?: true

Size: 976 Bytes

Versions: 15

Compression:

Stored size: 976 Bytes

Contents

# frozen_string_literal: true

module PriceHubble
  module Client
    module Request
      # Add some default headers to every request.
      class DefaultHeaders < Faraday::Middleware
        # Serve the Faraday middleware API.
        #
        # @param env [Hash{Symbol => Mixed}] the request
        def call(env)
          env[:request_headers].merge! \
            'User-Agent' => user_agent,
            'Accept' => 'application/json'

          # Set request content type to JSON as fallback
          env[:request_headers]['Content-Type'] = 'application/json' \
            if env[:request_headers]['Content-Type'].blank?

          @app.call(env)
        end

        # Build an useful user agent string to pass. We identify ourself as
        # +PriceHubbleGem+ with the current gem version.
        #
        # @return [String] the user agent string
        def user_agent
          "PriceHubbleGem/#{PriceHubble::VERSION}"
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
pricehubble-1.3.0 lib/price_hubble/client/request/default_headers.rb
pricehubble-1.2.5 lib/price_hubble/client/request/default_headers.rb
pricehubble-1.2.4 lib/price_hubble/client/request/default_headers.rb
pricehubble-1.2.3 lib/price_hubble/client/request/default_headers.rb
pricehubble-1.2.2 lib/price_hubble/client/request/default_headers.rb
pricehubble-1.2.1 lib/price_hubble/client/request/default_headers.rb
pricehubble-1.2.0 lib/price_hubble/client/request/default_headers.rb
pricehubble-1.1.0 lib/pricehubble/client/request/default_headers.rb
pricehubble-1.0.0 lib/pricehubble/client/request/default_headers.rb
pricehubble-0.4.2 lib/pricehubble/client/request/default_headers.rb
pricehubble-0.4.1 lib/pricehubble/client/request/default_headers.rb
pricehubble-0.4.0 lib/pricehubble/client/request/default_headers.rb
pricehubble-0.3.0 lib/pricehubble/client/request/default_headers.rb
pricehubble-0.2.0 lib/pricehubble/client/request/default_headers.rb
pricehubble-0.1.0 lib/pricehubble/client/request/default_headers.rb