Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: a02c230cca
...
compare: 4c437fa054
  • 5 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 23 additions and 17 deletions.
  1. +6 −6 geokit-geoip-provider.gemspec
  2. +17 −11 lib/geokit-geoip-provider.rb
View
12 geokit-geoip-provider.gemspec
@@ -1,15 +1,15 @@
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = "geokit-geoip-provider"
- s.version = "0.2.1"
- s.author = "Jan De Poorter"
- s.email = "geokit@defv.be"
- s.homepage = "http://workswithruby.com"
+ s.version = "0.3.0"
+ s.authors = ["Jan De Poorter", "Todd Eichel"]
+ s.email = ["geokit@defv.be", "todd@toddeichel.com"]
+ s.homepage = "https://github.com/tfe/geokit-geoip-provider"
s.summary = "GeoIP provider for geokit gem"
s.files = %w(README lib/geokit-geoip-provider.rb)
s.require_path = "lib"
s.has_rdoc = false
s.extra_rdoc_files = ["README"]
+ s.add_dependency('geokit', '~> 1.5.0')
+ s.add_dependency('geoip', '~> 1.1.1')
end
-
-
View
28 lib/geokit-geoip-provider.rb
@@ -4,7 +4,7 @@
module Geokit
module Geocoders
- # Should be overriden as Geokit::Geocoders::external_key in your configuration file
+ # Should be overriden as Geokit::Geocoders::geo_ip_database in your configuration file
@@geo_ip_database = 'REPLACE_WITH_GEOCITY_LOCATION'
__define_accessors
@@ -15,17 +15,23 @@ def self.db
end
def self.do_geocode(address, options = {})
- ip, ip2, country_code, country_code2, country, continent, region, city, postal, latitude, longitude, usa = db.city(address)
+ city = db.city(address)
+ return GeoLoc.new if not city
- res = GeoLoc.new
- res.city = city
- res.state = region
- res.country_code = country_code
- res.zip = postal
- res.lat = latitude
- res.lng = longitude
- res.success = !!(res.lat && res.lng)
- res
+ GeoLoc.new.tap do |gl|
+ gl.provider = 'geoip'
+ gl.city = city.city_name
+ gl.state = city.region_name
+ gl.zip = city.postal_code
+ gl.country_code = city.country_code2
+ gl.lng = city.longitude.to_f
+ gl.lat = city.latitude.to_f
+ gl.success = !!gl.city && !gl.city.empty?
+ end
+
+ rescue
+ logger.error "Caught an error during GeoIp geocoding call: "+$!
+ return GeoLoc.new
end
end

No commit comments for this range

Something went wrong with that request. Please try again.