Last active
August 29, 2015 14:01
-
-
Save guilleiguaran/6a007e48347f672867b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CountryChecker | |
COUNTRY_DB = nil # FIX | |
def initialize(app, options = {}) | |
@app = app | |
@ip_override = options[:allow_ip_override] | |
end | |
def call(env) | |
request = Rack::Request.new(env) | |
ip = @ip_override ? request.params['ip'] : request.ip | |
country = COUNTRY_DB.country(ip).country | |
if valid_domain?(country) | |
redirect_to_domain(country) | |
else | |
@app.call(env) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment