Sha256: 25222b71061042c9728e5bec655acb4b754243dfb5a84944b82b978c2f94d0eb
Contents?: true
Size: 1.11 KB
Versions: 6
Compression:
Stored size: 1.11 KB
Contents
require 'yaml' module Graticule #:nodoc: module Geocoder #:nodoc: class HostIp < Base def initialize @url = URI.parse 'http://api.hostip.info/get_html.php' end # Geocode an IP address using http://hostip.info def locate(address) get :ip => address, :position => true end private def prepare_response(response) # add new line so YAML.load doesn't puke YAML.load(response + "\n") end def parse_response(parse_type, response) #:nodoc: returning Location.new do |location| location.latitude = response['Latitude'] location.longitude = response['Longitude'] location.locality, location.region = response['City'].split(', ') country = response['Country'].match(/\((\w+)\)$/) location.country = country[1] if country end end def check_error(response) #:nodoc: raise AddressError, 'Unknown' if response['City'] =~ /Unknown City/ raise AddressError, 'Private Address' if response['City'] =~ /Private Address/ end end end end
Version data entries
6 entries across 6 versions & 2 rubygems