2013-03-15 04:23:37 +00:00
|
|
|
class ApiMaxmindRequestsController < ApiController
|
2012-12-15 20:17:41 +00:00
|
|
|
|
|
|
|
|
respond_to :json
|
|
|
|
|
|
2013-07-09 03:05:05 +00:00
|
|
|
def countries
|
|
|
|
|
countries = MaxMindManager.countries()
|
|
|
|
|
render :json => { :countries => countries }, :status => 200
|
|
|
|
|
end
|
|
|
|
|
|
2012-12-15 20:17:41 +00:00
|
|
|
def regions
|
|
|
|
|
regions = MaxMindManager.regions(params[:country])
|
|
|
|
|
if regions && regions.length > 0
|
|
|
|
|
render :json => { :regions => regions }, :status => 200
|
|
|
|
|
else
|
2013-05-17 03:54:33 +00:00
|
|
|
render :json => { :message => "Unrecognized Country" }, :status => 422
|
2012-12-15 20:17:41 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def cities
|
|
|
|
|
cities = MaxMindManager.cities(params[:country], params[:region])
|
|
|
|
|
if cities && cities.length > 0
|
|
|
|
|
render :json => { :cities => cities }, :status => 200
|
|
|
|
|
else
|
2013-06-24 23:41:29 +00:00
|
|
|
render :json => { :message => "Unrecognized country or region" }, :status => 422
|
2012-12-15 20:17:41 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2013-05-16 17:45:10 +00:00
|
|
|
def isps
|
|
|
|
|
isps = MaxMindManager.isps(params[:country])
|
|
|
|
|
if isps && isps.length > 0
|
|
|
|
|
render :json => { :isps => isps }, :status => 200
|
|
|
|
|
else
|
2013-06-24 23:41:29 +00:00
|
|
|
render :json => { :message => "Unrecognized Country" }, :status => 422
|
2013-05-16 17:45:10 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2013-12-09 03:31:49 +00:00
|
|
|
# returns location hash (country, region, state) based on requesting IP
|
|
|
|
|
def resolved_location
|
|
|
|
|
location = MaxMindManager.lookup(request.remote_ip)
|
|
|
|
|
render :json => { :country => location[:country], :region => location[:state], :city => location[:city] }, :status => 200
|
|
|
|
|
end
|
|
|
|
|
|
2012-12-15 20:17:41 +00:00
|
|
|
end
|