gem install geolocater
Pass any properly formatted IPv4 address string to a new instance of Geolocater like so.
Geolocater.geolocate_ip(IP_ADDRESS_STRING)
and get back a JSON Hash of the results
=> {"city"=>"CITY", "region_code"=>"ST", "region_name"=>"Region Name", "metrocode"=>"999", "zipcode"=>"98765", "longitude"=>"-92.23", "country_name"=>"United States", "country_code"=>"US", "ip"=>"IP_ADDRESS", "latitude"=>"27.54"}
- This library uses the free (and very good) freegeoip.net REST API.
- Results are returned in JSON format. For friendlier Ruby object-like results (and better nil handling), pipe the result hash into a new Hashie::Mash like so:
Hashie::Mash.new(Geolocater.ip_lookup(IP_ADDRESS_STRING))
- Add multiple geolocation services in the event the freegeoip service goes down
- Suggest additional tests/refactoring
- Submit a pull request