class ApiMaxmindRequestsController < ApiController respond_to :json def countries countriesx = MaxMindManager.countries render :json => { :countriesx => countriesx }, :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 # returns location hash (country, region, state) based on requesting IP def resolved_location location = GeoIpLocations.lookup(request.remote_ip) render :json => { :country => location[:country], :region => location[:state], :city => location[:city] }, :status => 200 end end