class Diesel::Middleware::Auth::APIKey

Public Class Methods

new(app, options) click to toggle source
# File lib/diesel/middleware/auth/api_key.rb, line 6
def initialize(app, options)
  @app = app
  @id = options[:id]
  @in = options[:in]
  @name = options[:name]
  @format = options[:format]
end

Public Instance Methods

call(env) click to toggle source
# File lib/diesel/middleware/auth/api_key.rb, line 14
def call(env)
  context = env[:context]
  value = format_value(context.options[@id])
  if @in == :header
    env[:request_headers][@name] = value
  elsif @in == :query
    env[:params][@name] = value
  elsif @in == :body
    env[:body] = if body = env[:body]
      body.merge(@name => value)
    else
      { @name => value }
    end
  end
  @app.call(env)
end

Protected Instance Methods

format_value(val) click to toggle source
# File lib/diesel/middleware/auth/api_key.rb, line 32
def format_value(val)
  return val unless @format
  @format % val
end