Sha256: d47d006d153b6c4c85b12af8d86b679dc15b4c702493a4fdd4132049ebe39833

Contents?: true

Size: 554 Bytes

Versions: 4

Compression:

Stored size: 554 Bytes

Contents

require 'zlib'
require 'open-uri'

namespace :georedirect do
  DB_URI = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz'

  desc "Fetches an updated copy of the GeoIP countries DB from MaxMind"
  task :fetch_db do
    # Fetches DB copy and gunzips it
    # Thx http://stackoverflow.com/a/2014317/107085
    source = open(DB_URI)
    gz = Zlib::GzipReader.new(source)
    result = gz.read

    # Write to file
    filename = Rails.root.join('db', 'GeoIP.dat')
    File.open(filename, 'w') { |f| f.write(result) }
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
geo_redirect-0.2.4 lib/tasks/geo_redirect.rb
geo_redirect-0.2.3 lib/tasks/geo_redirect.rb
geo_redirect-0.2.2 lib/tasks/geo_redirect.rb
geo_redirect-0.2.1 lib/tasks/geo_redirect.rb