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.



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

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

Instance Method Details

#call(env) ⇒ Object



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

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