geocoder 1.1.6 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of geocoder might be problematic. Click here for more details.

Files changed (48) hide show
  1. data/CHANGELOG.md +15 -1
  2. data/README.md +82 -2
  3. data/examples/autoexpire_cache_dalli.rb +62 -0
  4. data/examples/{autoexpire_cache.rb → autoexpire_cache_redis.rb} +4 -4
  5. data/lib/generators/geocoder/config/templates/initializer.rb +1 -1
  6. data/lib/geocoder.rb +1 -1
  7. data/lib/geocoder/cache.rb +4 -0
  8. data/lib/geocoder/calculations.rb +33 -1
  9. data/lib/geocoder/lookup.rb +2 -0
  10. data/lib/geocoder/lookups/base.rb +10 -10
  11. data/lib/geocoder/lookups/esri.rb +52 -0
  12. data/lib/geocoder/lookups/mapquest.rb +1 -1
  13. data/lib/geocoder/lookups/maxmind.rb +19 -3
  14. data/lib/geocoder/lookups/ovi.rb +52 -0
  15. data/lib/geocoder/lookups/test.rb +6 -0
  16. data/lib/geocoder/lookups/yahoo.rb +4 -2
  17. data/lib/geocoder/query.rb +4 -4
  18. data/lib/geocoder/request.rb +1 -1
  19. data/lib/geocoder/results/esri.rb +51 -0
  20. data/lib/geocoder/results/google.rb +28 -0
  21. data/lib/geocoder/results/mapquest.rb +1 -1
  22. data/lib/geocoder/results/maxmind.rb +4 -5
  23. data/lib/geocoder/results/ovi.rb +62 -0
  24. data/lib/geocoder/results/test.rb +2 -1
  25. data/lib/geocoder/results/yandex.rb +12 -2
  26. data/lib/geocoder/stores/active_record.rb +38 -16
  27. data/lib/geocoder/stores/mongo_base.rb +2 -1
  28. data/lib/geocoder/version.rb +1 -1
  29. data/test/calculations_test.rb +6 -0
  30. data/test/fixtures/esri_madison_square_garden +59 -0
  31. data/test/fixtures/esri_no_results +8 -0
  32. data/test/fixtures/esri_reverse +21 -0
  33. data/test/fixtures/maxmind_24_24_24_21 +1 -1
  34. data/test/fixtures/maxmind_24_24_24_22 +1 -1
  35. data/test/fixtures/maxmind_24_24_24_23 +1 -1
  36. data/test/fixtures/maxmind_24_24_24_24 +1 -1
  37. data/test/fixtures/ovi_madison_square_garden +72 -0
  38. data/test/fixtures/ovi_no_results +8 -0
  39. data/test/fixtures/yandex_no_city_and_town +112 -0
  40. data/test/lookup_test.rb +1 -0
  41. data/test/near_test.rb +32 -0
  42. data/test/query_test.rb +5 -0
  43. data/test/request_test.rb +29 -0
  44. data/test/result_test.rb +9 -0
  45. data/test/services_test.rb +59 -5
  46. data/test/test_helper.rb +1 -1
  47. data/test/test_mode_test.rb +32 -23
  48. metadata +15 -3
data/test/result_test.rb CHANGED
@@ -12,6 +12,15 @@ class ResultTest < Test::Unit::TestCase
12
12
  end
13
13
  end
14
14
 
15
+ def test_yandex_result_without_city_does_not_raise_exception
16
+ assert_nothing_raised do
17
+ Geocoder.configure(:lookup => :yandex)
18
+ set_api_key!(:yandex)
19
+ result = Geocoder.search("no city and town").first
20
+ assert_equal "", result.city
21
+ end
22
+ end
23
+
15
24
 
16
25
  private # ------------------------------------------------------------------
17
26
 
@@ -17,6 +17,12 @@ class ServicesTest < Test::Unit::TestCase
17
17
  result.address_components_of_type(:route).first['long_name']
18
18
  end
19
19
 
20
+ def test_google_result_components_contains_street_number
21
+ result = Geocoder.search("Madison Square Garden, New York, NY").first
22
+ assert_equal "4",
23
+ result.address_components_of_type(:street_number).first['long_name']
24
+ end
25
+
20
26
  def test_google_returns_city_when_no_locality_in_result
21
27
  result = Geocoder.search("no locality").first
22
28
  assert_equal "Haram", result.city
@@ -27,6 +33,11 @@ class ServicesTest < Test::Unit::TestCase
27
33
  assert_equal nil, result.city
28
34
  end
29
35
 
36
+ def test_google_street_address_returns_formatted_street_address
37
+ result = Geocoder.search("Madison Square Garden, New York, NY").first
38
+ assert_equal "4 Penn Plaza", result.street_address
39
+ end
40
+
30
41
  def test_google_precision
31
42
  result = Geocoder.search("Madison Square Garden, New York, NY").first
32
43
  assert_equal "ROOFTOP",
@@ -160,27 +171,27 @@ class ServicesTest < Test::Unit::TestCase
160
171
  end
161
172
 
162
173
  def test_maxmind_result_knows_country_service_name
163
- Geocoder.configure(:ip_lookup => :maxmind)
174
+ Geocoder.configure(:ip_lookup => :maxmind, :maxmind => {:service => :country})
164
175
  assert_equal :country, Geocoder.search("24.24.24.21").first.service_name
165
176
  end
166
177
 
167
178
  def test_maxmind_result_knows_city_service_name
168
- Geocoder.configure(:ip_lookup => :maxmind)
179
+ Geocoder.configure(:ip_lookup => :maxmind, :maxmind => {:service => :city})
169
180
  assert_equal :city, Geocoder.search("24.24.24.22").first.service_name
170
181
  end
171
182
 
172
183
  def test_maxmind_result_knows_city_isp_org_service_name
173
- Geocoder.configure(:ip_lookup => :maxmind)
184
+ Geocoder.configure(:ip_lookup => :maxmind, :maxmind => {:service => :city_isp_org})
174
185
  assert_equal :city_isp_org, Geocoder.search("24.24.24.23").first.service_name
175
186
  end
176
187
 
177
188
  def test_maxmind_result_knows_omni_service_name
178
- Geocoder.configure(:ip_lookup => :maxmind)
189
+ Geocoder.configure(:ip_lookup => :maxmind, :maxmind => {:service => :omni})
179
190
  assert_equal :omni, Geocoder.search("24.24.24.24").first.service_name
180
191
  end
181
192
 
182
193
  def test_maxmind_special_result_components
183
- Geocoder.configure(:ip_lookup => :maxmind)
194
+ Geocoder.configure(:ip_lookup => :maxmind, :maxmind => {:service => :omni})
184
195
  result = Geocoder.search("24.24.24.24").first
185
196
  assert_equal "Road Runner", result.isp_name
186
197
  assert_equal "Cable/DSL", result.netspeed
@@ -263,4 +274,47 @@ class ServicesTest < Test::Unit::TestCase
263
274
  assert_equal "46 West 31st Street, New York, NY, 10001, US",
264
275
  result.address
265
276
  end
277
+
278
+ # --- Esri ---
279
+
280
+ def test_esri_query_for_geocode
281
+ query = Geocoder::Query.new("Bluffton, SC")
282
+ lookup = Geocoder::Lookup.get(:esri)
283
+ res = lookup.query_url(query)
284
+ assert_equal "http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find?f=pjson&outFields=%2A&text=Bluffton%2C+SC",
285
+ res
286
+ end
287
+
288
+ def test_esri_query_for_reverse_geocode
289
+ query = Geocoder::Query.new([45.423733, -75.676333])
290
+ lookup = Geocoder::Lookup.get(:esri)
291
+ res = lookup.query_url(query)
292
+ assert_equal "http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode?location=-75.676333%2C45.423733&outFields=%2A&p=pjson",
293
+ res
294
+ end
295
+
296
+ def test_esri_results_component
297
+ Geocoder.configure(:lookup => :esri)
298
+ result = Geocoder.search("Madison Square Garden, New York, NY").first
299
+ assert_equal "10001", result.postal_code
300
+ assert_equal "USA", result.country
301
+ assert_equal "Madison Square Garden", result.address
302
+ assert_equal "New York", result.city
303
+ assert_equal "New York", result.state
304
+ assert_equal 40.75004981300049, result.coordinates[0]
305
+ assert_equal -73.99423889799965, result.coordinates[1]
306
+ end
307
+
308
+ def test_esri_results_component_when_reverse_geocoding
309
+ Geocoder.configure(:lookup => :esri)
310
+ result = Geocoder.search([45.423733, -75.676333]).first
311
+ assert_equal "75007", result.postal_code
312
+ assert_equal "FRA", result.country
313
+ assert_equal "4 Avenue Gustave Eiffel", result.address
314
+ assert_equal "Paris", result.city
315
+ assert_equal "Île-de-France", result.state
316
+ assert_equal 48.858129997357558, result.coordinates[0]
317
+ assert_equal 2.2956200048981574, result.coordinates[1]
318
+ end
319
+
266
320
  end
data/test/test_helper.rb CHANGED
@@ -239,7 +239,7 @@ end
239
239
  class Test::Unit::TestCase
240
240
 
241
241
  def setup
242
- Geocoder.configure(:maxmind => {:service => :omni})
242
+ Geocoder.configure(:maxmind => {:service => :city_isp_org})
243
243
  end
244
244
 
245
245
  def teardown
@@ -13,8 +13,39 @@ class TestModeTest < Test::Unit::TestCase
13
13
  end
14
14
 
15
15
  def test_search_with_known_stub
16
+ Geocoder::Lookup::Test.add_stub("New York, NY", [mock_attributes])
17
+
18
+ results = Geocoder.search("New York, NY")
19
+ result = results.first
20
+
21
+ assert_equal 1, results.size
22
+ mock_attributes.keys.each do |attr|
23
+ assert_equal mock_attributes[attr], result.send(attr)
24
+ end
25
+ end
26
+
27
+ def test_search_with_unknown_stub_without_default
28
+ assert_raise ArgumentError do
29
+ Geocoder.search("New York, NY")
30
+ end
31
+ end
32
+
33
+ def test_search_with_unknown_stub_with_default
34
+ Geocoder::Lookup::Test.set_default_stub([mock_attributes])
35
+
36
+ results = Geocoder.search("Atlantis, OC")
37
+ result = results.first
38
+
39
+ assert_equal 1, results.size
40
+ mock_attributes.keys.each do |attr|
41
+ assert_equal mock_attributes[attr], result.send(attr)
42
+ end
43
+ end
44
+
45
+ private
46
+ def mock_attributes
16
47
  coordinates = [40.7143528, -74.0059731]
17
- attributes = {
48
+ @mock_attributes ||= {
18
49
  'coordinates' => coordinates,
19
50
  'latitude' => coordinates[0],
20
51
  'longitude' => coordinates[1],
@@ -24,27 +55,5 @@ class TestModeTest < Test::Unit::TestCase
24
55
  'country' => 'United States',
25
56
  'country_code' => 'US',
26
57
  }
27
-
28
- Geocoder::Lookup::Test.add_stub("New York, NY", [attributes])
29
-
30
- results = Geocoder.search("New York, NY")
31
- assert_equal 1, results.size
32
-
33
- result = results.first
34
- assert_equal coordinates, result.coordinates
35
- assert_equal attributes['latitude'], result.latitude
36
- assert_equal attributes['longitude'], result.longitude
37
- assert_equal attributes['address'], result.address
38
- assert_equal attributes['state'], result.state
39
- assert_equal attributes['state_code'], result.state_code
40
- assert_equal attributes['country'], result.country
41
- assert_equal attributes['country_code'], result.country_code
42
- end
43
-
44
- def test_search_with_unknown_stub
45
- assert_raise ArgumentError do
46
- Geocoder.search("New York, NY")
47
- end
48
58
  end
49
-
50
59
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geocoder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-24 00:00:00.000000000 Z
12
+ date: 2013-04-21 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Provides object geocoding (by street or IP address), reverse geocoding
15
15
  (coordinates to street address), distance queries for ActiveRecord and Mongoid,
@@ -29,7 +29,8 @@ files:
29
29
  - README.md
30
30
  - Rakefile
31
31
  - bin/geocode
32
- - examples/autoexpire_cache.rb
32
+ - examples/autoexpire_cache_dalli.rb
33
+ - examples/autoexpire_cache_redis.rb
33
34
  - gemfiles/Gemfile.mongoid-2.4.x
34
35
  - lib/generators/geocoder/config/config_generator.rb
35
36
  - lib/generators/geocoder/config/templates/initializer.rb
@@ -43,6 +44,7 @@ files:
43
44
  - lib/geocoder/lookup.rb
44
45
  - lib/geocoder/lookups/base.rb
45
46
  - lib/geocoder/lookups/bing.rb
47
+ - lib/geocoder/lookups/esri.rb
46
48
  - lib/geocoder/lookups/freegeoip.rb
47
49
  - lib/geocoder/lookups/geocoder_ca.rb
48
50
  - lib/geocoder/lookups/google.rb
@@ -50,6 +52,7 @@ files:
50
52
  - lib/geocoder/lookups/mapquest.rb
51
53
  - lib/geocoder/lookups/maxmind.rb
52
54
  - lib/geocoder/lookups/nominatim.rb
55
+ - lib/geocoder/lookups/ovi.rb
53
56
  - lib/geocoder/lookups/test.rb
54
57
  - lib/geocoder/lookups/yahoo.rb
55
58
  - lib/geocoder/lookups/yandex.rb
@@ -63,6 +66,7 @@ files:
63
66
  - lib/geocoder/request.rb
64
67
  - lib/geocoder/results/base.rb
65
68
  - lib/geocoder/results/bing.rb
69
+ - lib/geocoder/results/esri.rb
66
70
  - lib/geocoder/results/freegeoip.rb
67
71
  - lib/geocoder/results/geocoder_ca.rb
68
72
  - lib/geocoder/results/google.rb
@@ -70,6 +74,7 @@ files:
70
74
  - lib/geocoder/results/mapquest.rb
71
75
  - lib/geocoder/results/maxmind.rb
72
76
  - lib/geocoder/results/nominatim.rb
77
+ - lib/geocoder/results/ovi.rb
73
78
  - lib/geocoder/results/test.rb
74
79
  - lib/geocoder/results/yahoo.rb
75
80
  - lib/geocoder/results/yandex.rb
@@ -93,6 +98,9 @@ files:
93
98
  - test/fixtures/bing_madison_square_garden
94
99
  - test/fixtures/bing_no_results
95
100
  - test/fixtures/bing_reverse
101
+ - test/fixtures/esri_madison_square_garden
102
+ - test/fixtures/esri_no_results
103
+ - test/fixtures/esri_reverse
96
104
  - test/fixtures/freegeoip_74_200_247_59
97
105
  - test/fixtures/freegeoip_no_results
98
106
  - test/fixtures/geocoder_ca_madison_square_garden
@@ -114,6 +122,8 @@ files:
114
122
  - test/fixtures/maxmind_no_results
115
123
  - test/fixtures/nominatim_madison_square_garden
116
124
  - test/fixtures/nominatim_no_results
125
+ - test/fixtures/ovi_madison_square_garden
126
+ - test/fixtures/ovi_no_results
117
127
  - test/fixtures/yahoo_error
118
128
  - test/fixtures/yahoo_invalid_key
119
129
  - test/fixtures/yahoo_madison_square_garden
@@ -121,6 +131,7 @@ files:
121
131
  - test/fixtures/yahoo_over_limit
122
132
  - test/fixtures/yandex_invalid_key
123
133
  - test/fixtures/yandex_kremlin
134
+ - test/fixtures/yandex_no_city_and_town
124
135
  - test/fixtures/yandex_no_results
125
136
  - test/geocoder_test.rb
126
137
  - test/https_test.rb
@@ -133,6 +144,7 @@ files:
133
144
  - test/oauth_util_test.rb
134
145
  - test/proxy_test.rb
135
146
  - test/query_test.rb
147
+ - test/request_test.rb
136
148
  - test/result_test.rb
137
149
  - test/services_test.rb
138
150
  - test/test_helper.rb