diff --git a/lib/maxmind_database.rb b/lib/maxmind_database.rb index 9330f03f6..fd07df948 100644 --- a/lib/maxmind_database.rb +++ b/lib/maxmind_database.rb @@ -6,9 +6,9 @@ module MaxmindDatabase extend self def download(package, dir = "tmp") - filepath = File.expand_path(File.join(dir, archive_filename(package))) + filepath = File.expand_path(File.join(dir, "#{archive_edition(package)}.zip")) open(filepath, 'wb') do |file| - uri = URI.parse(archive_url(package)) + uri = URI.parse(base_url(package)) Net::HTTP.start(uri.host, uri.port) do |http| http.request_get(uri.path) do |resp| # TODO: show progress @@ -94,16 +94,16 @@ def archive_url(package) base_url + archive_url_path(package) end - def archive_url_path(package) + def archive_edition(package) { - geolite_country_csv: "GeoLite2-Country-CSV.zip", - geolite_city_csv: "GeoLite2-City-CSV.zip", - geolite_asn_csv: "GeoLite2-ASN-CSV.zip" + geolite_country_csv: "GeoLite2-Country-CSV", + geolite_city_csv: "GeoLite2-City-CSV", + geolite_asn_csv: "GeoLite2-ASN-CSV" }[package] end - def base_url - "http://geolite.maxmind.com/download/geoip/database/" + def base_url(edition) + "https://download.maxmind.com/app/geoip_download?edition_id=#{edition}&license_key=#{ENV['LICENSE_KEY']}&suffix=zip" end end end diff --git a/lib/tasks/maxmind.rake b/lib/tasks/maxmind.rake index 2787e8140..3d4f6f780 100644 --- a/lib/tasks/maxmind.rake +++ b/lib/tasks/maxmind.rake @@ -54,7 +54,7 @@ module MaxmindTask end require 'fileutils' p = "geolite_#{package}_csv".intern - archive_filename = Geocoder::MaxmindDatabase.archive_filename(p) + archive_filename = "#{Geocoder::MaxmindDatabase.archive_edition(p)}.zip" Zip::File.open(File.join(options[:dir], archive_filename)).each do |entry| filepath = File.join(options[:dir], entry.name) if File.exist? filepath