Class: Codat::FaradayCodatAuth
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Codat::FaradayCodatAuth
- Defined in:
- lib/codat/faraday_codat_auth.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, api_key = '', options = {}) ⇒ FaradayCodatAuth
constructor
A new instance of FaradayCodatAuth.
Constructor Details
#initialize(app, api_key = '', options = {}) ⇒ FaradayCodatAuth
Returns a new instance of FaradayCodatAuth.
9 10 11 12 13 14 15 |
# File 'lib/codat/faraday_codat_auth.rb', line 9 def initialize(app, api_key = '', = {}) super() @app = app @api_key = api_key @options = end |
Instance Method Details
#call(env) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/codat/faraday_codat_auth.rb', line 17 def call(env) unless @api_key&.size&.positive? raise APIKeyError, 'Missing api_key! Use a Codat.configure block to add your key.' end env[:request_headers]['Authorization'] = "Basic #{Base64.encode64(@api_key)}" env[:request_headers]['Content-Type'] = 'application/json' env[:request_headers]['User-Agent'] = "finpoint/#{Codat::VERSION}" @app.call(env) end |