Sha256: 9eeff34c8d6e03ad04532ce08f41554ca083c622ff8b4a1b02286e41d96964c1

Contents?: true

Size: 785 Bytes

Versions: 1

Compression:

Stored size: 785 Bytes

Contents

module Geokit
  module Geocoders
    # Provides geocoding based upon an IP address.  The underlying web service is freegeoip.net
    class FreeGeoIpGeocoder < BaseIpGeocoder
      private

      def self.do_geocode(ip)
        process :xml, ip
      end

      def self.submit_url(ip)
        "http://freegeoip.net/xml/#{ip}"
      end

      XML_MAPPINGS = {
        city:         "City",
        state:        "RegionCode",
        zip:          "ZipCode",
        country_code: "CountryCode",
        lat:          "Latitude",
        lng:          "Longitude",
      }

      def self.parse_xml(xml)
        loc = new_loc
        set_mappings(loc, xml.elements["Response"], XML_MAPPINGS)
        loc.success = !!loc.city && !loc.city.empty?
        loc
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
geokit-1.10.0 lib/geokit/geocoders/free_geo_ip.rb