Locality
Postnummerservice
Installation
# Go and buy the rec2LK database from postnummerservice.se
# Put it in the ./db directory
Configuration
Locality.configure do |config|
config.postnummerfilen_path = '/some/custom/rec2LK.csv'
end
Usage
available_codes = Locality::Postnummerservice::Aregion.codes
lookup = Locality::Postnummerservice::Aregion.new 21
available_codes = Locality::Postnummerservice::State.codes
lookup = Locality::Postnummerservice::State.new 7
available_codes = Locality::Postnummerservice::Province.codes
lookup = Locality::Postnummerservice::Province.new '0182'
lookup = Locality::Postnummerservice::ZipCode.new '11417'
lookup.code
lookup.name
lookup.zip_codes
lookup.city_names
lookup.state_codes
lookup.state_names
lookup.province_code
lookup.province_names
lookup.aregion_codes
IP Lookup
Installation
# Get the libmaxminddb, e.g. via homebrew on Mac OS
brew install libmaxminddb
# Tell bundler where to find it
bundle config build.hive_geoip2 --with-opt-dir=$(brew --prefix)
# Download and extract the MaxMind GeoIp2 database
curl http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz -o ./db && gunzip ./db/GeoLite2-City.mmdb.gz
Configuration
Locality.configure do |config|
config.maxmind_geoip2_path = '/some/custom/maxmind_geolite2.mmdb'
config.add_custom_ip_location '198.51.100.99/24', city_name: 'Main Office', country_name: 'Australia'
end
Usage
Locality::IP.check!
lookup = Locality::IP.new '198.51.100.55'
lookup.ip
lookup.city_name
lookup.province_name
lookup.state_name
lookup.country_name
lookup.human_readable_name
lookup.to_hash