Sha256: 71643109b570e38296f63ceaa96e62806e3774ba15eac1009055d1aff90f7ea4

Contents?: true

Size: 792 Bytes

Versions: 1

Compression:

Stored size: 792 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, _=nil)
        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.11.0 lib/geokit/geocoders/free_geo_ip.rb