# Go and buy the rec2LK database from postnummerservice.se# Put it in the ./db directory
Configuration
Locality.configuredo |config|
# By default, locality will look for the rec2LK database in# these locations: `Locality.config.postnummerfilen_paths`# You can add a custom location like so:config.postnummerfilen_path='/some/custom/rec2LK.csv'end
Usage
# A-Regions# See https://sv.wikipedia.org/wiki/A-regionavailable_codes=Locality::Postnummerservice::Aregion.codeslookup=Locality::Postnummerservice::Aregion.new21# Gotland# States# See https://sv.wikipedia.org/wiki/Sveriges_l%C3%A4navailable_codes=Locality::Postnummerservice::State.codeslookup=Locality::Postnummerservice::State.new7# Kronoberg# Provinces# See https://sv.wikipedia.org/wiki/Sveriges_l%C3%A4navailable_codes=Locality::Postnummerservice::Province.codeslookup=Locality::Postnummerservice::Province.new'0182'# Nacka# Zip Codes# See https://sv.wikipedia.org/wiki/Postnummer_i_Sverigelookup=Locality::Postnummerservice::ZipCode.new'11417'# Stockholm# On all of the above lookups you have the following attributeslookup.codelookup.namelookup.zip_codeslookup.city_nameslookup.state_codeslookup.state_nameslookup.province_codelookup.province_nameslookup.aregion_codes# More to come...
IP Lookup
Installation
# Get the libmaxminddb, e.g. via homebrew on Mac OS
brew install libmaxminddb
# 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.configuredo |config|
# By default, locality will look for the maxmind database in# these locations: `Locality.config.maxmind_geoip2_paths`# You can add a custom location like so:config.maxmind_geoip2_path='/some/custom/maxmind_geolite2.mmdb'# If you want, you can add custom lookups like so:config.add_custom_ip_location'198.51.100.99/24',city_name: 'Main Office',country_name: 'Australia'end
Usage
# If you want to make sure on application# bootup that everything works, call this method:Locality::IP.check!# Lookup an IPlookup=Locality::IP.new'198.51.100.55'# All these attributes return either a String or nil.lookup.iplookup.city_namelookup.province_namelookup.state_namelookup.country_namelookup.human_readable_name# Get them all combined in a Hashlookup.to_hash
About
A thin abstraction of databases provided by maxmind.com and postnummerservice.se