Class: GeoDB
- Inherits:
-
Object
- Object
- GeoDB
- 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
-
.download ⇒ Boolean
Download the file from the GEOLITE url.
-
.perform(path) ⇒ Boolean
Begin creating folders and being downloadding the GeoLite db.
Class Method Details
.download ⇒ Boolean
Download the file from the GEOLITE url
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. if e. end |
.perform(path) ⇒ Boolean
Begin creating folders and being downloadding the GeoLite db
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.}" end |