Class: PriceHubble::Client::Request::DefaultHeaders

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/price_hubble/client/request/default_headers.rb

Overview

Add some default headers to every request.

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object

Serve the Faraday middleware API.

Parameters:

  • env (Hash{Symbol => Mixed})

    the request



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/price_hubble/client/request/default_headers.rb', line 11

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

#user_agentString

Build an useful user agent string to pass. We identify ourself as PriceHubbleGem with the current gem version.

Returns:

  • (String)

    the user agent string



27
28
29
# File 'lib/price_hubble/client/request/default_headers.rb', line 27

def user_agent
  "PriceHubbleGem/#{PriceHubble::VERSION}"
end