Sha256: 5ae5f46a68fcd9b39e17866109e472f60b71d10199bce4df3db022a6792ff90a

Contents?: true

Size: 778 Bytes

Versions: 4

Compression:

Stored size: 778 Bytes

Contents

module Geokit
  module Geocoders
    # Provides geocoding based upon an IP address.  The underlying web service is ip-api.com
    class IpApiGeocoder < BaseIpGeocoder
      private

      def self.do_geocode(ip, _=nil)
        process :json, ip
      end

      def self.submit_url(ip)
        "http://ip-api.com/json/#{ip}"
      end

      def self.parse_json(result)
        loc = new_loc
        return loc unless result['status'] == 'success'

        loc.success = true
        loc.city = result['city']
        loc.state = result['region']
        loc.state_name = result['regionName']
        loc.zip = result['zip']
        loc.lat = result['lat']
        loc.lng = result['lon']
        loc.country_code = result['countryCode']
        loc
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
geokit-1.14.0 lib/geokit/geocoders/ip_api_geocoder.rb
geokit-1.13.1 lib/geokit/geocoders/ip_api_geocoder.rb
geokit-1.13.0 lib/geokit/geocoders/ip_api_geocoder.rb
geokit-1.12.0 lib/geokit/geocoders/ip_api_geocoder.rb