DefV-geokit-geoip-provider 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README +18 -0
  2. data/lib/geokit-geoip-provider.rb +32 -0
  3. metadata +55 -0
data/README ADDED
@@ -0,0 +1,18 @@
1
+ == GeoKit GeoIP Provider
2
+
3
+ === Install
4
+ gem install DefV-geokit-geoip-provider
5
+
6
+ === Setup
7
+
8
+ ==== Rails
9
+ config.gem 'DefV-geokit-geoip-provider', :lib => 'geokit-geoip-provider'
10
+
11
+ Download and unzip a recent GeoCity database from http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
12
+
13
+ Add GeoIp as a ip_address provider:
14
+
15
+ GeoKit::Geocoders.ip_provider_order.unshift :geo_ip
16
+ GeoKit::Geocoders.geo_ip_database = RAILS_ROOT + "/lib/ext/GeoLiteCity.dat" # or the path you downloaded your geocity database
17
+
18
+ And you can start using the GeoIp geocoder
@@ -0,0 +1,32 @@
1
+ require 'geokit'
2
+ require 'geoip'
3
+
4
+ module Geokit
5
+ module Geocoders
6
+
7
+ # Should be overriden as Geokit::Geocoders::external_key in your configuration file
8
+ @@geo_ip_database = 'REPLACE_WITH_GEOCITY_LOCATION'
9
+ __define_accessors
10
+
11
+ class GeoIpGeocoder < Geocoder
12
+ private
13
+ def self.db
14
+ @@db ||= GeoIP.new(Geocoders.geo_ip_database)
15
+ end
16
+
17
+ def self.do_geocode(address, options = {})
18
+ ip, ip2, country_code, country_code2, country, continent, region, city, postal, latitude, longitude, usa = db.city(address)
19
+
20
+ res = GeoLoc.new
21
+ res.city = city
22
+ res.country_code = country_code
23
+ res.zip = postal
24
+ res.lat = latitude
25
+ res.lng = longitude
26
+
27
+ res
28
+ end
29
+ end
30
+
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: DefV-geokit-geoip-provider
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Jan De Poorter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-16 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: geokit@defv.be
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ files:
25
+ - README
26
+ - lib/geokit-geoip-provider.rb
27
+ has_rdoc: false
28
+ homepage: http://workswithruby.com
29
+ licenses:
30
+ post_install_message:
31
+ rdoc_options: []
32
+
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: "0"
40
+ version:
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ requirements: []
48
+
49
+ rubyforge_project:
50
+ rubygems_version: 1.3.5
51
+ signing_key:
52
+ specification_version: 2
53
+ summary: GeoIP provider for geokit gem
54
+ test_files: []
55
+