class BasicApiAuth::Middleware

Public Class Methods

new(app, api_key) click to toggle source
# File lib/basic_api_auth.rb, line 11
def initialize(app, api_key)
  @app = app
  @api_key = api_key
end

Public Instance Methods

authenticate_hashkey() click to toggle source
# File lib/basic_api_auth.rb, line 24
def authenticate_hashkey
  @hashkey == generate_hashkey_for(@params, @api_key)
end
call(env) click to toggle source
# File lib/basic_api_auth.rb, line 16
def call(env)
  @params = Rack::Request.new(env).params
  @hashkey = @params.delete('hashkey')
  return @@hashkey_requirement_error unless @hashkey
  return @@authenticity_error unless authenticate_hashkey
  @app.call(env)
end