geokit 1.8.5 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +0 -1
  3. data/CHANGELOG.md +7 -0
  4. data/README.markdown +31 -14
  5. data/fixtures/vcr_cassettes/geonames_geocode.yml +1 -1
  6. data/fixtures/vcr_cassettes/geonames_geocode_premium.yml +42 -0
  7. data/fixtures/vcr_cassettes/google_country_code_biased_result_orly.yml +160 -0
  8. data/fixtures/vcr_cassettes/google_country_code_biased_result_toledo.yml +111 -0
  9. data/fixtures/vcr_cassettes/google_result_toledo_default_bias.yml +275 -0
  10. data/fixtures/vcr_cassettes/google_sublocality.yml +126 -0
  11. data/fixtures/vcr_cassettes/mapbox_forward_geocode.yml +59 -0
  12. data/fixtures/vcr_cassettes/mapbox_reverse_geocode.yml +63 -0
  13. data/fixtures/vcr_cassettes/opencage_city.yml +51 -0
  14. data/fixtures/vcr_cassettes/opencage_full.yml +65 -0
  15. data/fixtures/vcr_cassettes/opencage_language_response_es.yml +66 -0
  16. data/fixtures/vcr_cassettes/opencage_reverse_madrid.yml +51 -0
  17. data/fixtures/vcr_cassettes/opencage_reverse_prilep.yml +53 -0
  18. data/geokit.gemspec +5 -3
  19. data/lib/geokit/bounds.rb +40 -31
  20. data/lib/geokit/core_ext.rb +1 -1
  21. data/lib/geokit/geo_loc.rb +63 -41
  22. data/lib/geokit/geocoders.rb +13 -13
  23. data/lib/geokit/geocoders/bing.rb +9 -9
  24. data/lib/geokit/geocoders/ca_geocoder.rb +29 -29
  25. data/lib/geokit/geocoders/fcc.rb +4 -4
  26. data/lib/geokit/geocoders/free_geo_ip.rb +6 -7
  27. data/lib/geokit/geocoders/geo_plugin.rb +5 -6
  28. data/lib/geokit/geocoders/geocodio.rb +2 -2
  29. data/lib/geokit/geocoders/geonames.rb +18 -12
  30. data/lib/geokit/geocoders/google.rb +31 -30
  31. data/lib/geokit/geocoders/ip.rb +3 -4
  32. data/lib/geokit/geocoders/mapbox.rb +94 -0
  33. data/lib/geokit/geocoders/mapquest.rb +5 -5
  34. data/lib/geokit/geocoders/opencage.rb +93 -0
  35. data/lib/geokit/geocoders/openstreetmap.rb +9 -6
  36. data/lib/geokit/geocoders/ripe.rb +3 -3
  37. data/lib/geokit/geocoders/us_geocoder.rb +10 -9
  38. data/lib/geokit/geocoders/yahoo.rb +33 -34
  39. data/lib/geokit/geocoders/yandex.rb +17 -17
  40. data/lib/geokit/inflectors.rb +4 -10
  41. data/lib/geokit/lat_lng.rb +50 -26
  42. data/lib/geokit/mappable.rb +83 -83
  43. data/lib/geokit/multi_geocoder.rb +25 -20
  44. data/lib/geokit/net_adapter/net_http.rb +7 -4
  45. data/lib/geokit/polygon.rb +36 -4
  46. data/lib/geokit/version.rb +1 -1
  47. data/test/helper.rb +15 -13
  48. data/test/test_base_geocoder.rb +6 -7
  49. data/test/test_bing_geocoder.rb +20 -21
  50. data/test/test_bounds.rb +26 -28
  51. data/test/test_ca_geocoder.rb +9 -10
  52. data/test/test_fcc_geocoder.rb +1 -1
  53. data/test/test_free_geo_ip_geocoder.rb +1 -1
  54. data/test/test_geo_plugin_geocoder.rb +9 -9
  55. data/test/test_geoloc.rb +7 -6
  56. data/test/test_geonames_geocoder.rb +28 -6
  57. data/test/test_google_geocoder.rb +210 -176
  58. data/test/test_inflector.rb +0 -1
  59. data/test/test_ipgeocoder.rb +17 -18
  60. data/test/test_latlng.rb +105 -85
  61. data/test/test_map_quest.rb +18 -21
  62. data/test/test_mapbox_geocoder.rb +31 -0
  63. data/test/test_mappable.rb +46 -0
  64. data/test/test_maxmind_geocoder.rb +1 -3
  65. data/test/test_multi_geocoder.rb +8 -9
  66. data/test/test_multi_ip_geocoder.rb +3 -5
  67. data/test/test_net_adapter.rb +4 -4
  68. data/test/test_opencage_geocoder.rb +108 -0
  69. data/test/test_openstreetmap_geocoder.rb +62 -44
  70. data/test/{test_polygon_contains.rb → test_polygon.rb} +30 -20
  71. data/test/test_ripe_geocoder.rb +2 -0
  72. data/test/test_us_geocoder.rb +7 -8
  73. data/test/test_yahoo_geocoder.rb +20 -21
  74. data/test/test_yandex_geocoder.rb +34 -35
  75. metadata +79 -56
  76. data/fixtures/vcr_cassettes/google_country_code_biased_result.yml +0 -401
@@ -4,20 +4,42 @@ class GeonamesGeocoderTest < BaseGeocoderTest #:nodoc: all
4
4
  def setup
5
5
  super
6
6
  @city = 'Adelaide'
7
+ Geokit::Geocoders::GeonamesGeocoder.key = 'demo'
7
8
  end
8
9
 
9
10
  def assert_url(expected_url)
10
11
  assert_equal expected_url, TestHelper.get_last_url.gsub(/&oauth_[a-z_]+=[a-zA-Z0-9\-. %]+/, '').gsub('%20', '+')
11
12
  end
12
13
 
14
+ def test_geonames_missing_key
15
+ Geokit::Geocoders::GeonamesGeocoder.key = nil
16
+ exception = assert_raise(Geokit::Geocoders::GeocodeError) do
17
+ Geokit::Geocoders::GeonamesGeocoder.geocode(@city)
18
+ end
19
+ assert_equal('Geonames requires a key to use their service.', exception.message)
20
+ end
21
+
13
22
  def test_geonames_geocode
14
23
  VCR.use_cassette('geonames_geocode') do
15
- url = "http://ws.geonames.org/postalCodeSearch?placename=#{@city}&maxRows=10"
16
- res = Geokit::Geocoders::GeonamesGeocoder.geocode(@city)
17
- assert_url url
18
- assert_equal res.country_code, 'AU'
19
- assert_equal res.state, 'South Australia'
20
- assert_equal res.city, 'Adelaide'
24
+ url = "http://api.geonames.org/postalCodeSearch?placename=#{@city}&maxRows=10&username=demo"
25
+ res = Geokit::Geocoders::GeonamesGeocoder.geocode(@city)
26
+ assert_url url
27
+ assert_equal res.country_code, 'AU'
28
+ assert_equal res.state, 'SA'
29
+ assert_equal res.state_name, 'South Australia'
30
+ assert_equal res.state_code, 'SA'
31
+ assert_equal res.city, 'Adelaide'
32
+ end
33
+ end
34
+
35
+ def test_geonames_geocode_premium
36
+ # note this test will not actually return results because a valid premium
37
+ # username is required so we are just testing if the url is correct
38
+ Geokit::Geocoders::GeonamesGeocoder.premium = true
39
+ VCR.use_cassette('geonames_geocode_premium') do
40
+ url = "http://ws.geonames.net/postalCodeSearch?placename=#{@city}&maxRows=10&username=demo"
41
+ res = Geokit::Geocoders::GeonamesGeocoder.geocode(@city)
42
+ assert_url url
21
43
  end
22
44
  end
23
45
  end
@@ -2,19 +2,17 @@
2
2
  require File.join(File.dirname(__FILE__), 'helper')
3
3
 
4
4
  class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
5
-
6
5
  def setup
7
6
  super
8
7
  @full_address = '100 Spear St Apt. 5, San Francisco, CA, 94105-1522, US'
9
8
  @full_address_short_zip = '100 Spear St Apt. 5, San Francisco, CA, 94105, US'
10
- @google_full_hash = {:street_address=>"100 Spear St Apt. 5", :city=>"San Francisco", :state=>"CA", :zip=>"94105", :country_code=>"US"}
11
- @google_city_hash = {:city=>"San Francisco", :state=>"CA"}
9
+ @google_full_hash = {street_address: '100 Spear St Apt. 5', city: 'San Francisco', state: 'CA', zip: '94105', country_code: 'US'}
10
+ @google_city_hash = {city: 'San Francisco', state: 'CA'}
12
11
 
13
12
  @google_full_loc = Geokit::GeoLoc.new(@google_full_hash)
14
13
  @google_city_loc = Geokit::GeoLoc.new(@google_city_hash)
15
14
  end
16
15
 
17
-
18
16
  # Example from:
19
17
  # https://developers.google.com/maps/documentation/business/webservices#signature_examples
20
18
  def test_google_signature
@@ -24,7 +22,6 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
24
22
  assert_equal 'KrU1TzVQM7Ur0i8i7K3huiw3MsA=', signature
25
23
  end
26
24
 
27
-
28
25
  # Example from:
29
26
  # https://developers.google.com/maps/documentation/business/webservices#signature_examples
30
27
  def test_google_signature_and_url
@@ -52,207 +49,244 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
52
49
 
53
50
  def test_google_full_address
54
51
  VCR.use_cassette('google_full_short') do
55
- url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@address)}"
52
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@address)}"
56
53
  TestHelper.expects(:last_url).with(url)
57
- res=Geokit::Geocoders::GoogleGeocoder.geocode(@address)
58
- assert_equal "CA", res.state
59
- assert_equal "San Francisco", res.city
54
+ res = Geokit::Geocoders::GoogleGeocoder.geocode(@address)
55
+ assert_equal 'CA', res.state
56
+ assert_equal 'San Francisco', res.city
60
57
  assert_array_in_delta [37.7749295, -122.4194155], res.to_a # slightly dif from yahoo
61
58
  assert res.is_us?
62
- assert_equal "San Francisco, CA, USA", res.full_address #slightly different from yahoo
63
- assert_equal "google", res.provider
59
+ assert_equal 'San Francisco, CA, USA', res.full_address # slightly different from yahoo
60
+ assert_equal 'google', res.provider
64
61
  end
65
62
  end
66
63
 
67
64
  def test_google_full_address_with_geo_loc
68
- VCR.use_cassette('google_full') do
69
- url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@full_address_short_zip)}"
70
- TestHelper.expects(:last_url).with(url)
71
- res=Geokit::Geocoders::GoogleGeocoder.geocode(@google_full_loc)
72
- assert_equal "CA", res.state
73
- assert_equal "San Francisco", res.city
74
- assert_array_in_delta [37.7921509, -122.394], res.to_a # slightly dif from yahoo
75
- assert res.is_us?
76
- assert_equal "100 Spear Street #5, San Francisco, CA 94105, USA", res.full_address #slightly different from yahoo
77
- assert_equal "google", res.provider
78
- end
79
- end
65
+ VCR.use_cassette('google_full') do
66
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@full_address_short_zip)}"
67
+ TestHelper.expects(:last_url).with(url)
68
+ res = Geokit::Geocoders::GoogleGeocoder.geocode(@google_full_loc)
69
+ assert_equal 'CA', res.state
70
+ assert_equal 'San Francisco', res.city
71
+ assert_array_in_delta [37.7921509, -122.394], res.to_a # slightly dif from yahoo
72
+ assert res.is_us?
73
+ assert_equal '100 Spear Street #5, San Francisco, CA 94105, USA', res.full_address # slightly different from yahoo
74
+ assert_equal 'google', res.provider
75
+ end
76
+ end
80
77
 
81
- def test_google_full_address_accuracy
82
- VCR.use_cassette('google_full') do
83
- url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@full_address_short_zip)}"
84
- TestHelper.expects(:last_url).with(url)
85
- res=Geokit::Geocoders::GoogleGeocoder.geocode(@google_full_loc)
78
+ def test_google_full_address_accuracy
79
+ VCR.use_cassette('google_full') do
80
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@full_address_short_zip)}"
81
+ TestHelper.expects(:last_url).with(url)
82
+ res = Geokit::Geocoders::GoogleGeocoder.geocode(@google_full_loc)
86
83
 
87
- assert_equal 9, res.accuracy
88
- end
89
- end
84
+ assert_equal 9, res.accuracy
85
+ end
86
+ end
90
87
 
91
- def test_google_city
92
- VCR.use_cassette('google_city') do
93
- url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@address)}"
88
+ def test_google_city
89
+ VCR.use_cassette('google_city') do
90
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@address)}"
91
+ TestHelper.expects(:last_url).with(url)
92
+ res = Geokit::Geocoders::GoogleGeocoder.do_geocode(@address)
93
+ assert_nil res.street_address
94
+ assert_equal 'CA', res.state
95
+ assert_equal 'San Francisco', res.city
96
+ assert_equal '37.7749295,-122.4194155', res.ll
97
+ assert res.is_us?
98
+ assert_equal 'San Francisco, CA, USA', res.full_address
99
+ assert_equal 'google', res.provider
100
+ end
101
+ end
102
+
103
+ def test_google_sublocality
104
+ @address = '682 prospect place Brooklyn ny 11216'
105
+ VCR.use_cassette('google_sublocality') do
106
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@address)}"
94
107
  TestHelper.expects(:last_url).with(url)
95
- res=Geokit::Geocoders::GoogleGeocoder.do_geocode(@address)
96
- assert_nil res.street_address
97
- assert_equal "CA", res.state
98
- assert_equal "San Francisco", res.city
99
- assert_equal "37.7749295,-122.4194155", res.ll
108
+ res = Geokit::Geocoders::GoogleGeocoder.do_geocode(@address)
109
+ assert_equal '682 Prospect Place', res.street_address
110
+ assert_equal 'NY', res.state
111
+ assert_equal 'Brooklyn', res.city
112
+ assert_equal '40.6745812,-73.9541582', res.ll
100
113
  assert res.is_us?
101
- assert_equal "San Francisco, CA, USA", res.full_address
102
- assert_equal "google", res.provider
114
+ assert_equal '682 Prospect Place, Brooklyn, NY 11216, USA', res.full_address
115
+ assert_equal 'google', res.provider
103
116
  end
104
117
  end
105
118
 
106
- def test_google_city_accuracy
107
- VCR.use_cassette('google_city') do
108
- url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@address)}"
109
- TestHelper.expects(:last_url).with(url)
110
- res=Geokit::Geocoders::GoogleGeocoder.geocode(@address)
111
- assert_equal 4, res.accuracy
112
- end
113
- end
119
+ def test_google_city_accuracy
120
+ VCR.use_cassette('google_city') do
121
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@address)}"
122
+ TestHelper.expects(:last_url).with(url)
123
+ res = Geokit::Geocoders::GoogleGeocoder.geocode(@address)
124
+ assert_equal 4, res.accuracy
125
+ end
126
+ end
114
127
 
115
- def test_google_city_with_geo_loc
116
- VCR.use_cassette('google_city') do
117
- url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@address)}"
118
- TestHelper.expects(:last_url).with(url)
119
- res=Geokit::Geocoders::GoogleGeocoder.geocode(@google_city_loc)
120
- assert_equal "CA", res.state
121
- assert_equal "San Francisco", res.city
122
- assert_equal "37.7749295,-122.4194155", res.ll
123
- assert res.is_us?
124
- assert_equal "San Francisco, CA, USA", res.full_address
125
- assert_nil res.street_address
126
- assert_equal "google", res.provider
127
- end
128
- end
128
+ def test_google_city_with_geo_loc
129
+ VCR.use_cassette('google_city') do
130
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@address)}"
131
+ TestHelper.expects(:last_url).with(url)
132
+ res = Geokit::Geocoders::GoogleGeocoder.geocode(@google_city_loc)
133
+ assert_equal 'CA', res.state
134
+ assert_equal 'San Francisco', res.city
135
+ assert_equal '37.7749295,-122.4194155', res.ll
136
+ assert res.is_us?
137
+ assert_equal 'San Francisco, CA, USA', res.full_address
138
+ assert_nil res.street_address
139
+ assert_equal 'google', res.provider
140
+ end
141
+ end
129
142
 
130
- def test_google_suggested_bounds
131
- VCR.use_cassette('google_full') do
132
- url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@full_address_short_zip)}"
133
- TestHelper.expects(:last_url).with(url)
134
- res = Geokit::Geocoders::GoogleGeocoder.geocode(@google_full_loc)
135
- assert_instance_of Geokit::Bounds, res.suggested_bounds
136
- assert_array_in_delta [37.7908019197085, -122.3953489802915], res.suggested_bounds.sw.to_a
137
- assert_array_in_delta [37.7934998802915, -122.3926510197085], res.suggested_bounds.ne.to_a
138
- end
139
- end
143
+ def test_google_suggested_bounds
144
+ VCR.use_cassette('google_full') do
145
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@full_address_short_zip)}"
146
+ TestHelper.expects(:last_url).with(url)
147
+ res = Geokit::Geocoders::GoogleGeocoder.geocode(@google_full_loc)
148
+ assert_instance_of Geokit::Bounds, res.suggested_bounds
149
+ assert_array_in_delta [37.7908019197085, -122.3953489802915], res.suggested_bounds.sw.to_a
150
+ assert_array_in_delta [37.7934998802915, -122.3926510197085], res.suggested_bounds.ne.to_a
151
+ end
152
+ end
140
153
 
141
- def test_google_suggested_bounds_url
142
- bounds = Geokit::Bounds.new(
143
- Geokit::LatLng.new(33.7036917, -118.6681759),
144
- Geokit::LatLng.new(34.3373061, -118.1552891)
145
- )
146
- url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=Winnetka&bounds=33.7036917%2C-118.6681759%7C34.3373061%2C-118.1552891"
147
- Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url)
148
- Geokit::Geocoders::GoogleGeocoder.geocode('Winnetka', :bias => bounds)
154
+ def test_google_suggested_bounds_url
155
+ bounds = Geokit::Bounds.new(
156
+ Geokit::LatLng.new(33.7036917, -118.6681759),
157
+ Geokit::LatLng.new(34.3373061, -118.1552891)
158
+ )
159
+ url = 'https://maps.google.com/maps/api/geocode/json?sensor=false&address=Winnetka&bounds=33.7036917%2C-118.6681759%7C34.3373061%2C-118.1552891'
160
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url)
161
+ Geokit::Geocoders::GoogleGeocoder.geocode('Winnetka', bias: bounds)
149
162
  end
150
163
 
151
- def test_service_unavailable
152
- response = MockFailure.new
153
- url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@address)}"
154
- Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
155
- assert !Geokit::Geocoders::GoogleGeocoder.geocode(@google_city_loc).success
156
- end
164
+ def test_service_unavailable
165
+ response = MockFailure.new
166
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@address)}"
167
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
168
+ assert !Geokit::Geocoders::GoogleGeocoder.geocode(@google_city_loc).success
169
+ end
157
170
 
158
- def test_multiple_results
159
- VCR.use_cassette('google_multi') do
160
- url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape('via Sandro Pertini 8, Ossona, MI')}"
161
- TestHelper.expects(:last_url).with(url)
162
- res=Geokit::Geocoders::GoogleGeocoder.geocode('via Sandro Pertini 8, Ossona, MI')
163
- assert_equal 5, res.all.size
164
- res = res.all[0]
165
- assert_equal "Lombardy", res.state
166
- assert_equal "Mesero", res.city
167
- assert_array_in_delta [45.4966218, 8.852694], res.to_a
168
- assert !res.is_us?
169
- assert_equal "Via Sandro Pertini, 8, 20010 Mesero Milan, Italy", res.full_address
170
- assert_equal "8 Via Sandro Pertini", res.street_address
171
- assert_equal "google", res.provider
172
-
173
- res = res.all[4]
174
- assert_equal "Lombardy", res.state
175
- assert_equal "Ossona", res.city
176
- assert_array_in_delta [45.5074444, 8.90232], res.to_a
177
- assert !res.is_us?
178
- assert_equal "Via S. Pertini, 20010 Ossona Milan, Italy", res.full_address
179
- assert_equal "Via S. Pertini", res.street_address
180
- assert_equal "google", res.provider
181
- end
182
- end
183
- #
184
- def test_reverse_geocode
185
- VCR.use_cassette('google_reverse_madrid') do
186
- madrid = Geokit::GeoLoc.new
187
- madrid.lat, madrid.lng = "40.4167413", "-3.7032498"
188
- url = "https://maps.google.com/maps/api/geocode/json?sensor=false&latlng=#{Geokit::Inflector::url_escape(madrid.ll)}"
189
- TestHelper.expects(:last_url).with(url)
190
- res=Geokit::Geocoders::GoogleGeocoder.do_reverse_geocode(madrid.ll)
171
+ def test_multiple_results
172
+ VCR.use_cassette('google_multi') do
173
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape('via Sandro Pertini 8, Ossona, MI')}"
174
+ TestHelper.expects(:last_url).with(url)
175
+ res = Geokit::Geocoders::GoogleGeocoder.geocode('via Sandro Pertini 8, Ossona, MI')
176
+ assert_equal 5, res.all.size
177
+ res = res.all[0]
178
+ assert_equal 'Lombardy', res.state
179
+ assert_equal 'Mesero', res.city
180
+ assert_array_in_delta [45.4966218, 8.852694], res.to_a
181
+ assert !res.is_us?
182
+ assert_equal 'Via Sandro Pertini, 8, 20010 Mesero Milan, Italy', res.full_address
183
+ assert_equal '8 Via Sandro Pertini', res.street_address
184
+ assert_equal 'google', res.provider
185
+
186
+ res = res.all[4]
187
+ assert_equal 'Lombardy', res.state
188
+ assert_equal 'Ossona', res.city
189
+ assert_array_in_delta [45.5074444, 8.90232], res.to_a
190
+ assert !res.is_us?
191
+ assert_equal 'Via S. Pertini, 20010 Ossona Milan, Italy', res.full_address
192
+ assert_equal 'Via S. Pertini', res.street_address
193
+ assert_equal 'google', res.provider
194
+ end
195
+ end
191
196
 
192
- assert_equal madrid.lat.to_s.slice(1..5), res.lat.to_s.slice(1..5)
193
- assert_equal madrid.lng.to_s.slice(1..5), res.lng.to_s.slice(1..5)
194
- assert_equal "ES", res.country_code
195
- assert_equal "google", res.provider
197
+ def test_reverse_geocode
198
+ VCR.use_cassette('google_reverse_madrid') do
199
+ madrid = Geokit::GeoLoc.new
200
+ madrid.lat, madrid.lng = '40.4167413', '-3.7032498'
201
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&latlng=#{Geokit::Inflector.url_escape(madrid.ll)}"
202
+ TestHelper.expects(:last_url).with(url)
203
+ res = Geokit::Geocoders::GoogleGeocoder.do_reverse_geocode(madrid.ll)
196
204
 
197
- assert_equal "Madrid", res.city
198
- assert_equal "Community of Madrid", res.state
205
+ assert_equal madrid.lat.to_s.slice(1..5), res.lat.to_s.slice(1..5)
206
+ assert_equal madrid.lng.to_s.slice(1..5), res.lng.to_s.slice(1..5)
207
+ assert_equal 'ES', res.country_code
208
+ assert_equal 'google', res.provider
199
209
 
200
- assert_equal "Spain", res.country
201
- assert_equal "28013", res.zip
202
- assert_equal true, res.success
203
- end
204
- end
210
+ assert_equal 'Madrid', res.city
211
+ assert_equal 'Community of Madrid', res.state
205
212
 
206
- def test_reverse_geocode_language
207
- VCR.use_cassette('google_reverse_madrid_es') do
208
- url = "https://maps.google.com/maps/api/geocode/json?sensor=false&latlng=40.416%2C-3.703&language=es"
209
- TestHelper.expects(:last_url).with(url)
210
- language_result = Geokit::Geocoders::GoogleGeocoder.reverse_geocode('40.416,-3.703', :language => 'es')
213
+ assert_equal 'Spain', res.country
214
+ assert_equal '28013', res.zip
215
+ assert_equal true, res.success
216
+ end
217
+ end
211
218
 
212
- assert_equal 'ES', language_result.country_code
213
- assert_equal 'Madrid', language_result.city
214
- end
215
- end
219
+ def test_reverse_geocode_language
220
+ VCR.use_cassette('google_reverse_madrid_es') do
221
+ url = 'https://maps.google.com/maps/api/geocode/json?sensor=false&latlng=40.416%2C-3.703&language=es'
222
+ TestHelper.expects(:last_url).with(url)
223
+ language_result = Geokit::Geocoders::GoogleGeocoder.reverse_geocode('40.416,-3.703', language: 'es')
216
224
 
217
- def test_country_code_biasing
218
- VCR.use_cassette('google_country_code_biased_result') do
219
- url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=Syracuse&region=it"
220
- TestHelper.expects(:last_url).with(url)
221
- biased_result = Geokit::Geocoders::GoogleGeocoder.geocode('Syracuse', :bias => 'it')
225
+ assert_equal 'ES', language_result.country_code
226
+ assert_equal 'Madrid', language_result.city
227
+ end
228
+ end
222
229
 
223
- assert_equal 'IT', biased_result.country_code
224
- assert_equal 'Sicilia', biased_result.state
225
- end
226
- end
230
+ def test_language_response
231
+ VCR.use_cassette('google_language_response_fr') do
232
+ url = 'https://maps.google.com/maps/api/geocode/json?sensor=false&address=Hanoi&language=FR'
233
+ TestHelper.expects(:last_url).with(url)
234
+ language_result = Geokit::Geocoders::GoogleGeocoder.geocode('Hanoi', language: 'FR')
227
235
 
228
- def test_language_response
229
- VCR.use_cassette('google_language_response_fr') do
230
- url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=Hanoi&language=FR"
231
- TestHelper.expects(:last_url).with(url)
232
- language_result = Geokit::Geocoders::GoogleGeocoder.geocode('Hanoi', :language => 'FR')
236
+ assert_equal 'VN', language_result.country_code
237
+ assert_equal 'Hanoï', language_result.city
238
+ end
239
+ end
233
240
 
234
- assert_equal 'VN', language_result.country_code
235
- assert_equal 'Hanoï', language_result.city
236
- end
237
- end
241
+ def test_too_many_queries
242
+ response = MockSuccess.new
243
+ response.expects(:body).returns %q/{"status": "OVER_QUERY_LIMIT"}/
244
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@address)}"
245
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
246
+ assert_raise Geokit::Geocoders::TooManyQueriesError do
247
+ res = Geokit::Geocoders::GoogleGeocoder.geocode(@address)
248
+ end
249
+ end
238
250
 
239
- def test_too_many_queries
240
- response = MockSuccess.new
241
- response.expects(:body).returns %q/{"status": "OVER_QUERY_LIMIT"}/
242
- url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@address)}"
243
- Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
244
- assert_raise Geokit::Geocoders::TooManyQueriesError do
245
- res=Geokit::Geocoders::GoogleGeocoder.geocode(@address)
246
- end
247
- end
251
+ def test_invalid_request
252
+ response = MockSuccess.new
253
+ response.expects(:body).returns %q/{"results" : [], "status" : "INVALID_REQUEST"}/
254
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape("3961 V\u00EDa Marisol")}"
255
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
256
+ assert_raise Geokit::Geocoders::GeocodeError do
257
+ Geokit::Geocoders::GoogleGeocoder.geocode("3961 V\u00EDa Marisol")
258
+ end
259
+ end
260
+
261
+ def test_country_code_biasing_toledo
262
+ VCR.use_cassette('google_country_code_biased_result_toledo') do
263
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=toledo&region=es"
264
+ TestHelper.expects(:last_url).with(url)
265
+ biased_result = Geokit::Geocoders::GoogleGeocoder.geocode('toledo', :bias => 'es')
266
+
267
+ assert_equal 'ES', biased_result.country_code
268
+ assert_equal 'CM', biased_result.state
269
+ end
270
+
271
+ VCR.use_cassette('google_result_toledo_default_bias') do
272
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=toledo"
273
+ TestHelper.expects(:last_url).with(url)
274
+ biased_result = Geokit::Geocoders::GoogleGeocoder.geocode('toledo')
275
+
276
+ assert_equal 'US', biased_result.country_code
277
+ assert_equal 'OH', biased_result.state
278
+ end
279
+ end
280
+
281
+ def test_country_code_biasing_orly
282
+ VCR.use_cassette('google_country_code_biased_result_orly') do
283
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=orly&region=fr"
284
+ TestHelper.expects(:last_url).with(url)
285
+ biased_result = Geokit::Geocoders::GoogleGeocoder.geocode('orly', :bias => 'fr')
286
+
287
+ assert_equal 'FR', biased_result.country_code
288
+ assert_equal 'Orly, France', biased_result.full_address
289
+ end
290
+ end
248
291
 
249
- def test_invalid_request
250
- response = MockSuccess.new
251
- response.expects(:body).returns %q/{"results" : [], "status" : "INVALID_REQUEST"}/
252
- url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape("3961 V\u00EDa Marisol")}"
253
- Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
254
- assert_raise Geokit::Geocoders::GeocodeError do
255
- Geokit::Geocoders::GoogleGeocoder.geocode("3961 V\u00EDa Marisol")
256
- end
257
- end
258
292
  end