geo_location 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in geo_location.gemspec
4
+ gemspec
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Chris Your
1
+ Copyright (c) 2010-2011 Chris Your
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -1,53 +1,2 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "geo_location"
8
- gem.summary = %Q{Geo-locate your users using their IP address via hostip.info or maxmind.com.}
9
- gem.description = %Q{Geo-locate your users using their IP address via hostip.info or maxmind.com.}
10
- gem.email = "chris@ignitionindustries.com"
11
- gem.homepage = "http://github.com/chrisyour/geo_location"
12
- gem.authors = ["Chris Your"]
13
- gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
- end
16
- Jeweler::GemcutterTasks.new
17
- rescue LoadError
18
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
- end
20
-
21
- require 'rake/testtask'
22
- Rake::TestTask.new(:test) do |test|
23
- test.libs << 'lib' << 'test'
24
- test.pattern = 'test/**/test_*.rb'
25
- test.verbose = true
26
- end
27
-
28
- begin
29
- require 'rcov/rcovtask'
30
- Rcov::RcovTask.new do |test|
31
- test.libs << 'test'
32
- test.pattern = 'test/**/test_*.rb'
33
- test.verbose = true
34
- end
35
- rescue LoadError
36
- task :rcov do
37
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
- end
39
- end
40
-
41
- task :test => :check_dependencies
42
-
43
- task :default => :test
44
-
45
- require 'rake/rdoctask'
46
- Rake::RDocTask.new do |rdoc|
47
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
-
49
- rdoc.rdoc_dir = 'rdoc'
50
- rdoc.title = "geo_location #{version}"
51
- rdoc.rdoc_files.include('README*')
52
- rdoc.rdoc_files.include('lib/**/*.rb')
53
- end
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/geo_location.gemspec CHANGED
@@ -1,61 +1,24 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "geo_location/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{geo_location}
8
- s.version = "0.4.0"
6
+ s.name = "geo_location"
7
+ s.version = GeoLocation::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Chris Your"]
10
+ s.email = ["chris@ignitionindustries.com"]
11
+ s.homepage = "http://github.com/chrisyour/geo_location"
12
+ s.summary = %q{Geo Location allows you to geo-locate your users using their IP address via hostip.info or maxmind.com.}
13
+ s.description = %q{Geo Location allows you to geo-locate your users using their IP address via hostip.info or maxmind.com. This Ruby gem is dead simple to use and configure. Checkout the README and post any issue (or pull requests) to us on GitHub.}
14
+
15
+ s.add_development_dependency "thoughtbot-shoulda"
16
+ s.add_development_dependency "nokogiri"
9
17
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Chris Your"]
12
- s.date = %q{2010-08-29}
13
- s.description = %q{Geo-locate your users using their IP address via hostip.info or maxmind.com.}
14
- s.email = %q{chris@ignitionindustries.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "geo_location.gemspec",
27
- "lib/geo_location.rb",
28
- "lib/geo_location/countries.rb",
29
- "lib/geo_location/countries.txt",
30
- "lib/geo_location/geo_location.rb",
31
- "lib/geo_location/setup.rb",
32
- "lib/geo_location/timezones.rb",
33
- "lib/geo_location/timezones.txt",
34
- "lib/geo_location/version.rb",
35
- "test/helper.rb",
36
- "test/test_geo_location.rb"
37
- ]
38
- s.homepage = %q{http://github.com/chrisyour/geo_location}
39
- s.rdoc_options = ["--charset=UTF-8"]
40
- s.require_paths = ["lib"]
41
- s.rubygems_version = %q{1.3.7}
42
- s.summary = %q{Geo-locate your users using their IP address via hostip.info or maxmind.com.}
43
- s.test_files = [
44
- "test/helper.rb",
45
- "test/test_geo_location.rb"
46
- ]
47
-
48
- if s.respond_to? :specification_version then
49
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
- s.specification_version = 3
18
+ s.rubyforge_project = "geo_location"
51
19
 
52
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
54
- else
55
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
56
- end
57
- else
58
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
59
- end
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
60
24
  end
61
-
@@ -1,6 +1,5 @@
1
1
  require 'net/http'
2
- require 'rexml/document'
3
- include REXML
2
+ require 'nokogiri'
4
3
 
5
4
  module GeoLocation
6
5
 
@@ -86,33 +85,24 @@ module GeoLocation
86
85
  # == Handle http response data from HostIP
87
86
  # xml formatted body
88
87
  def data_from_hostip_http_response(ip, body)
89
- xml = body
90
- location = REXML::Document.new(xml)
88
+ location = Nokogiri::HTML.parse(body)
91
89
 
92
- data = {}
93
-
94
- hostip = XPath.first( location, "//Hostip" )
90
+ hostip = location.at("hostip")
95
91
  return nil if hostip.nil?
96
92
 
97
- hostip.elements.each do |element|
98
- case element.name
99
- when 'name'
100
- data[:city] = element.text.split(', ')[0].titleize
101
- data[:region] = element.text.split(', ')[1]
102
- when 'countryAbbrev'
103
- data[:country_code] = element.text
104
- data[:country] = country(element.text)
105
- end
106
- end
93
+ data = {}
107
94
 
108
- coords = XPath.first( location, "//gml:Point" )
109
- coords.elements.each do |element|
110
- case element.name
111
- when 'coordinates'
112
- coordinates = element.text.split(',')
113
- data[:latitude] = coordinates[1]
114
- data[:longitude] = coordinates[0]
115
- end
95
+ element = hostip.at('name')
96
+ data[:city] = element.text.split(', ')[0].titleize
97
+ data[:region] = element.text.split(', ')[1]
98
+
99
+ element = hostip.at('countryabbrev')
100
+ data[:country_code] = element.text
101
+ data[:country] = country(element.text)
102
+
103
+ element = hostip.at( "point coordinates" )
104
+ if element
105
+ data[:longitude], data[:latitude] = element.text.split(',')
116
106
  end
117
107
 
118
108
  data[:ip] = ip
@@ -122,4 +112,4 @@ module GeoLocation
122
112
  end
123
113
 
124
114
  end
125
- end
115
+ end
@@ -18,7 +18,7 @@ module GeoLocation
18
18
  zones.each do |z|
19
19
  zone = z.split(" ")
20
20
  country = zone[0].to_sym
21
- region = zone[1].to_sym
21
+ region = zone[1].empty? ? '' : zone[1].to_sym
22
22
  value = zone[2]
23
23
 
24
24
  data[country] = {} if data[country].nil?
@@ -70,227 +70,6 @@ AU 05 Australia/South
70
70
  AU 06 Australia/Tasmania
71
71
  AU 07 Australia/Victoria
72
72
  AU 08 Australia/West
73
- AS US/Samoa
74
- CI Africa/Abidjan
75
- GH Africa/Accra
76
- DZ Africa/Algiers
77
- ER Africa/Asmera
78
- ML Africa/Bamako
79
- CF Africa/Bangui
80
- GM Africa/Banjul
81
- GW Africa/Bissau
82
- CG Africa/Brazzaville
83
- BI Africa/Bujumbura
84
- EG Africa/Cairo
85
- MA Africa/Casablanca
86
- GN Africa/Conakry
87
- SN Africa/Dakar
88
- DJ Africa/Djibouti
89
- SL Africa/Freetown
90
- BW Africa/Gaborone
91
- ZW Africa/Harare
92
- ZA Africa/Johannesburg
93
- UG Africa/Kampala
94
- SD Africa/Khartoum
95
- RW Africa/Kigali
96
- NG Africa/Lagos
97
- GA Africa/Libreville
98
- TG Africa/Lome
99
- AO Africa/Luanda
100
- ZM Africa/Lusaka
101
- GQ Africa/Malabo
102
- MZ Africa/Maputo
103
- LS Africa/Maseru
104
- SZ Africa/Mbabane
105
- SO Africa/Mogadishu
106
- LR Africa/Monrovia
107
- KE Africa/Nairobi
108
- TD Africa/Ndjamena
109
- NE Africa/Niamey
110
- MR Africa/Nouakchott
111
- BF Africa/Ouagadougou
112
- ST Africa/Sao_Tome
113
- LY Africa/Tripoli
114
- TN Africa/Tunis
115
- AI America/Anguilla
116
- AG America/Antigua
117
- AW America/Aruba
118
- BB America/Barbados
119
- BZ America/Belize
120
- CO America/Bogota
121
- VE America/Caracas
122
- KY America/Cayman
123
- CR America/Costa_Rica
124
- DM America/Dominica
125
- SV America/El_Salvador
126
- GD America/Grenada
127
- FR Europe/Paris
128
- GP America/Guadeloupe
129
- GT America/Guatemala
130
- GY America/Guyana
131
- CU America/Havana
132
- JM America/Jamaica
133
- BO America/La_Paz
134
- PE America/Lima
135
- NI America/Managua
136
- MQ America/Martinique
137
- UY America/Montevideo
138
- MS America/Montserrat
139
- BS America/Nassau
140
- PA America/Panama
141
- SR America/Paramaribo
142
- PR America/Puerto_Rico
143
- KN America/St_Kitts
144
- LC America/St_Lucia
145
- VC America/St_Vincent
146
- HN America/Tegucigalpa
147
- YE Asia/Aden
148
- JO Asia/Amman
149
- TM Asia/Ashgabat
150
- IQ Asia/Baghdad
151
- BH Asia/Bahrain
152
- AZ Asia/Baku
153
- TH Asia/Bangkok
154
- LB Asia/Beirut
155
- KG Asia/Bishkek
156
- BN Asia/Brunei
157
- IN Asia/Calcutta
158
- MN Asia/Choibalsan
159
- LK Asia/Colombo
160
- BD Asia/Dhaka
161
- AE Asia/Dubai
162
- TJ Asia/Dushanbe
163
- HK Asia/Hong_Kong
164
- TR Asia/Istanbul
165
- IL Asia/Jerusalem
166
- AF Asia/Kabul
167
- PK Asia/Karachi
168
- NP Asia/Katmandu
169
- KW Asia/Kuwait
170
- MO Asia/Macao
171
- PH Asia/Manila
172
- OM Asia/Muscat
173
- CY Asia/Nicosia
174
- KP Asia/Pyongyang
175
- QA Asia/Qatar
176
- MM Asia/Rangoon
177
- SA Asia/Riyadh
178
- KR Asia/Seoul
179
- SG Asia/Singapore
180
- TW Asia/Taipei
181
- GE Asia/Tbilisi
182
- BT Asia/Thimphu
183
- JP Asia/Tokyo
184
- LA Asia/Vientiane
185
- AM Asia/Yerevan
186
- BM Atlantic/Bermuda
187
- CV Atlantic/Cape_Verde
188
- FO Atlantic/Faeroe
189
- IS Atlantic/Reykjavik
190
- GS Atlantic/South_Georgia
191
- SH Atlantic/St_Helena
192
- CL Chile/Continental
193
- NL Europe/Amsterdam
194
- AD Europe/Andorra
195
- GR Europe/Athens
196
- YU Europe/Belgrade
197
- DE Europe/Berlin
198
- SK Europe/Bratislava
199
- BE Europe/Brussels
200
- RO Europe/Bucharest
201
- HU Europe/Budapest
202
- DK Europe/Copenhagen
203
- IE Europe/Dublin
204
- GI Europe/Gibraltar
205
- FI Europe/Helsinki
206
- SI Europe/Ljubljana
207
- GB Europe/London
208
- LU Europe/Luxembourg
209
- MT Europe/Malta
210
- BY Europe/Minsk
211
- MC Europe/Monaco
212
- NO Europe/Oslo
213
- CZ Europe/Prague
214
- LV Europe/Riga
215
- IT Europe/Rome
216
- SM Europe/San_Marino
217
- BA Europe/Sarajevo
218
- MK Europe/Skopje
219
- BG Europe/Sofia
220
- SE Europe/Stockholm
221
- EE Europe/Tallinn
222
- AL Europe/Tirane
223
- LI Europe/Vaduz
224
- VA Europe/Vatican
225
- AT Europe/Vienna
226
- LT Europe/Vilnius
227
- PL Europe/Warsaw
228
- HR Europe/Zagreb
229
- IR Asia/Tehran
230
- MG Indian/Antananarivo
231
- CX Indian/Christmas
232
- CC Indian/Cocos
233
- KM Indian/Comoro
234
- MV Indian/Maldives
235
- MU Indian/Mauritius
236
- YT Indian/Mayotte
237
- RE Indian/Reunion
238
- FJ Pacific/Fiji
239
- TV Pacific/Funafuti
240
- GU Pacific/Guam
241
- NR Pacific/Nauru
242
- NU Pacific/Niue
243
- NF Pacific/Norfolk
244
- PW Pacific/Palau
245
- PN Pacific/Pitcairn
246
- CK Pacific/Rarotonga
247
- WS Pacific/Samoa
248
- KI Pacific/Tarawa
249
- TO Pacific/Tongatapu
250
- WF Pacific/Wallis
251
- TZ Africa/Dar_es_Salaam
252
- VN Asia/Phnom_Penh
253
- KH Asia/Phnom_Penh
254
- CM Africa/Lagos
255
- DO America/Santo_Domingo
256
- ET Africa/Addis_Ababa
257
- FX Europe/Paris
258
- HT America/Port-au-Prince
259
- CH Europe/Zurich
260
- AN America/Curacao
261
- BJ Africa/Porto-Novo
262
- EH Africa/El_Aaiun
263
- FK Atlantic/Stanley
264
- GF America/Cayenne
265
- IO Indian/Chagos
266
- MD Europe/Chisinau
267
- MP Pacific/Saipan
268
- MW Africa/Blantyre
269
- NA Africa/Windhoek
270
- NC Pacific/Noumea
271
- PG Pacific/Port_Moresby
272
- PM America/Miquelon
273
- PS Asia/Gaza
274
- PY America/Asuncion
275
- SB Pacific/Guadalcanal
276
- SC Indian/Mahe
277
- SJ Arctic/Longyearbyen
278
- SY Asia/Damascus
279
- TC America/Grand_Turk
280
- TF Indian/Kerguelen
281
- TK Pacific/Fakaofo
282
- TT America/Port_of_Spain
283
- VG America/Tortola
284
- VI America/St_Thomas
285
- VU Pacific/Efate
286
- RS Europe/Belgrade
287
- ME Europe/Podgorica
288
- AX Europe/Mariehamn
289
- GG Europe/Guernsey
290
- IM Europe/Isle_of_Man
291
- JE Europe/Jersey
292
- BL America/St_Barthelemy
293
- MF America/Marigot
294
73
  AR 01 America/Argentina/Buenos_Aires
295
74
  AR 02 America/Argentina/Catamarca
296
75
  AR 03 America/Argentina/Tucuman
@@ -671,5 +450,3 @@ UZ 10 Asia/Samarkand
671
450
  UZ 12 Asia/Samarkand
672
451
  UZ 13 Asia/Tashkent
673
452
  UZ 14 Asia/Tashkent
674
- TL Asia/Dili
675
- PF Pacific/Marquesas
@@ -1,9 +1,3 @@
1
1
  module GeoLocation
2
- file = File.join(File.dirname(__FILE__), '../../VERSION' )
3
- File.open(file, "r") do |infile|
4
- while (line = infile.gets)
5
- VERSION = line.gsub(/\n/,"")
6
- break
7
- end
8
- end
2
+ VERSION = "0.4.1"
9
3
  end
@@ -145,4 +145,21 @@ class TestGeoLocation < Test::Unit::TestCase
145
145
 
146
146
  end
147
147
 
148
+ context 'on localhost' do
149
+
150
+ setup do
151
+ #GeoLocation::use = :hostip
152
+ GeoLocation::use = :maxmind
153
+ GeoLocation::key = 'sNHKg3eUWYoT'
154
+ GeoLocation::dev = nil
155
+ GeoLocation::dev_ip = nil
156
+ @location = GeoLocation.find('127.0.0.1')
157
+ end
158
+
159
+ should "not work properly" do
160
+ puts @location.inspect
161
+ assert_equal "nothing", @location[:city]
162
+ end
163
+ end
164
+
148
165
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 0
9
- version: 0.4.0
8
+ - 1
9
+ version: 0.4.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Chris Your
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-29 00:00:00 -06:00
17
+ date: 2011-01-20 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -30,18 +30,31 @@ dependencies:
30
30
  version: "0"
31
31
  type: :development
32
32
  version_requirements: *id001
33
- description: Geo-locate your users using their IP address via hostip.info or maxmind.com.
34
- email: chris@ignitionindustries.com
33
+ - !ruby/object:Gem::Dependency
34
+ name: nokogiri
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :development
45
+ version_requirements: *id002
46
+ description: Geo Location allows you to geo-locate your users using their IP address via hostip.info or maxmind.com. This Ruby gem is dead simple to use and configure. Checkout the README and post any issue (or pull requests) to us on GitHub.
47
+ email:
48
+ - chris@ignitionindustries.com
35
49
  executables: []
36
50
 
37
51
  extensions: []
38
52
 
39
- extra_rdoc_files:
40
- - LICENSE
41
- - README.rdoc
53
+ extra_rdoc_files: []
54
+
42
55
  files:
43
- - .document
44
56
  - .gitignore
57
+ - Gemfile
45
58
  - LICENSE
46
59
  - README.rdoc
47
60
  - Rakefile
@@ -62,8 +75,8 @@ homepage: http://github.com/chrisyour/geo_location
62
75
  licenses: []
63
76
 
64
77
  post_install_message:
65
- rdoc_options:
66
- - --charset=UTF-8
78
+ rdoc_options: []
79
+
67
80
  require_paths:
68
81
  - lib
69
82
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -84,11 +97,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
97
  version: "0"
85
98
  requirements: []
86
99
 
87
- rubyforge_project:
100
+ rubyforge_project: geo_location
88
101
  rubygems_version: 1.3.7
89
102
  signing_key:
90
103
  specification_version: 3
91
- summary: Geo-locate your users using their IP address via hostip.info or maxmind.com.
104
+ summary: Geo Location allows you to geo-locate your users using their IP address via hostip.info or maxmind.com.
92
105
  test_files:
93
106
  - test/helper.rb
94
107
  - test/test_geo_location.rb
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE