geokit 1.8.5 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +0 -1
- data/CHANGELOG.md +7 -0
- data/README.markdown +31 -14
- data/fixtures/vcr_cassettes/geonames_geocode.yml +1 -1
- data/fixtures/vcr_cassettes/geonames_geocode_premium.yml +42 -0
- data/fixtures/vcr_cassettes/google_country_code_biased_result_orly.yml +160 -0
- data/fixtures/vcr_cassettes/google_country_code_biased_result_toledo.yml +111 -0
- data/fixtures/vcr_cassettes/google_result_toledo_default_bias.yml +275 -0
- data/fixtures/vcr_cassettes/google_sublocality.yml +126 -0
- data/fixtures/vcr_cassettes/mapbox_forward_geocode.yml +59 -0
- data/fixtures/vcr_cassettes/mapbox_reverse_geocode.yml +63 -0
- data/fixtures/vcr_cassettes/opencage_city.yml +51 -0
- data/fixtures/vcr_cassettes/opencage_full.yml +65 -0
- data/fixtures/vcr_cassettes/opencage_language_response_es.yml +66 -0
- data/fixtures/vcr_cassettes/opencage_reverse_madrid.yml +51 -0
- data/fixtures/vcr_cassettes/opencage_reverse_prilep.yml +53 -0
- data/geokit.gemspec +5 -3
- data/lib/geokit/bounds.rb +40 -31
- data/lib/geokit/core_ext.rb +1 -1
- data/lib/geokit/geo_loc.rb +63 -41
- data/lib/geokit/geocoders.rb +13 -13
- data/lib/geokit/geocoders/bing.rb +9 -9
- data/lib/geokit/geocoders/ca_geocoder.rb +29 -29
- data/lib/geokit/geocoders/fcc.rb +4 -4
- data/lib/geokit/geocoders/free_geo_ip.rb +6 -7
- data/lib/geokit/geocoders/geo_plugin.rb +5 -6
- data/lib/geokit/geocoders/geocodio.rb +2 -2
- data/lib/geokit/geocoders/geonames.rb +18 -12
- data/lib/geokit/geocoders/google.rb +31 -30
- data/lib/geokit/geocoders/ip.rb +3 -4
- data/lib/geokit/geocoders/mapbox.rb +94 -0
- data/lib/geokit/geocoders/mapquest.rb +5 -5
- data/lib/geokit/geocoders/opencage.rb +93 -0
- data/lib/geokit/geocoders/openstreetmap.rb +9 -6
- data/lib/geokit/geocoders/ripe.rb +3 -3
- data/lib/geokit/geocoders/us_geocoder.rb +10 -9
- data/lib/geokit/geocoders/yahoo.rb +33 -34
- data/lib/geokit/geocoders/yandex.rb +17 -17
- data/lib/geokit/inflectors.rb +4 -10
- data/lib/geokit/lat_lng.rb +50 -26
- data/lib/geokit/mappable.rb +83 -83
- data/lib/geokit/multi_geocoder.rb +25 -20
- data/lib/geokit/net_adapter/net_http.rb +7 -4
- data/lib/geokit/polygon.rb +36 -4
- data/lib/geokit/version.rb +1 -1
- data/test/helper.rb +15 -13
- data/test/test_base_geocoder.rb +6 -7
- data/test/test_bing_geocoder.rb +20 -21
- data/test/test_bounds.rb +26 -28
- data/test/test_ca_geocoder.rb +9 -10
- data/test/test_fcc_geocoder.rb +1 -1
- data/test/test_free_geo_ip_geocoder.rb +1 -1
- data/test/test_geo_plugin_geocoder.rb +9 -9
- data/test/test_geoloc.rb +7 -6
- data/test/test_geonames_geocoder.rb +28 -6
- data/test/test_google_geocoder.rb +210 -176
- data/test/test_inflector.rb +0 -1
- data/test/test_ipgeocoder.rb +17 -18
- data/test/test_latlng.rb +105 -85
- data/test/test_map_quest.rb +18 -21
- data/test/test_mapbox_geocoder.rb +31 -0
- data/test/test_mappable.rb +46 -0
- data/test/test_maxmind_geocoder.rb +1 -3
- data/test/test_multi_geocoder.rb +8 -9
- data/test/test_multi_ip_geocoder.rb +3 -5
- data/test/test_net_adapter.rb +4 -4
- data/test/test_opencage_geocoder.rb +108 -0
- data/test/test_openstreetmap_geocoder.rb +62 -44
- data/test/{test_polygon_contains.rb → test_polygon.rb} +30 -20
- data/test/test_ripe_geocoder.rb +2 -0
- data/test/test_us_geocoder.rb +7 -8
- data/test/test_yahoo_geocoder.rb +20 -21
- data/test/test_yandex_geocoder.rb +34 -35
- metadata +79 -56
- 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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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 = {:
|
11
|
-
@google_city_hash = {:
|
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
|
-
|
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
|
59
|
-
assert_equal
|
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
|
63
|
-
assert_equal
|
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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
|
-
|
88
|
-
|
89
|
-
|
84
|
+
assert_equal 9, res.accuracy
|
85
|
+
end
|
86
|
+
end
|
90
87
|
|
91
|
-
|
92
|
-
|
93
|
-
|
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
|
-
|
97
|
-
assert_equal
|
98
|
-
assert_equal
|
99
|
-
assert_equal
|
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
|
102
|
-
assert_equal
|
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
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
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
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
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
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
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
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
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
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
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
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
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
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
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
|
-
|
198
|
-
|
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
|
-
|
201
|
-
|
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
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
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
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
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
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
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
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
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
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
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
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
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
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
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®ion=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®ion=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
|