Class: PriceHubble::Client::Request::DefaultHeaders
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- PriceHubble::Client::Request::DefaultHeaders
- Defined in:
- lib/price_hubble/client/request/default_headers.rb
Overview
Add some default headers to every request.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Serve the Faraday middleware API.
-
#user_agent ⇒ String
Build an useful user agent string to pass.
Instance Method Details
#call(env) ⇒ Object
Serve the Faraday middleware API.
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_agent ⇒ String
Build an useful user agent string to pass. We identify ourself as PriceHubbleGem
with the current gem version.
27 28 29 |
# File 'lib/price_hubble/client/request/default_headers.rb', line 27 def user_agent "PriceHubbleGem/#{PriceHubble::VERSION}" end |