class Codat::FaradayCodatAuth

Public Class Methods

new(app, api_key = '', options = {}) click to toggle source
# File lib/codat/faraday_codat_auth.rb, line 9
def initialize(app, api_key = '', options = {})
  @app = app
  @api_key = api_key
  @options = options
end

Public Instance Methods

call(env) click to toggle source
# File lib/codat/faraday_codat_auth.rb, line 15
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