geocoder 1.1.5 → 1.1.6
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.
- data/.travis.yml +4 -0
- data/{CHANGELOG.rdoc → CHANGELOG.md} +90 -37
- data/README.md +96 -45
- data/examples/autoexpire_cache.rb +1 -3
- data/lib/generators/geocoder/config/templates/initializer.rb +18 -22
- data/lib/geocoder.rb +2 -4
- data/lib/geocoder/cache.rb +2 -1
- data/lib/geocoder/calculations.rb +12 -12
- data/lib/geocoder/cli.rb +10 -11
- data/lib/geocoder/configuration.rb +67 -43
- data/lib/geocoder/configuration_hash.rb +11 -0
- data/lib/geocoder/exceptions.rb +3 -0
- data/lib/geocoder/lookup.rb +1 -1
- data/lib/geocoder/lookups/base.rb +59 -16
- data/lib/geocoder/lookups/bing.rb +21 -11
- data/lib/geocoder/lookups/freegeoip.rb +8 -4
- data/lib/geocoder/lookups/geocoder_ca.rb +11 -7
- data/lib/geocoder/lookups/google.rb +18 -9
- data/lib/geocoder/lookups/google_premier.rb +16 -8
- data/lib/geocoder/lookups/mapquest.rb +12 -5
- data/lib/geocoder/lookups/maxmind.rb +72 -0
- data/lib/geocoder/lookups/nominatim.rb +13 -8
- data/lib/geocoder/lookups/test.rb +4 -0
- data/lib/geocoder/lookups/yahoo.rb +38 -11
- data/lib/geocoder/lookups/yandex.rb +17 -9
- data/lib/geocoder/query.rb +17 -8
- data/lib/geocoder/request.rb +7 -1
- data/lib/geocoder/results/google.rb +6 -0
- data/lib/geocoder/results/maxmind.rb +136 -0
- data/lib/geocoder/results/nominatim.rb +0 -10
- data/lib/geocoder/sql.rb +6 -4
- data/lib/geocoder/stores/active_record.rb +5 -5
- data/lib/geocoder/stores/base.rb +3 -2
- data/lib/geocoder/version.rb +1 -1
- data/lib/hash_recursive_merge.rb +74 -0
- data/lib/oauth_util.rb +8 -2
- data/test/cache_test.rb +2 -2
- data/test/calculations_test.rb +4 -4
- data/test/configuration_test.rb +26 -51
- data/test/error_handling_test.rb +4 -4
- data/test/fixtures/bing_invalid_key +1 -0
- data/test/fixtures/{bing_madison_square_garden.json → bing_madison_square_garden} +0 -0
- data/test/fixtures/{bing_no_results.json → bing_no_results} +0 -0
- data/test/fixtures/{bing_reverse.json → bing_reverse} +0 -0
- data/test/fixtures/{freegeoip_74_200_247_59.json → freegeoip_74_200_247_59} +0 -0
- data/test/fixtures/{freegeoip_no_results.json → freegeoip_no_results} +0 -0
- data/test/fixtures/{geocoder_ca_madison_square_garden.json → geocoder_ca_madison_square_garden} +0 -0
- data/test/fixtures/{geocoder_ca_no_results.json → geocoder_ca_no_results} +0 -0
- data/test/fixtures/{geocoder_ca_reverse.json → geocoder_ca_reverse} +0 -0
- data/test/fixtures/{google_garbage.json → google_garbage} +0 -0
- data/test/fixtures/{google_madison_square_garden.json → google_madison_square_garden} +0 -0
- data/test/fixtures/{google_no_city_data.json → google_no_city_data} +0 -0
- data/test/fixtures/{google_no_locality.json → google_no_locality} +0 -0
- data/test/fixtures/{google_no_results.json → google_no_results} +0 -0
- data/test/fixtures/{mapquest_madison_square_garden.json → mapquest_madison_square_garden} +0 -0
- data/test/fixtures/{mapquest_no_results.json → mapquest_no_results} +0 -0
- data/test/fixtures/maxmind_24_24_24_21 +1 -0
- data/test/fixtures/maxmind_24_24_24_22 +1 -0
- data/test/fixtures/maxmind_24_24_24_23 +1 -0
- data/test/fixtures/maxmind_24_24_24_24 +1 -0
- data/test/fixtures/maxmind_74_200_247_59 +1 -0
- data/test/fixtures/maxmind_invalid_key +1 -0
- data/test/fixtures/maxmind_no_results +1 -0
- data/test/fixtures/{nominatim_madison_square_garden.json → nominatim_madison_square_garden} +0 -0
- data/test/fixtures/{nominatim_no_results.json → nominatim_no_results} +0 -0
- data/test/fixtures/{yahoo_error.json → yahoo_error} +0 -0
- data/test/fixtures/yahoo_invalid_key +2 -0
- data/test/fixtures/{yahoo_madison_square_garden.json → yahoo_madison_square_garden} +0 -0
- data/test/fixtures/{yahoo_no_results.json → yahoo_no_results} +0 -0
- data/test/fixtures/yahoo_over_limit +2 -0
- data/test/fixtures/{yandex_invalid_key.json → yandex_invalid_key} +0 -0
- data/test/fixtures/{yandex_kremlin.json → yandex_kremlin} +0 -0
- data/test/fixtures/{yandex_no_results.json → yandex_no_results} +0 -0
- data/test/https_test.rb +3 -3
- data/test/integration/smoke_test.rb +2 -2
- data/test/lookup_test.rb +82 -5
- data/test/oauth_util_test.rb +30 -0
- data/test/proxy_test.rb +2 -2
- data/test/query_test.rb +3 -0
- data/test/result_test.rb +2 -2
- data/test/services_test.rb +121 -44
- data/test/test_helper.rb +44 -109
- data/test/test_mode_test.rb +3 -3
- metadata +42 -33
data/test/result_test.rb
CHANGED
@@ -5,7 +5,7 @@ class ResultTest < Test::Unit::TestCase
|
|
5
5
|
|
6
6
|
def test_result_has_required_attributes
|
7
7
|
Geocoder::Lookup.all_services_except_test.each do |l|
|
8
|
-
Geocoder
|
8
|
+
Geocoder.configure(:lookup => l)
|
9
9
|
set_api_key!(l)
|
10
10
|
result = Geocoder.search([45.423733, -75.676333]).first
|
11
11
|
assert_result_has_required_attributes(result)
|
@@ -16,7 +16,7 @@ class ResultTest < Test::Unit::TestCase
|
|
16
16
|
private # ------------------------------------------------------------------
|
17
17
|
|
18
18
|
def assert_result_has_required_attributes(result)
|
19
|
-
m = "Lookup #{Geocoder
|
19
|
+
m = "Lookup #{Geocoder.config.lookup} does not support %s attribute."
|
20
20
|
assert result.coordinates.is_a?(Array), m % "coordinates"
|
21
21
|
assert result.latitude.is_a?(Float), m % "latitude"
|
22
22
|
assert result.longitude.is_a?(Float), m % "longitude"
|
data/test/services_test.rb
CHANGED
@@ -3,20 +3,6 @@ require 'test_helper'
|
|
3
3
|
|
4
4
|
class ServicesTest < Test::Unit::TestCase
|
5
5
|
|
6
|
-
|
7
|
-
def test_query_url_contains_values_in_params_hash
|
8
|
-
Geocoder::Lookup.all_services_except_test.each do |l|
|
9
|
-
next if l == :freegeoip # does not use query string
|
10
|
-
set_api_key!(l)
|
11
|
-
url = Geocoder::Lookup.get(l).send(:query_url, Geocoder::Query.new(
|
12
|
-
"test", :params => {:one_in_the_hand => "two in the bush"}
|
13
|
-
))
|
14
|
-
# should be "+"s for all lookups except Yahoo
|
15
|
-
assert_match /one_in_the_hand=two(%20|\+)in(%20|\+)the(%20|\+)bush/, url,
|
16
|
-
"Lookup #{l} does not appear to support arbitrary params in URL"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
6
|
# --- Google ---
|
21
7
|
|
22
8
|
def test_google_result_components
|
@@ -25,6 +11,12 @@ class ServicesTest < Test::Unit::TestCase
|
|
25
11
|
result.address_components_of_type(:sublocality).first['long_name']
|
26
12
|
end
|
27
13
|
|
14
|
+
def test_google_result_components_contains_route
|
15
|
+
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
16
|
+
assert_equal "Penn Plaza",
|
17
|
+
result.address_components_of_type(:route).first['long_name']
|
18
|
+
end
|
19
|
+
|
28
20
|
def test_google_returns_city_when_no_locality_in_result
|
29
21
|
result = Geocoder.search("no locality").first
|
30
22
|
assert_equal "Haram", result.city
|
@@ -43,17 +35,46 @@ class ServicesTest < Test::Unit::TestCase
|
|
43
35
|
|
44
36
|
def test_google_query_url_contains_bounds
|
45
37
|
lookup = Geocoder::Lookup::Google.new
|
46
|
-
url = lookup.
|
38
|
+
url = lookup.query_url(Geocoder::Query.new(
|
47
39
|
"Some Intersection",
|
48
40
|
:bounds => [[40.0, -120.0], [39.0, -121.0]]
|
49
41
|
))
|
50
42
|
assert_match /bounds=40.0+%2C-120.0+%7C39.0+%2C-121.0+/, url
|
51
43
|
end
|
52
44
|
|
45
|
+
def test_google_query_url_contains_region
|
46
|
+
lookup = Geocoder::Lookup::Google.new
|
47
|
+
url = lookup.query_url(Geocoder::Query.new(
|
48
|
+
"Some Intersection",
|
49
|
+
:region => "gb"
|
50
|
+
))
|
51
|
+
assert_match /region=gb/, url
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_google_query_url_contains_components_when_given_as_string
|
55
|
+
lookup = Geocoder::Lookup::Google.new
|
56
|
+
url = lookup.query_url(Geocoder::Query.new(
|
57
|
+
"Some Intersection",
|
58
|
+
:components => "locality:ES"
|
59
|
+
))
|
60
|
+
formatted = "components=" + CGI.escape("locality:ES")
|
61
|
+
assert url.include?(formatted), "Expected #{formatted} to be included in #{url}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_google_query_url_contains_components_when_given_as_array
|
65
|
+
lookup = Geocoder::Lookup::Google.new
|
66
|
+
url = lookup.query_url(Geocoder::Query.new(
|
67
|
+
"Some Intersection",
|
68
|
+
:components => ["country:ES", "locality:ES"]
|
69
|
+
))
|
70
|
+
formatted = "components=" + CGI.escape("country:ES|locality:ES")
|
71
|
+
assert url.include?(formatted), "Expected #{formatted} to be included in #{url}"
|
72
|
+
end
|
73
|
+
|
53
74
|
# --- Google Premier ---
|
54
75
|
|
55
76
|
def test_google_premier_result_components
|
56
|
-
Geocoder
|
77
|
+
Geocoder.configure(:lookup => :google_premier)
|
57
78
|
set_api_key!(:google_premier)
|
58
79
|
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
59
80
|
assert_equal "Manhattan",
|
@@ -61,21 +82,23 @@ class ServicesTest < Test::Unit::TestCase
|
|
61
82
|
end
|
62
83
|
|
63
84
|
def test_google_premier_query_url
|
64
|
-
Geocoder
|
85
|
+
Geocoder.configure(:api_key => ["deadbeef", "gme-test", "test-dev"])
|
65
86
|
assert_equal "http://maps.googleapis.com/maps/api/geocode/json?address=Madison+Square+Garden%2C+New+York%2C+NY&channel=test-dev&client=gme-test&language=en&sensor=false&signature=doJvJqX7YJzgV9rJ0DnVkTGZqTg=",
|
66
|
-
Geocoder::Lookup::GooglePremier.new.
|
87
|
+
Geocoder::Lookup::GooglePremier.new.query_url(Geocoder::Query.new("Madison Square Garden, New York, NY"))
|
67
88
|
end
|
68
89
|
|
69
90
|
|
70
91
|
# --- Yahoo ---
|
71
92
|
|
72
93
|
def test_yahoo_no_results
|
73
|
-
Geocoder
|
94
|
+
Geocoder.configure(:lookup => :yahoo)
|
95
|
+
set_api_key!(:yahoo)
|
74
96
|
assert_equal [], Geocoder.search("no results")
|
75
97
|
end
|
76
98
|
|
77
99
|
def test_yahoo_error
|
78
|
-
Geocoder
|
100
|
+
Geocoder.configure(:lookup => :yahoo)
|
101
|
+
set_api_key!(:yahoo)
|
79
102
|
# keep test output clean: suppress timeout warning
|
80
103
|
orig = $VERBOSE; $VERBOSE = nil
|
81
104
|
assert_equal [], Geocoder.search("error")
|
@@ -84,34 +107,32 @@ class ServicesTest < Test::Unit::TestCase
|
|
84
107
|
end
|
85
108
|
|
86
109
|
def test_yahoo_result_components
|
87
|
-
Geocoder
|
110
|
+
Geocoder.configure(:lookup => :yahoo)
|
111
|
+
set_api_key!(:yahoo)
|
88
112
|
result = Geocoder.search("madison square garden").first
|
89
113
|
assert_equal "10001", result.postal_code
|
90
114
|
end
|
91
115
|
|
92
116
|
def test_yahoo_address_formatting
|
93
|
-
Geocoder
|
117
|
+
Geocoder.configure(:lookup => :yahoo)
|
118
|
+
set_api_key!(:yahoo)
|
94
119
|
result = Geocoder.search("madison square garden").first
|
95
120
|
assert_equal "Madison Square Garden, New York, NY 10001, United States", result.address
|
96
121
|
end
|
97
122
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
Geocoder::Configuration.lookup = :yandex
|
105
|
-
assert_equal [], Geocoder.search("invalid key")
|
106
|
-
ensure
|
107
|
-
$VERBOSE = orig
|
123
|
+
def test_yahoo_raises_exception_when_over_query_limit
|
124
|
+
Geocoder.configure(:always_raise => [Geocoder::OverQueryLimitError])
|
125
|
+
l = Geocoder::Lookup.get(:yahoo)
|
126
|
+
assert_raises Geocoder::OverQueryLimitError do
|
127
|
+
l.send(:results, Geocoder::Query.new("over limit"))
|
128
|
+
end
|
108
129
|
end
|
109
130
|
|
110
|
-
|
111
131
|
# --- Geocoder.ca ---
|
112
132
|
|
113
133
|
def test_geocoder_ca_result_components
|
114
|
-
Geocoder
|
134
|
+
Geocoder.configure(:lookup => :geocoder_ca)
|
135
|
+
set_api_key!(:geocoder_ca)
|
115
136
|
result = Geocoder.search([45.423733, -75.676333]).first
|
116
137
|
assert_equal "CA", result.country_code
|
117
138
|
assert_equal "289 Somerset ST E, Ottawa, ON K1N6W1, Canada", result.address
|
@@ -130,11 +151,56 @@ class ServicesTest < Test::Unit::TestCase
|
|
130
151
|
assert_equal "Plano, TX 75093, United States", result.address
|
131
152
|
end
|
132
153
|
|
154
|
+
# --- MaxMind ---
|
155
|
+
|
156
|
+
def test_maxmind_result_on_ip_address_search
|
157
|
+
Geocoder.configure(:ip_lookup => :maxmind, :maxmind => {:service => :city_isp_org})
|
158
|
+
result = Geocoder.search("74.200.247.59").first
|
159
|
+
assert result.is_a?(Geocoder::Result::Maxmind)
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_maxmind_result_knows_country_service_name
|
163
|
+
Geocoder.configure(:ip_lookup => :maxmind)
|
164
|
+
assert_equal :country, Geocoder.search("24.24.24.21").first.service_name
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_maxmind_result_knows_city_service_name
|
168
|
+
Geocoder.configure(:ip_lookup => :maxmind)
|
169
|
+
assert_equal :city, Geocoder.search("24.24.24.22").first.service_name
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_maxmind_result_knows_city_isp_org_service_name
|
173
|
+
Geocoder.configure(:ip_lookup => :maxmind)
|
174
|
+
assert_equal :city_isp_org, Geocoder.search("24.24.24.23").first.service_name
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_maxmind_result_knows_omni_service_name
|
178
|
+
Geocoder.configure(:ip_lookup => :maxmind)
|
179
|
+
assert_equal :omni, Geocoder.search("24.24.24.24").first.service_name
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_maxmind_special_result_components
|
183
|
+
Geocoder.configure(:ip_lookup => :maxmind)
|
184
|
+
result = Geocoder.search("24.24.24.24").first
|
185
|
+
assert_equal "Road Runner", result.isp_name
|
186
|
+
assert_equal "Cable/DSL", result.netspeed
|
187
|
+
assert_equal "rr.com", result.domain
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_maxmind_raises_exception_when_service_not_configured
|
191
|
+
Geocoder.configure(:ip_lookup => :maxmind)
|
192
|
+
Geocoder.configure(:maxmind => {:service => nil})
|
193
|
+
assert_raises Geocoder::ConfigurationError do
|
194
|
+
Geocoder::Query.new("24.24.24.24").url
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
133
198
|
|
134
199
|
# --- Bing ---
|
135
200
|
|
136
201
|
def test_bing_result_components
|
137
|
-
Geocoder
|
202
|
+
Geocoder.configure(:lookup => :bing)
|
203
|
+
set_api_key!(:bing)
|
138
204
|
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
139
205
|
assert_equal "Madison Square Garden, NY", result.address
|
140
206
|
assert_equal "NY", result.state
|
@@ -142,7 +208,8 @@ class ServicesTest < Test::Unit::TestCase
|
|
142
208
|
end
|
143
209
|
|
144
210
|
def test_bing_no_results
|
145
|
-
Geocoder
|
211
|
+
Geocoder.configure(:lookup => :bing)
|
212
|
+
set_api_key!(:bing)
|
146
213
|
results = Geocoder.search("no results")
|
147
214
|
assert_equal 0, results.length
|
148
215
|
end
|
@@ -150,38 +217,48 @@ class ServicesTest < Test::Unit::TestCase
|
|
150
217
|
# --- Nominatim ---
|
151
218
|
|
152
219
|
def test_nominatim_result_components
|
153
|
-
Geocoder
|
220
|
+
Geocoder.configure(:lookup => :nominatim)
|
221
|
+
set_api_key!(:nominatim)
|
154
222
|
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
155
223
|
assert_equal "10001", result.postal_code
|
156
224
|
end
|
157
225
|
|
158
226
|
def test_nominatim_address_formatting
|
159
|
-
Geocoder
|
227
|
+
Geocoder.configure(:lookup => :nominatim)
|
228
|
+
set_api_key!(:nominatim)
|
160
229
|
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
161
230
|
assert_equal "Madison Square Garden, West 31st Street, Long Island City, New York City, New York, 10001, United States of America",
|
162
231
|
result.address
|
163
232
|
end
|
233
|
+
|
234
|
+
def test_nominatim_host_config
|
235
|
+
Geocoder.configure(:lookup => :nominatim, :nominatim => {:host => "local.com"})
|
236
|
+
lookup = Geocoder::Lookup::Nominatim.new
|
237
|
+
query = Geocoder::Query.new("Bluffton, SC")
|
238
|
+
assert_match %r(http://local\.com), lookup.query_url(query)
|
239
|
+
end
|
240
|
+
|
164
241
|
# --- MapQuest ---
|
165
242
|
|
166
243
|
def test_api_route
|
167
|
-
Geocoder
|
168
|
-
Geocoder::Configuration.api_key = "abc123"
|
169
|
-
|
244
|
+
Geocoder.configure(:lookup => :mapquest, :api_key => "abc123")
|
170
245
|
lookup = Geocoder::Lookup::Mapquest.new
|
171
246
|
query = Geocoder::Query.new("Bluffton, SC")
|
172
|
-
res = lookup.
|
247
|
+
res = lookup.query_url(query)
|
173
248
|
assert_equal "http://www.mapquestapi.com/geocoding/v1/address?key=abc123&location=Bluffton%2C+SC",
|
174
249
|
res
|
175
250
|
end
|
176
251
|
|
177
252
|
def test_mapquest_result_components
|
178
|
-
Geocoder
|
253
|
+
Geocoder.configure(:lookup => :mapquest)
|
254
|
+
set_api_key!(:mapquest)
|
179
255
|
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
180
256
|
assert_equal "10001", result.postal_code
|
181
257
|
end
|
182
258
|
|
183
259
|
def test_mapquest_address_formatting
|
184
|
-
Geocoder
|
260
|
+
Geocoder.configure(:lookup => :mapquest)
|
261
|
+
set_api_key!(:mapquest)
|
185
262
|
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
186
263
|
assert_equal "46 West 31st Street, New York, NY, 10001, US",
|
187
264
|
result.address
|
data/test/test_helper.rb
CHANGED
@@ -73,7 +73,11 @@ require "geocoder/lookups/base"
|
|
73
73
|
module Geocoder
|
74
74
|
module Lookup
|
75
75
|
class Base
|
76
|
-
private
|
76
|
+
private
|
77
|
+
def fixture_exists?(filename)
|
78
|
+
File.exist?(File.join("test", "fixtures", filename))
|
79
|
+
end
|
80
|
+
|
77
81
|
def read_fixture(file)
|
78
82
|
filepath = File.join("test", "fixtures", file)
|
79
83
|
s = File.read(filepath).strip.gsub(/\n\s*/, "")
|
@@ -83,124 +87,56 @@ module Geocoder
|
|
83
87
|
end
|
84
88
|
s
|
85
89
|
end
|
86
|
-
end
|
87
90
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
file = case query.text
|
94
|
-
when "no results"; :no_results
|
95
|
-
when "no locality"; :no_locality
|
96
|
-
when "no city data"; :no_city_data
|
97
|
-
else :madison_square_garden
|
98
|
-
end
|
99
|
-
read_fixture "google_#{file}.json"
|
91
|
+
##
|
92
|
+
# Fixture to use if none match the given query.
|
93
|
+
#
|
94
|
+
def default_fixture_filename
|
95
|
+
"#{fixture_prefix}_madison_square_garden"
|
100
96
|
end
|
101
|
-
end
|
102
|
-
|
103
|
-
class GooglePremier < Google
|
104
|
-
end
|
105
97
|
|
106
|
-
|
107
|
-
|
108
|
-
def make_api_request(query)
|
109
|
-
raise TimeoutError if query.text == "timeout"
|
110
|
-
raise SocketError if query.text == "socket_error"
|
111
|
-
file = case query.text
|
112
|
-
when "no results"; :no_results
|
113
|
-
when "error"; :error
|
114
|
-
else :madison_square_garden
|
115
|
-
end
|
116
|
-
read_fixture "yahoo_#{file}.json"
|
98
|
+
def fixture_prefix
|
99
|
+
handle
|
117
100
|
end
|
118
|
-
end
|
119
101
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
raise SocketError if query.text == "socket_error"
|
125
|
-
file = case query.text
|
126
|
-
when "no results"; :no_results
|
127
|
-
when "invalid key"; :invalid_key
|
128
|
-
else :kremlin
|
129
|
-
end
|
130
|
-
read_fixture "yandex_#{file}.json"
|
102
|
+
def fixture_for_query(query)
|
103
|
+
label = query.reverse_geocode? ? "reverse" : query.text.gsub(/[ \.]/, "_")
|
104
|
+
filename = "#{fixture_prefix}_#{label}"
|
105
|
+
fixture_exists?(filename) ? filename : default_fixture_filename
|
131
106
|
end
|
132
|
-
end
|
133
107
|
|
134
|
-
class GeocoderCa < Base
|
135
|
-
private #-----------------------------------------------------------------
|
136
108
|
def make_api_request(query)
|
137
109
|
raise TimeoutError if query.text == "timeout"
|
138
110
|
raise SocketError if query.text == "socket_error"
|
139
|
-
|
140
|
-
read_fixture "geocoder_ca_reverse.json"
|
141
|
-
else
|
142
|
-
file = case query.text
|
143
|
-
when "no results"; :no_results
|
144
|
-
else :madison_square_garden
|
145
|
-
end
|
146
|
-
read_fixture "geocoder_ca_#{file}.json"
|
147
|
-
end
|
111
|
+
read_fixture fixture_for_query(query)
|
148
112
|
end
|
149
113
|
end
|
150
114
|
|
151
|
-
class
|
152
|
-
private
|
153
|
-
def
|
154
|
-
|
155
|
-
raise SocketError if query.text == "socket_error"
|
156
|
-
file = case query.text
|
157
|
-
when "no results"; :no_results
|
158
|
-
else "74_200_247_59"
|
159
|
-
end
|
160
|
-
read_fixture "freegeoip_#{file}.json"
|
115
|
+
class GooglePremier
|
116
|
+
private
|
117
|
+
def fixture_prefix
|
118
|
+
"google"
|
161
119
|
end
|
162
120
|
end
|
163
121
|
|
164
|
-
class
|
165
|
-
private
|
166
|
-
def
|
167
|
-
|
168
|
-
raise SocketError if query.text == "socket_error"
|
169
|
-
if query.reverse_geocode?
|
170
|
-
read_fixture "bing_reverse.json"
|
171
|
-
else
|
172
|
-
file = case query.text
|
173
|
-
when "no results"; :no_results
|
174
|
-
else :madison_square_garden
|
175
|
-
end
|
176
|
-
read_fixture "bing_#{file}.json"
|
177
|
-
end
|
122
|
+
class Yandex
|
123
|
+
private
|
124
|
+
def default_fixture_filename
|
125
|
+
"yandex_kremlin"
|
178
126
|
end
|
179
127
|
end
|
180
128
|
|
181
|
-
class
|
182
|
-
private
|
183
|
-
def
|
184
|
-
|
185
|
-
raise SocketError if query.text == "socket_error"
|
186
|
-
file = case query.text
|
187
|
-
when "no results"; :no_results
|
188
|
-
else :madison_square_garden
|
189
|
-
end
|
190
|
-
read_fixture "nominatim_#{file}.json"
|
129
|
+
class Freegeoip
|
130
|
+
private
|
131
|
+
def default_fixture_filename
|
132
|
+
"freegeoip_74_200_247_59"
|
191
133
|
end
|
192
134
|
end
|
193
135
|
|
194
|
-
class
|
195
|
-
private
|
196
|
-
def
|
197
|
-
|
198
|
-
raise SocketError if query.text == "socket_error"
|
199
|
-
file = case query.text
|
200
|
-
when "no results"; :no_results
|
201
|
-
else :madison_square_garden
|
202
|
-
end
|
203
|
-
read_fixture "mapquest_#{file}.json"
|
136
|
+
class Maxmind
|
137
|
+
private
|
138
|
+
def default_fixture_filename
|
139
|
+
"maxmind_74_200_247_59"
|
204
140
|
end
|
205
141
|
end
|
206
142
|
|
@@ -302,6 +238,10 @@ end
|
|
302
238
|
|
303
239
|
class Test::Unit::TestCase
|
304
240
|
|
241
|
+
def setup
|
242
|
+
Geocoder.configure(:maxmind => {:service => :omni})
|
243
|
+
end
|
244
|
+
|
305
245
|
def teardown
|
306
246
|
Geocoder.send(:remove_const, :Configuration)
|
307
247
|
load "geocoder/configuration.rb"
|
@@ -326,19 +266,14 @@ class Test::Unit::TestCase
|
|
326
266
|
end
|
327
267
|
|
328
268
|
def set_api_key!(lookup_name)
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
]
|
335
|
-
elsif lookup_name == :yahoo
|
336
|
-
Geocoder::Configuration.api_key = [
|
337
|
-
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
|
338
|
-
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
|
339
|
-
]
|
269
|
+
lookup = Geocoder::Lookup.get(lookup_name)
|
270
|
+
if lookup.required_api_key_parts.size == 1
|
271
|
+
key = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
|
272
|
+
elsif lookup.required_api_key_parts.size > 1
|
273
|
+
key = lookup.required_api_key_parts
|
340
274
|
else
|
341
|
-
|
275
|
+
key = nil
|
342
276
|
end
|
277
|
+
Geocoder.configure(:api_key => key)
|
343
278
|
end
|
344
279
|
end
|