Class: Embargoed::IPLocator
- Inherits:
-
Object
- Object
- Embargoed::IPLocator
- Defined in:
- lib/embargoed/ip_locator.rb
Class Method Summary collapse
Class Method Details
.get_country_code(ip) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/embargoed/ip_locator.rb', line 6 def self.get_country_code(ip) country_code = "none" # Using an Open-Source IP db released under an Apache2 license: https://github.com/geoacumen/geoacumen-country db = File.("../../../public/Geoacumen-Country.mmdb", __FILE__) reader = MaxMind::DB.new(db, mode: MaxMind::DB::MODE_MEMORY) begin record = reader.get(ip) rescue => error puts error.inspect end if !record.nil? country_code = record['country']['iso_code'] end reader.close return country_code end |