lib/rack/geo_locale.rb in rack-geo-locale-0.0.7 vs lib/rack/geo_locale.rb in rack-geo-locale-0.0.8

- old
+ new

@@ -31,11 +31,15 @@ def parse_country(env) if database? if remote_addr = env["REMOTE_ADDR"] remote_addr = env["HTTP_X_FORWARDED_FOR"] if env["HTTP_X_FORWARDED_FOR"] - result = geoip.country(remote_addr).country_code2 + begin + result = geoip.country(remote_addr).country_code2 + rescue Exception => e + puts "WARNING: .country raised an exception #{e}" + end return result if result != "--" else puts "WARNING: Didn't find env['REMOTE_ADDR']" end @@ -66,14 +70,11 @@ def fetch_database if ENV["GEOIP_DATABASE_URI"] puts "-> Fetching #{ENV["GEOIP_DATABASE_URI"]}" - open(ENV["GEOIP_DATABASE_URI"]) do |src| - data = Zlib::GzipReader.new(StringIO.new(src.read)).read - - open(DATABASE, "wb") {|dst| dst.write(data)} - end + `curl --silent -o #{DATABASE}.gz #{ENV["GEOIP_DATABASE_URI"]}` + `gunzip #{DATABASE}.gz` else puts "WARNING: Set the ENV['GEOIP_DATABASE_URI'] to the location of your .gz database file." end end