Class: FaradayMiddleware::Request::ApiKey

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/faraday_middleware/request/api_key.rb

Overview

Public: Adds the api key as a url param if present

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/faraday_middleware/request/api_key.rb', line 9

def call(env)
  api_key = env[:request][:client_options][:api_key]

  if api_key
    env[:url].query = env[:url].query ? "#{env[:url].query}&key=#{api_key}" : "key=#{api_key}"
  end

  @app.call env
end