43 lines
1.3 KiB
Ruby
43 lines
1.3 KiB
Ruby
class ApiMaxmindRequestsController < ApiController
|
|
|
|
respond_to :json
|
|
|
|
def countries
|
|
countries = MaxMindManager.countries()
|
|
render :json => { :countries => countries }, :status => 200
|
|
end
|
|
|
|
def regions
|
|
regions = MaxMindManager.regions(params[:country])
|
|
if regions && regions.length > 0
|
|
render :json => { :regions => regions }, :status => 200
|
|
else
|
|
render :json => { :message => "Unrecognized Country" }, :status => 422
|
|
end
|
|
end
|
|
|
|
def cities
|
|
cities = MaxMindManager.cities(params[:country], params[:region])
|
|
if cities && cities.length > 0
|
|
render :json => { :cities => cities }, :status => 200
|
|
else
|
|
render :json => { :message => "Unrecognized country or region" }, :status => 422
|
|
end
|
|
end
|
|
|
|
def isps
|
|
isps = MaxMindManager.isps(params[:country])
|
|
if isps && isps.length > 0
|
|
render :json => { :isps => isps }, :status => 200
|
|
else
|
|
render :json => { :message => "Unrecognized Country" }, :status => 422
|
|
end
|
|
end
|
|
|
|
# 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
|
|
|
|
end |