Parent

Geokit::Geocoders::IpGeocoder

Provides geocoding based upon an IP address. The underlying web service is a hostip.info which sources their data through a combination of publicly available information as well as community contributions.

Constants

NON_ROUTABLE_IP_RANGES

A number of non-routable IP ranges.

— Sources for these:

  RFC 3330: Special-Use IPv4 Addresses
  The bogon list: http://www.cymru.com/Documents/bogon-list.html

Private Class Methods

do_geocode(ip, options = {}) click to toggle source

Given an IP address, returns a GeoLoc instance which contains latitude, longitude, city, and country code. Sets the success attribute to false if the ip parameter does not match an ip address.

     # File /Users/andre/projects/rails/geokit/lib/geokit/geocoders.rb, line 588
588:       def self.do_geocode(ip, options = {})
589:         return GeoLoc.new unless /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})?$/.match(ip)
590:         return GeoLoc.new if self.private_ip_address?(ip)
591:         url = "http://api.hostip.info/get_html.php?ip=#{ip}&position=true"
592:         response = self.call_geocoder_service(url)
593:         response.is_a?(Net::HTTPSuccess) ? parse_body(response.body) : GeoLoc.new
594:       rescue
595:         logger.error "Caught an error during HostIp geocoding call: "+$!
596:         return GeoLoc.new
597:       end
private_ip_address?(ip) click to toggle source

Checks whether the IP address belongs to a private address range.

This function is used to reduce the number of useless queries made to the geocoding service. Such queries can occur frequently during integration tests.

     # File /Users/andre/projects/rails/geokit/lib/geokit/geocoders.rb, line 625
625:       def self.private_ip_address?(ip)
626:         return NON_ROUTABLE_IP_RANGES.any? { |range| range.include?(ip) }
627:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.