class Faraday::MogueraAuthentication

Public Class Methods

new(app, access_key, secret_access_key) click to toggle source
Calls superclass method
# File lib/faraday/moguera_authentication.rb, line 7
def initialize(app, access_key, secret_access_key)
  super(app) # @app = app
  @access_key = access_key
  @secret_access_key = secret_access_key
end

Public Instance Methods

call(env) click to toggle source
# File lib/faraday/moguera_authentication.rb, line 13
def call(env)
  params = build_parameter(env)
  request = Moguera::Authentication::Request.new(params)
  headers = {
      'Authorization' => request.token,
      'Content-Type' => params[:content_type],
      'Date' => params[:http_date]
  }
  env.request_headers.merge!(headers)
  @app.call(env)
end

Private Instance Methods

build_parameter(env) click to toggle source
# File lib/faraday/moguera_authentication.rb, line 27
def build_parameter(env)
  path = env.url.path
  method = "#{env.method}".upcase
  headers = env.request_headers
  {
      access_key: @access_key,
      secret_access_key: @secret_access_key,
      request_path: path,
      request_method: method,
      content_type: headers['Content-Type'],
      http_date: headers['Date'] || Time.now.httpdate
  }
end