Sha256: fe0f5a08ff89f10088944b44f0392e0b0b17e943f493809d7ac5e394250e6a13
Contents?: true
Size: 977 Bytes
Versions: 2
Compression:
Stored size: 977 Bytes
Contents
module Geokit module Geocoders # Provides geocoding based upon an IP address. The underlying web service is geoplugin.net class GeoPluginGeocoder < BaseIpGeocoder private def self.do_geocode(ip) return GeoLoc.new unless valid_ip?(ip) url = "http://www.geoplugin.net/xml.gp?ip=#{ip}" res = call_geocoder_service(url) return GeoLoc.new if !res.is_a?(Net::HTTPSuccess) parse :xml, res.body end XML_MAPPINGS = { :city => 'geoplugin_city', :state => 'geoplugin_region', :country_code => 'geoplugin_countryCode', :lat => 'geoplugin_latitude', :lng => 'geoplugin_longitude' } def self.parse_xml(xml) loc = GeoLoc.new loc.provider = 'geoPlugin' set_mappings(loc, xml.elements['geoPlugin'], XML_MAPPINGS) loc.success = !!loc.city && !loc.city.empty? loc end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
geokit-1.8.1 | lib/geokit/geocoders/geo_plugin.rb |
geokit-1.8.0 | lib/geokit/geocoders/geo_plugin.rb |