Sha256: d9c57dea29822593be1e11d29188167f4242db642df13944c37d6fa07ca4eee2
Contents?: true
Size: 1.03 KB
Versions: 2
Compression:
Stored size: 1.03 KB
Contents
module Geokit module Geocoders # Provides geocoding based upon an IP address. The underlying web service is geoplugin.net class RipeGeocoder < Geocoder private def self.do_geocode(ip, options = {}) return GeoLoc.new unless /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})?$/.match(ip) response = self.call_geocoder_service("http://stat.ripe.net/data/geoloc/data.json?resource=#{ip}") return response.is_a?(Net::HTTPSuccess) ? parse_json(response.body) : GeoLoc.new rescue logger.error "Caught an error during GeoPluginGeocoder geocoding call: #{$!}" return GeoLoc.new end def self.parse_json(json) json = MultiJson.load(json) geo = GeoLoc.new data = json['data']['locations'][0] geo.provider='RIPE' geo.city = data['city'] geo.country_code = data['country'] geo.lat = data['latitude'] geo.lng = data['longitude'] geo.success = (data['status_code'] == 200) return geo end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
geokit-1.7.1 | lib/geokit/services/ripe.rb |
geokit-1.7.0 | lib/geokit/services/ripe.rb |