Module: PriceHubble::Client::Utils::Request

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/price_hubble/client/utils/request.rb

Overview

Some helpers to prepare requests in a general way.

Constant Summary collapse

CONTENT_TYPE =

A common HTTP content type to symbol mapping for correct header settings.

{
  json: 'application/json',
  multipart: 'multipart/form-data',
  url_encoded: 'application/x-www-form-urlencoded'
}.freeze

Instance Method Summary collapse

Instance Method Details

#use_authentication(req) ⇒ Object

Use the configured identity to authenticate the given request.

Parameters:

  • req (Faraday::Request)

    the request to manipulate



23
24
25
# File 'lib/price_hubble/client/utils/request.rb', line 23

def use_authentication(req)
  req.params.merge!(access_token: PriceHubble.identity.access_token)
end

#use_default_context(req, action) ⇒ Object

Use the default request context to identificate the request.

Parameters:

  • action (String, Symbol)

    the used client action

  • req (Faraday::Request)

    the request to manipulate



31
32
33
34
35
36
# File 'lib/price_hubble/client/utils/request.rb', line 31

def use_default_context(req, action)
  req.options.context ||= {}
  req.options.context.merge!(client: self.class,
                             action: action,
                             request_id: SecureRandom.hex(3))
end