Class: ProjectHoneypot::Rack::Forbidden

Inherits:
Object
  • Object
show all
Defined in:
lib/project_honeypot/rack/forbidden.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Forbidden

Returns a new instance of Forbidden.

Raises:

  • (ArgumentError)


3
4
5
6
7
8
# File 'lib/project_honeypot/rack/forbidden.rb', line 3

def initialize(app, options={})
  @app = app

  raise ArgumentError, 'Must specify an API key' unless options[:api_key]
  ProjectHoneypot.api_key = options[:api_key]
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/project_honeypot/rack/forbidden.rb', line 10

def call(env)
  request = ::Rack::Request.new(env)
  url = ProjectHoneypot.lookup(request.ip)

  if url.safe?
    @app.call(request.env)
  else
    [403, {"Content-Type" => "text/html"}, ["Forbidden"]]
  end
end