Class: Johac::Connection::Middleware::Authorization

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/johac/connection.rb

Overview

Adds Authorization header to all requests.

Instance Method Summary collapse

Constructor Details

#initialize(app, scheme, access_key, secret_key) ⇒ Authorization

Returns a new instance of Authorization.



156
157
158
159
160
161
# File 'lib/johac/connection.rb', line 156

def initialize(app, scheme, access_key, secret_key)
  @scheme = scheme
  @access_key = access_key
  @secret_key = secret_key
  super(app)
end

Instance Method Details

#call(env) ⇒ Object



163
164
165
166
167
168
169
170
171
# File 'lib/johac/connection.rb', line 163

def call(env)
  if auth = case @scheme
            when :basic then "Basic #{basic_auth_token}"
            when :hmac  then "hmac #{hmac_auth_token(env.url.path)}"
            end
    env[:request_headers]['Authorization'] = auth
  end
  @app.call(env)
end