Module: IPGeolocation
- Defined in:
- lib/ipgeolocation.rb
Overview
to its credit, blogama seems to be very, very accurate.
Defined Under Namespace
Classes: BlogamaLocator, HostIPLocator, Location, NetGeoLocator
Constant Summary collapse
- VERSION =
'0.1.0'
- ACCEPTABLE_LOCATORS =
[:blogama, :netgeo, :hostip]
- RESULT_FIELDS =
Fields you can get from the different services
[:ip, :country_code, :country_name, :region_code, :region_name, :city, :postal_code, :latitude, :longitude]
Class Method Summary collapse
-
.locate(ip, locator) ⇒ Object
Main Location thread.
Class Method Details
.locate(ip, locator) ⇒ Object
Main Location thread. You must choose from one of the available location services. In future versions this will support a local database.
Available locators:
[:blogama] The Blogama IP database - highly accurate
[:netgeo] Netgeo, a legacy IP geolocation service. Doesn't offer zip-codes.
[:hostip] Hostip.info - this is a newer location service, but coverage is somewhat spotty.
Usage:
IPgeolocation.locate("12.345.678.90", :blogama)
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ipgeolocation.rb', line 35 def locate(ip, locator) raise ArgumentError.new("Invalid locator: #{locator}") unless ACCEPTABLE_LOCATORS.include?(locator) klass = case locator when :blogama IPGeolocation::BlogamaLocator when :netgeo IPGeolocation::NetGeoLocator when :hostip IPGeolocation::HostIPLocator end klass.locate(ip) end |