geokit-geoip-provider 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +18 -0
- data/lib/geokit-geoip-provider.rb +33 -0
- metadata +68 -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,33 @@
|
|
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.state = region
|
23
|
+
res.country_code = country_code
|
24
|
+
res.zip = postal
|
25
|
+
res.lat = latitude
|
26
|
+
res.lng = longitude
|
27
|
+
res.success = !!(res.lat && res.lng)
|
28
|
+
res
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: geokit-geoip-provider
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jan De Poorter
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-09-21 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description:
|
23
|
+
email: geokit@defv.be
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README
|
30
|
+
files:
|
31
|
+
- README
|
32
|
+
- lib/geokit-geoip-provider.rb
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://workswithruby.com
|
35
|
+
licenses: []
|
36
|
+
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
hash: 3
|
48
|
+
segments:
|
49
|
+
- 0
|
50
|
+
version: "0"
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.5.0
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: GeoIP provider for geokit gem
|
67
|
+
test_files: []
|
68
|
+
|