Add `ProjectHoneypot::Rack` class to DRY
parent
707b115428
commit
415f7c9d24
|
@ -1,6 +1,7 @@
|
||||||
require 'net/dns'
|
require 'net/dns'
|
||||||
require "project_honeypot/url"
|
require "project_honeypot/url"
|
||||||
require "project_honeypot/base"
|
require "project_honeypot/base"
|
||||||
|
require "project_honeypot/rack"
|
||||||
require "project_honeypot/rack/header"
|
require "project_honeypot/rack/header"
|
||||||
require "project_honeypot/rack/forbidden"
|
require "project_honeypot/rack/forbidden"
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
module ProjectHoneypot
|
||||||
|
class Rack
|
||||||
|
def initialize(app, options={})
|
||||||
|
@app = app
|
||||||
|
|
||||||
|
raise ArgumentError, 'Must specify an API key' unless options[:api_key]
|
||||||
|
ProjectHoneypot.api_key = options[:api_key]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,12 +1,6 @@
|
||||||
module ProjectHoneypot::Rack
|
module ProjectHoneypot
|
||||||
class Forbidden
|
class Rack
|
||||||
def initialize(app, options={})
|
class Forbidden < Rack
|
||||||
@app = app
|
|
||||||
|
|
||||||
raise ArgumentError, 'Must specify an API key' unless options[:api_key]
|
|
||||||
ProjectHoneypot.api_key = options[:api_key]
|
|
||||||
end
|
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
request = ::Rack::Request.new(env)
|
request = ::Rack::Request.new(env)
|
||||||
url = ProjectHoneypot.lookup(request.ip)
|
url = ProjectHoneypot.lookup(request.ip)
|
||||||
|
@ -19,3 +13,4 @@ module ProjectHoneypot::Rack
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
module ProjectHoneypot::Rack
|
module ProjectHoneypot
|
||||||
class Header
|
class Rack
|
||||||
def initialize(app, options={})
|
class Header < Rack
|
||||||
@app = app
|
|
||||||
|
|
||||||
raise ArgumentError, 'Must specify an API key' unless options[:api_key]
|
|
||||||
ProjectHoneypot.api_key = options[:api_key]
|
|
||||||
end
|
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
request = ::Rack::Request.new(env)
|
request = ::Rack::Request.new(env)
|
||||||
url = ProjectHoneypot.lookup(request.ip)
|
url = ProjectHoneypot.lookup(request.ip)
|
||||||
|
@ -17,3 +11,4 @@ module ProjectHoneypot::Rack
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue