Class: GeoDB

Inherits:
Object
  • Object
show all
Defined in:
lib/kowl/geodb.rb

Overview

Used for fetching the GeoLite db from maxmind

Constant Summary collapse

GEOLITE_URL =
'http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz'

Class Method Summary collapse

Class Method Details

.downloadBoolean

Download the file from the GEOLITE url

Returns:

  • (Boolean)

    returns if the the file was succcessfully downloaded



30
31
32
33
34
35
36
37
38
39
# File 'lib/kowl/geodb.rb', line 30

def self.download
  FileUtils.rm_f GEOLIB_PATH
  res = Net::HTTP.get_response(URI.parse(GEOLITE_URL))
  File.open(GEOLIB_PATH, 'wb') do |f|
    f.write(res.body)
  end
rescue => e
  puts 'GeoLite2 database could not be downloaded at this time.'
  puts e.message if e.message
end

.perform(path) ⇒ Boolean

Begin creating folders and being downloadding the GeoLite db

Parameters:

  • path (String)

    the applications relative path

Returns:

  • (Boolean)

    if the GeoLite2 database was successfully downloaded and decompressed



17
18
19
20
21
22
23
24
25
26
# File 'lib/kowl/geodb.rb', line 17

def self.perform(path)
  const_set('GEOLIB_DIR', File.join(path, 'db/maxmind'))
  const_set('GEOLIB_PATH', File.join(GEOLIB_DIR, 'GeoLite2-City.tar.gz'))

  FileUtils.mkdir_p GEOLIB_DIR
  download
  extract
rescue => e
  puts "Error while setting up GeoLite DB - #{e.message}"
end