class RequestInfo::GeoIP

Brigdes MaxmindGeoIP2.

Examples: RequestInfo::GeoIP.instance.lookup('116.49.226.82') RequestInfo::GeoIP.instance.lookup('24.24.24.24')

Attributes

database[RW]

Public Class Methods

new() click to toggle source

Sets up the GeoIPCity database for upcoming queries

# File lib/request_info/geoip.rb, line 20
def initialize
  unless geoip2_db_path.nil?
    ensure_maxmind_geoip2_availability
    self.database = setup_database
  end
end

Public Instance Methods

ensure_maxmind_geoip2_availability() click to toggle source
# File lib/request_info/geoip.rb, line 44
def ensure_maxmind_geoip2_availability
  MaxmindGeoIP2
rescue LoadError
  raise "RequestInfo requires maxmind_geoip2 gem for GeoIP2 database " +
    "lookup. Refer to README for configuration details."
end
geoip2_db_path() click to toggle source
# File lib/request_info/geoip.rb, line 40
def geoip2_db_path
  RequestInfo.configuration.geoip2_db_path
end
lookup(ip) click to toggle source

Looks up the specified IP address (string) and returns information about the IP address.

# File lib/request_info/geoip.rb, line 35
def lookup(ip)
  return nil if database.nil? || ip.blank?
  database.locate(ip)
end
setup_database() click to toggle source
# File lib/request_info/geoip.rb, line 27
def setup_database
  MaxmindGeoIP2.file(geoip2_db_path)
  MaxmindGeoIP2.locale("en")
  MaxmindGeoIP2
end