jam-cloud/web/lib/max_mind_manager.rb

45 lines
1.0 KiB
Ruby

class MaxMindManager < BaseManager
def initialize(options={})
super(options)
end
def self.countries
Country.get_all.map do |c|
country = Carmen::Country.coded(c.countrycode)
{
countrycode: c.countrycode,
countryname: country.name
}
end
end
def self.regions(country)
Region.get_all(country).map do |r|
country = Carmen::Country.coded(r.countrycode)
region = country.subregions.coded(r.region)
{
region: r.region,
name: region.name
}
end
end
def self.cities(country, region)
City.get_all(country, region).map { |c| c.city }
end
def self.create_phony_database
GeoIpBlocks.connection.execute("select generate_scores_dataset()").check
end
private
def clear_location_table
@pg_conn.exec("DELETE FROM geoiplocations").clear
end
def clear_isp_table
@pg_conn.exec("DELETE FROM geoispip").clear
end
end # class MaxMindManager