geokit 1.10.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.hound.yml +2 -0
- data/.rubocop.yml +358 -0
- data/.travis.yml +4 -4
- data/CHANGELOG.md +16 -0
- data/Gemfile +3 -3
- data/README.markdown +19 -4
- data/Rakefile +11 -16
- data/fixtures/keys.yml +9 -0
- data/fixtures/vcr_cassettes/google_postal_town.yml +117 -0
- data/fixtures/vcr_cassettes/mapbox_forward_geocode.yml +30 -30
- data/fixtures/vcr_cassettes/mapbox_forward_geocode_city_only.yml +25 -25
- data/fixtures/vcr_cassettes/mapbox_forward_geocode_state_only.yml +71 -0
- data/fixtures/vcr_cassettes/mapbox_reverse_geocode.yml +25 -25
- data/fixtures/vcr_cassettes/test_component_filtering_off.yml +390 -0
- data/fixtures/vcr_cassettes/test_component_filtering_on.yml +164 -0
- data/fixtures/vcr_cassettes/test_component_filtering_on_without_filter.yml +404 -0
- data/geokit.gemspec +24 -23
- data/lib/geokit.rb +7 -7
- data/lib/geokit/core_ext.rb +1 -1
- data/lib/geokit/geo_loc.rb +25 -19
- data/lib/geokit/geocoders.rb +21 -30
- data/lib/geokit/geocoders/bing.rb +5 -4
- data/lib/geokit/geocoders/ca_geocoder.rb +10 -11
- data/lib/geokit/geocoders/fcc.rb +9 -9
- data/lib/geokit/geocoders/free_geo_ip.rb +8 -8
- data/lib/geokit/geocoders/geo_plugin.rb +7 -7
- data/lib/geokit/geocoders/geobytes.rb +10 -10
- data/lib/geokit/geocoders/geocodio.rb +14 -14
- data/lib/geokit/geocoders/geonames.rb +12 -12
- data/lib/geokit/geocoders/google.rb +89 -61
- data/lib/geokit/geocoders/ip.rb +9 -14
- data/lib/geokit/geocoders/mapbox.rb +30 -30
- data/lib/geokit/geocoders/mapquest.rb +12 -12
- data/lib/geokit/geocoders/maxmind.rb +1 -1
- data/lib/geokit/geocoders/opencage.rb +19 -19
- data/lib/geokit/geocoders/openstreetmap.rb +21 -19
- data/lib/geokit/geocoders/ripe.rb +7 -7
- data/lib/geokit/geocoders/us_geocoder.rb +5 -5
- data/lib/geokit/geocoders/yahoo.rb +46 -46
- data/lib/geokit/geocoders/yandex.rb +18 -17
- data/lib/geokit/inflectors.rb +5 -5
- data/lib/geokit/lat_lng.rb +5 -4
- data/lib/geokit/multi_geocoder.rb +4 -2
- data/lib/geokit/net_adapter/net_http.rb +3 -2
- data/lib/geokit/net_adapter/typhoeus.rb +2 -1
- data/lib/geokit/version.rb +1 -1
- data/test/coverage_loader.rb +25 -0
- data/test/helper.rb +18 -87
- data/test/test_base_geocoder.rb +44 -11
- data/test/test_bing_geocoder.rb +40 -48
- data/test/test_bounds.rb +1 -1
- data/test/test_ca_geocoder.rb +15 -15
- data/test/test_fcc_geocoder.rb +8 -9
- data/test/test_free_geo_ip_geocoder.rb +8 -10
- data/test/test_geo_plugin_geocoder.rb +21 -22
- data/test/test_geobytes_geocoder.rb +9 -11
- data/test/test_geocodio_geocoder.rb +12 -14
- data/test/test_geoloc.rb +48 -49
- data/test/test_geonames_geocoder.rb +19 -23
- data/test/test_google_geocoder.rb +197 -189
- data/test/test_inflector.rb +7 -7
- data/test/test_ipgeocoder.rb +32 -31
- data/test/test_latlng.rb +28 -28
- data/test/test_map_quest.rb +23 -27
- data/test/test_mapbox_geocoder.rb +38 -28
- data/test/test_mappable.rb +2 -2
- data/test/test_maxmind_geocoder.rb +16 -16
- data/test/test_multi_geocoder.rb +5 -5
- data/test/test_multi_ip_geocoder.rb +3 -3
- data/test/test_net_adapter.rb +4 -4
- data/test/test_opencage_geocoder.rb +58 -67
- data/test/test_openstreetmap_geocoder.rb +67 -65
- data/test/test_polygon.rb +4 -22
- data/test/test_ripe_geocoder.rb +21 -26
- data/test/test_us_geocoder.rb +21 -21
- data/test/test_useragent.rb +46 -0
- data/test/test_yahoo_geocoder.rb +35 -47
- data/test/test_yandex_geocoder.rb +29 -27
- data/test/vcr_loader.rb +18 -0
- metadata +20 -6
@@ -1,183 +1,183 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
require File.join(File.dirname(__FILE__),
|
2
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
3
3
|
|
4
4
|
class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
5
5
|
def setup
|
6
6
|
super
|
7
|
-
@full_address =
|
8
|
-
@full_address_short_zip =
|
9
|
-
@google_full_hash = {street_address:
|
10
|
-
@google_city_hash = {city:
|
7
|
+
@full_address = '100 Spear St Apt. 5, San Francisco, CA, 94105-1522, US'
|
8
|
+
@full_address_short_zip = '100 Spear St Apt. 5, San Francisco, CA, 94105, US'
|
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'}
|
11
11
|
|
12
12
|
@google_full_loc = Geokit::GeoLoc.new(@google_full_hash)
|
13
13
|
@google_city_loc = Geokit::GeoLoc.new(@google_city_hash)
|
14
|
+
|
15
|
+
@key_url = 'https://maps.googleapis.com/maps/api/geocode/json'
|
16
|
+
@base_url = 'https://maps.google.com/maps/api/geocode/json'
|
14
17
|
end
|
15
18
|
|
16
19
|
# Example from:
|
17
20
|
# https://developers.google.com/maps/documentation/business/webservices#signature_examples
|
18
21
|
def test_google_signature
|
19
|
-
cryptographic_key =
|
20
|
-
query_string =
|
21
|
-
signature =
|
22
|
-
assert_equal
|
22
|
+
cryptographic_key = 'vNIXE0xscrmjlyV-12Nj_BvUPaw='
|
23
|
+
query_string = '/maps/api/geocode/json?address=New+York&sensor=false&client=clientID'
|
24
|
+
signature = geocoder_class.send(:sign_gmap_bus_api_url, query_string, cryptographic_key)
|
25
|
+
assert_equal 'KrU1TzVQM7Ur0i8i7K3huiw3MsA=', signature
|
23
26
|
end
|
24
27
|
|
25
28
|
# Example from:
|
26
29
|
# https://developers.google.com/maps/documentation/business/webservices#signature_examples
|
27
30
|
def test_google_signature_and_url
|
28
|
-
|
29
|
-
|
30
|
-
url =
|
31
|
-
|
32
|
-
|
33
|
-
assert_equal "
|
31
|
+
geocoder_class.client_id = 'clientID'
|
32
|
+
geocoder_class.cryptographic_key = 'vNIXE0xscrmjlyV-12Nj_BvUPaw='
|
33
|
+
url = geocoder_class.send(:submit_url, 'address=New+York')
|
34
|
+
geocoder_class.client_id = nil
|
35
|
+
geocoder_class.cryptographic_key = nil
|
36
|
+
assert_equal "#{@key_url}?sensor=false&address=New+York&client=clientID&signature=9mevp7SoVsSKzF9nj-vApMYbatg=", url
|
34
37
|
end
|
35
38
|
|
36
39
|
def test_google_api_key
|
37
|
-
|
38
|
-
url =
|
39
|
-
|
40
|
-
assert_equal "
|
40
|
+
geocoder_class.api_key = 'someKey'
|
41
|
+
url = geocoder_class.send(:submit_url, 'address=New+York')
|
42
|
+
geocoder_class.api_key = nil
|
43
|
+
assert_equal "#{@key_url}?sensor=false&address=New+York&key=someKey", url
|
41
44
|
end
|
42
45
|
|
43
46
|
def test_google_insecure_url
|
44
47
|
Geokit::Geocoders.secure = false
|
45
|
-
url =
|
48
|
+
url = geocoder_class.send(:submit_url, 'address=New+York')
|
46
49
|
Geokit::Geocoders.secure = true
|
47
|
-
assert_equal
|
50
|
+
assert_equal 'http://maps.google.com/maps/api/geocode/json?sensor=false&address=New+York', url
|
48
51
|
end
|
49
52
|
|
50
53
|
def test_google_full_address
|
51
|
-
|
52
|
-
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@address)}"
|
54
|
+
url = "#{@base_url}?sensor=false&address=#{escape(@address)}"
|
53
55
|
TestHelper.expects(:last_url).with(url)
|
54
|
-
res =
|
55
|
-
assert_equal
|
56
|
-
assert_equal
|
56
|
+
res = geocode(@address, :google_full_short)
|
57
|
+
assert_equal 'CA', res.state
|
58
|
+
assert_equal 'San Francisco', res.city
|
57
59
|
assert_array_in_delta [37.7749295, -122.4194155], res.to_a # slightly dif from yahoo
|
58
60
|
assert res.is_us?
|
59
|
-
assert_equal
|
60
|
-
assert_equal
|
61
|
-
end
|
61
|
+
assert_equal 'San Francisco, CA, USA', res.full_address # slightly different from yahoo
|
62
|
+
assert_equal 'google', res.provider
|
62
63
|
end
|
63
64
|
|
64
65
|
def test_google_full_address_with_geo_loc
|
65
|
-
|
66
|
-
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@full_address_short_zip)}"
|
66
|
+
url = "#{@base_url}?sensor=false&address=#{escape(@full_address_short_zip)}"
|
67
67
|
TestHelper.expects(:last_url).with(url)
|
68
|
-
res =
|
69
|
-
assert_equal
|
70
|
-
assert_equal
|
68
|
+
res = geocode(@google_full_loc, :google_full)
|
69
|
+
assert_equal 'CA', res.state
|
70
|
+
assert_equal 'San Francisco', res.city
|
71
71
|
assert_array_in_delta [37.7921509, -122.394], res.to_a # slightly dif from yahoo
|
72
72
|
assert res.is_us?
|
73
|
-
assert_equal
|
74
|
-
assert_equal
|
75
|
-
end
|
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
|
76
75
|
end
|
77
76
|
|
78
77
|
def test_google_full_address_accuracy
|
79
|
-
|
80
|
-
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@full_address_short_zip)}"
|
78
|
+
url = "#{@base_url}?sensor=false&address=#{escape(@full_address_short_zip)}"
|
81
79
|
TestHelper.expects(:last_url).with(url)
|
82
|
-
res =
|
80
|
+
res = geocode(@google_full_loc, :google_full)
|
83
81
|
|
84
82
|
assert_equal 9, res.accuracy
|
85
|
-
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_google_postal_town
|
86
|
+
address = 'London SE3 0JB, UK'
|
87
|
+
url = "#{@base_url}?sensor=false&address=#{escape(address)}"
|
88
|
+
TestHelper.expects(:last_url).with(url)
|
89
|
+
res = geocode(address, :google_postal_town)
|
90
|
+
assert_equal 'Kidbrooke Way', res.street_address
|
91
|
+
assert_equal 'England', res.state
|
92
|
+
assert_equal 'London', res.city
|
93
|
+
assert_equal 'Greater London', res.district
|
94
|
+
assert_equal 'SE3 0JB', res.zip
|
95
|
+
assert_equal '51.465923,0.0290915', res.ll
|
96
|
+
assert !res.is_us?
|
97
|
+
assert_equal 'Kidbrooke Way, London SE3 0JB, UK', res.full_address
|
98
|
+
assert_equal 'zip+4', res.precision
|
99
|
+
assert_equal 'google', res.provider
|
86
100
|
end
|
87
101
|
|
88
102
|
def test_google_city
|
89
|
-
|
90
|
-
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@address)}"
|
103
|
+
url = "#{@base_url}?sensor=false&address=#{escape(@address)}"
|
91
104
|
TestHelper.expects(:last_url).with(url)
|
92
|
-
res =
|
105
|
+
res = geocode(@address, :google_city)
|
93
106
|
assert_nil res.street_address
|
94
|
-
assert_equal
|
95
|
-
assert_equal
|
96
|
-
assert_equal
|
107
|
+
assert_equal 'CA', res.state
|
108
|
+
assert_equal 'San Francisco', res.city
|
109
|
+
assert_equal '37.7749295,-122.4194155', res.ll
|
97
110
|
assert res.is_us?
|
98
|
-
assert_equal
|
99
|
-
assert_equal
|
100
|
-
assert_equal
|
101
|
-
end
|
111
|
+
assert_equal 'San Francisco, CA, USA', res.full_address
|
112
|
+
assert_equal 'city', res.precision
|
113
|
+
assert_equal 'google', res.provider
|
102
114
|
end
|
103
115
|
|
104
116
|
def test_google_sublocality
|
105
|
-
@address =
|
106
|
-
|
107
|
-
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@address)}"
|
117
|
+
@address = '682 prospect place Brooklyn ny 11216'
|
118
|
+
url = "#{@base_url}?sensor=false&address=#{escape(@address)}"
|
108
119
|
TestHelper.expects(:last_url).with(url)
|
109
|
-
res =
|
110
|
-
assert_equal
|
111
|
-
assert_equal
|
112
|
-
assert_equal
|
113
|
-
assert_equal
|
120
|
+
res = geocode(@address, :google_sublocality)
|
121
|
+
assert_equal '682 Prospect Place', res.street_address
|
122
|
+
assert_equal 'NY', res.state
|
123
|
+
assert_equal 'Brooklyn', res.city
|
124
|
+
assert_equal '40.6745812,-73.9541582', res.ll
|
114
125
|
assert res.is_us?
|
115
|
-
assert_equal
|
116
|
-
assert_equal
|
117
|
-
assert_equal
|
118
|
-
end
|
126
|
+
assert_equal '682 Prospect Place, Brooklyn, NY 11216, USA', res.full_address
|
127
|
+
assert_equal 'address', res.precision
|
128
|
+
assert_equal 'google', res.provider
|
119
129
|
end
|
120
130
|
|
121
131
|
def test_google_administrative_area_level_3
|
122
|
-
@address =
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
assert_equal "google", res.provider
|
135
|
-
end
|
132
|
+
@address = '8 Barkwood Lane, Clifton Park, NY 12065'
|
133
|
+
url = "#{@base_url}?sensor=false&address=#{escape(@address)}"
|
134
|
+
TestHelper.expects(:last_url).with(url)
|
135
|
+
res = geocode(@address, :google_administrative_area_level_3)
|
136
|
+
assert_equal '8 Barkwood Lane', res.street_address
|
137
|
+
assert_equal 'NY', res.state
|
138
|
+
assert_equal 'Clifton Park', res.city
|
139
|
+
assert_equal '42.829583,-73.788174', res.ll
|
140
|
+
assert res.is_us?
|
141
|
+
assert_equal '8 Barkwood Lane, Clifton Park, NY 12065, USA', res.full_address
|
142
|
+
assert_equal 'building', res.precision
|
143
|
+
assert_equal 'google', res.provider
|
136
144
|
end
|
137
145
|
|
138
146
|
def test_google_city_improved_ordering
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
assert_equal "62510 Arques, France", res.full_address
|
143
|
-
end
|
147
|
+
res = geocode('62510, fr', :google_city_ordering, bias: 'fr')
|
148
|
+
assert_equal 'zip+4', res.precision
|
149
|
+
assert_equal '62510 Arques, France', res.full_address
|
144
150
|
end
|
145
151
|
|
146
152
|
def test_google_city_accuracy
|
147
|
-
|
148
|
-
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@address)}"
|
153
|
+
url = "#{@base_url}?sensor=false&address=#{escape(@address)}"
|
149
154
|
TestHelper.expects(:last_url).with(url)
|
150
|
-
res =
|
151
|
-
assert_equal
|
155
|
+
res = geocode(@address, :google_city)
|
156
|
+
assert_equal 'city', res.precision
|
152
157
|
assert_equal 4, res.accuracy
|
153
|
-
end
|
154
158
|
end
|
155
159
|
|
156
160
|
def test_google_city_with_geo_loc
|
157
|
-
|
158
|
-
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@address)}"
|
161
|
+
url = "#{@base_url}?sensor=false&address=#{escape(@address)}"
|
159
162
|
TestHelper.expects(:last_url).with(url)
|
160
|
-
res =
|
161
|
-
assert_equal
|
162
|
-
assert_equal
|
163
|
-
assert_equal
|
163
|
+
res = geocode(@google_city_loc, :google_city)
|
164
|
+
assert_equal 'CA', res.state
|
165
|
+
assert_equal 'San Francisco', res.city
|
166
|
+
assert_equal '37.7749295,-122.4194155', res.ll
|
164
167
|
assert res.is_us?
|
165
|
-
assert_equal
|
168
|
+
assert_equal 'San Francisco, CA, USA', res.full_address
|
166
169
|
assert_nil res.street_address
|
167
|
-
assert_equal
|
168
|
-
assert_equal
|
169
|
-
end
|
170
|
+
assert_equal 'city', res.precision
|
171
|
+
assert_equal 'google', res.provider
|
170
172
|
end
|
171
173
|
|
172
174
|
def test_google_suggested_bounds
|
173
|
-
|
174
|
-
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@full_address_short_zip)}"
|
175
|
+
url = "#{@base_url}?sensor=false&address=#{escape(@full_address_short_zip)}"
|
175
176
|
TestHelper.expects(:last_url).with(url)
|
176
|
-
res =
|
177
|
+
res = geocode(@google_full_loc, :google_full)
|
177
178
|
assert_instance_of Geokit::Bounds, res.suggested_bounds
|
178
179
|
assert_array_in_delta [37.7908019197085, -122.3953489802915], res.suggested_bounds.sw.to_a
|
179
180
|
assert_array_in_delta [37.7934998802915, -122.3926510197085], res.suggested_bounds.ne.to_a
|
180
|
-
end
|
181
181
|
end
|
182
182
|
|
183
183
|
def test_google_suggested_bounds_url
|
@@ -185,167 +185,175 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
185
185
|
Geokit::LatLng.new(33.7036917, -118.6681759),
|
186
186
|
Geokit::LatLng.new(34.3373061, -118.1552891),
|
187
187
|
)
|
188
|
-
url = "
|
189
|
-
|
190
|
-
|
188
|
+
url = "#{@base_url}?sensor=false&address=Winnetka&bounds=33.7036917%2C-118.6681759%7C34.3373061%2C-118.1552891"
|
189
|
+
geocoder_class.expects(:call_geocoder_service).with(url)
|
190
|
+
geocode('Winnetka', bias: bounds)
|
191
191
|
end
|
192
192
|
|
193
193
|
def test_google_place_id
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
assert_equal 'EjExMDAgU3BlYXIgU3RyZWV0ICM1LCBTYW4gRnJhbmNpc2NvLCBDQSA5NDEwNSwgVVNB', res.place_id
|
199
|
-
end
|
194
|
+
url = "#{@base_url}?sensor=false&address=#{escape(@full_address_short_zip)}"
|
195
|
+
TestHelper.expects(:last_url).with(url)
|
196
|
+
res = geocode(@full_address_short_zip, :google_full_v3_20)
|
197
|
+
assert_equal 'EjExMDAgU3BlYXIgU3RyZWV0ICM1LCBTYW4gRnJhbmNpc2NvLCBDQSA5NDEwNSwgVVNB', res.place_id
|
200
198
|
end
|
201
199
|
|
202
200
|
def test_google_formatted_address
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
assert_equal '100 Spear Street #5, San Francisco, CA 94105, USA', res.formatted_address
|
208
|
-
end
|
201
|
+
url = "#{@base_url}?sensor=false&address=#{escape(@full_address_short_zip)}"
|
202
|
+
TestHelper.expects(:last_url).with(url)
|
203
|
+
res = geocode(@full_address_short_zip, :google_full_v3_20)
|
204
|
+
assert_equal '100 Spear Street #5, San Francisco, CA 94105, USA', res.formatted_address
|
209
205
|
end
|
210
206
|
|
211
207
|
def test_service_unavailable
|
212
208
|
response = MockFailure.new
|
213
|
-
url = "
|
214
|
-
|
215
|
-
assert !
|
209
|
+
url = "#{@base_url}?sensor=false&address=#{escape(@address)}"
|
210
|
+
geocoder_class.expects(:call_geocoder_service).with(url).returns(response)
|
211
|
+
assert !geocode(@google_city_loc).success
|
216
212
|
end
|
217
213
|
|
218
214
|
def test_multiple_results
|
219
|
-
|
220
|
-
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape('via Sandro Pertini 8, Ossona, MI')}"
|
215
|
+
url = "#{@base_url}?sensor=false&address=#{escape('via Sandro Pertini 8, Ossona, MI')}"
|
221
216
|
TestHelper.expects(:last_url).with(url)
|
222
|
-
res =
|
217
|
+
res = geocode('via Sandro Pertini 8, Ossona, MI', :google_multi)
|
223
218
|
assert_equal 5, res.all.size
|
224
219
|
res = res.all[0]
|
225
|
-
assert_equal
|
226
|
-
assert_equal
|
220
|
+
assert_equal 'Lombardy', res.state
|
221
|
+
assert_equal 'Mesero', res.city
|
227
222
|
assert_array_in_delta [45.4966218, 8.852694], res.to_a
|
228
223
|
assert !res.is_us?
|
229
|
-
assert_equal
|
230
|
-
assert_equal
|
231
|
-
assert_equal
|
224
|
+
assert_equal 'Via Sandro Pertini, 8, 20010 Mesero Milan, Italy', res.full_address
|
225
|
+
assert_equal '8 Via Sandro Pertini', res.street_address
|
226
|
+
assert_equal 'google', res.provider
|
232
227
|
|
233
228
|
res = res.all[4]
|
234
|
-
assert_equal
|
235
|
-
assert_equal
|
229
|
+
assert_equal 'Lombardy', res.state
|
230
|
+
assert_equal 'Ossona', res.city
|
236
231
|
assert_array_in_delta [45.5074444, 8.90232], res.to_a
|
237
232
|
assert !res.is_us?
|
238
|
-
assert_equal
|
239
|
-
assert_equal
|
240
|
-
assert_equal
|
241
|
-
end
|
233
|
+
assert_equal 'Via S. Pertini, 20010 Ossona Milan, Italy', res.full_address
|
234
|
+
assert_equal 'Via S. Pertini', res.street_address
|
235
|
+
assert_equal 'google', res.provider
|
242
236
|
end
|
243
237
|
|
244
238
|
def test_reverse_geocode
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&latlng=#{Geokit::Inflector.url_escape(madrid.ll)}"
|
239
|
+
madrid = Geokit::GeoLoc.new
|
240
|
+
madrid.lat, madrid.lng = '40.4167413', '-3.7032498'
|
241
|
+
url = "#{@base_url}?sensor=false&latlng=#{escape(madrid.ll)}"
|
249
242
|
TestHelper.expects(:last_url).with(url)
|
250
|
-
res =
|
243
|
+
res = reverse_geocode(madrid.ll, :google_reverse_madrid)
|
251
244
|
|
252
245
|
assert_equal madrid.lat.to_s.slice(1..5), res.lat.to_s.slice(1..5)
|
253
246
|
assert_equal madrid.lng.to_s.slice(1..5), res.lng.to_s.slice(1..5)
|
254
|
-
assert_equal
|
255
|
-
assert_equal
|
247
|
+
assert_equal 'ES', res.country_code
|
248
|
+
assert_equal 'google', res.provider
|
256
249
|
|
257
|
-
assert_equal
|
258
|
-
assert_equal
|
250
|
+
assert_equal 'Madrid', res.city
|
251
|
+
assert_equal 'Community of Madrid', res.state
|
259
252
|
|
260
|
-
assert_equal
|
261
|
-
assert_equal
|
253
|
+
assert_equal 'Spain', res.country
|
254
|
+
assert_equal '28013', res.zip
|
262
255
|
assert_equal true, res.success
|
263
|
-
end
|
264
256
|
end
|
265
257
|
|
266
258
|
def test_reverse_geocode_language
|
267
|
-
|
268
|
-
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&latlng=40.416%2C-3.703&language=es"
|
259
|
+
url = "#{@base_url}?sensor=false&latlng=40.416%2C-3.703&language=es"
|
269
260
|
TestHelper.expects(:last_url).with(url)
|
270
|
-
language_result =
|
261
|
+
language_result = reverse_geocode('40.416,-3.703', :google_reverse_madrid_es, language: 'es')
|
271
262
|
|
272
|
-
assert_equal
|
273
|
-
assert_equal
|
274
|
-
end
|
263
|
+
assert_equal 'ES', language_result.country_code
|
264
|
+
assert_equal 'Madrid', language_result.city
|
275
265
|
end
|
276
266
|
|
277
267
|
def test_language_response
|
278
|
-
|
279
|
-
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=Hanoi&language=FR"
|
268
|
+
url = "#{@base_url}?sensor=false&address=Hanoi&language=FR"
|
280
269
|
TestHelper.expects(:last_url).with(url)
|
281
|
-
language_result =
|
270
|
+
language_result = geocode('Hanoi', :google_language_response_fr, language: 'FR')
|
282
271
|
|
283
|
-
assert_equal
|
272
|
+
assert_equal 'VN', language_result.country_code
|
284
273
|
assert_equal "Hanoï", language_result.city
|
285
|
-
end
|
286
274
|
end
|
287
275
|
|
288
276
|
def test_too_many_queries
|
289
277
|
response = MockSuccess.new
|
290
278
|
response.expects(:body).returns '{"status": "OVER_QUERY_LIMIT", "error_message": "quota exceeded!"}'
|
291
|
-
url = "
|
292
|
-
|
279
|
+
url = "#{@base_url}?sensor=false&address=#{escape(@address)}"
|
280
|
+
geocoder_class.expects(:call_geocoder_service).with(url).returns(response)
|
293
281
|
err = assert_raise Geokit::Geocoders::TooManyQueriesError do
|
294
|
-
|
282
|
+
geocode(@address)
|
295
283
|
end
|
296
|
-
assert_equal
|
284
|
+
assert_equal 'quota exceeded!', err.message
|
297
285
|
end
|
298
286
|
|
299
287
|
def test_access_denied
|
300
288
|
response = MockSuccess.new
|
301
289
|
response.expects(:body).returns '{"status": "REQUEST_DENIED", "error_message": "access denied!"}'
|
302
|
-
url = "
|
303
|
-
|
290
|
+
url = "#{@base_url}?sensor=false&address=#{escape(@address)}"
|
291
|
+
geocoder_class.expects(:call_geocoder_service).with(url).returns(response)
|
304
292
|
err = assert_raise Geokit::Geocoders::AccessDeniedError do
|
305
|
-
|
293
|
+
geocode(@address)
|
306
294
|
end
|
307
|
-
assert_equal
|
295
|
+
assert_equal 'access denied!', err.message
|
308
296
|
end
|
309
297
|
|
310
298
|
def test_invalid_request
|
311
299
|
response = MockSuccess.new
|
312
300
|
response.expects(:body).returns '{"results" : [], "status" : "INVALID_REQUEST", "error_message": "error!" }'
|
313
|
-
url = "
|
314
|
-
|
301
|
+
url = "#{@base_url}?sensor=false&address=#{escape("3961 V\u00EDa Marisol")}"
|
302
|
+
geocoder_class.expects(:call_geocoder_service).with(url).returns(response)
|
315
303
|
err = assert_raise Geokit::Geocoders::GeocodeError do
|
316
|
-
|
304
|
+
geocode("3961 V\u00EDa Marisol")
|
317
305
|
end
|
318
|
-
assert_equal
|
306
|
+
assert_equal 'error!', err.message
|
319
307
|
end
|
320
308
|
|
321
309
|
def test_country_code_biasing_toledo
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
biased_result = Geokit::Geocoders::GoogleGeocoder.geocode("toledo", bias: "es")
|
310
|
+
url = "#{@base_url}?sensor=false&address=toledo®ion=es"
|
311
|
+
TestHelper.expects(:last_url).with(url)
|
312
|
+
biased_result = geocode('toledo', :google_country_code_biased_result_toledo, bias: 'es')
|
326
313
|
|
327
|
-
|
328
|
-
|
329
|
-
end
|
314
|
+
assert_equal 'ES', biased_result.country_code
|
315
|
+
assert_equal 'CM', biased_result.state
|
330
316
|
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
biased_result = Geokit::Geocoders::GoogleGeocoder.geocode("toledo")
|
317
|
+
url = "#{@base_url}?sensor=false&address=toledo"
|
318
|
+
TestHelper.expects(:last_url).with(url)
|
319
|
+
biased_result = geocode('toledo', :google_result_toledo_default_bias)
|
335
320
|
|
336
|
-
|
337
|
-
|
338
|
-
end
|
321
|
+
assert_equal 'US', biased_result.country_code
|
322
|
+
assert_equal 'OH', biased_result.state
|
339
323
|
end
|
340
324
|
|
341
325
|
def test_country_code_biasing_orly
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
biased_result = Geokit::Geocoders::GoogleGeocoder.geocode("orly", bias: "fr")
|
326
|
+
url = "#{@base_url}?sensor=false&address=orly®ion=fr"
|
327
|
+
TestHelper.expects(:last_url).with(url)
|
328
|
+
biased_result = geocode('orly', :google_country_code_biased_result_orly, bias: 'fr')
|
346
329
|
|
347
|
-
|
348
|
-
|
349
|
-
|
330
|
+
assert_equal 'FR', biased_result.country_code
|
331
|
+
assert_equal 'Orly, France', biased_result.full_address
|
332
|
+
end
|
333
|
+
|
334
|
+
|
335
|
+
def test_component_filtering
|
336
|
+
url = 'https://maps.google.com/maps/api/geocode/json?sensor=false&address=austin'
|
337
|
+
TestHelper.expects(:last_url).with(url)
|
338
|
+
filtered_result = geocode('austin', :test_component_filtering_off)
|
339
|
+
|
340
|
+
assert_equal 'TX', filtered_result.state
|
341
|
+
assert_equal 'Austin, TX, USA', filtered_result.full_address
|
342
|
+
|
343
|
+
url = 'https://maps.google.com/maps/api/geocode/json?sensor=false&address=austin&components=administrative_area:il%7Ccountry:us'
|
344
|
+
TestHelper.expects(:last_url).with(url)
|
345
|
+
filtered_result = geocode('austin',
|
346
|
+
:test_component_filtering_on,
|
347
|
+
components: { administrative_area: 'IL', country: 'US' })
|
348
|
+
|
349
|
+
assert_equal 'IL', filtered_result.state
|
350
|
+
assert_equal 'Austin, Chicago, IL, USA', filtered_result.full_address
|
351
|
+
|
352
|
+
url = 'https://maps.google.com/maps/api/geocode/json?sensor=false&address=austin'
|
353
|
+
TestHelper.expects(:last_url).with(url)
|
354
|
+
filtered_result = geocode('austin', :test_component_filtering_on_without_filter, components: nil)
|
355
|
+
|
356
|
+
assert_equal 'TX', filtered_result.state
|
357
|
+
assert_equal 'Austin, TX, USA', filtered_result.full_address
|
350
358
|
end
|
351
359
|
end
|