Class: Cobinhood::AuthRequestMiddleware

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/cobinhood/client/rest/auth_request_middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, api_key) ⇒ AuthRequestMiddleware

Returns a new instance of AuthRequestMiddleware.



3
4
5
6
# File 'lib/cobinhood/client/rest/auth_request_middleware.rb', line 3

def initialize app, api_key
  super(app)
  @api_key = api_key
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
# File 'lib/cobinhood/client/rest/auth_request_middleware.rb', line 8

def call env
  raise Cobinhood::MissingApiKeyError.new('API KEY not provided') if @api_key.to_s == ''
  env[:request_headers]["authorization"] = @api_key
  @app.call(env)
end