geocoder-sgonyea 1.1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.travis.yml +23 -0
- data/CHANGELOG.md +298 -0
- data/LICENSE +20 -0
- data/README.md +656 -0
- data/Rakefile +25 -0
- data/bin/geocode +5 -0
- data/examples/autoexpire_cache.rb +28 -0
- data/gemfiles/Gemfile.mongoid-2.4.x +15 -0
- data/lib/generators/geocoder/config/config_generator.rb +14 -0
- data/lib/generators/geocoder/config/templates/initializer.rb +21 -0
- data/lib/geocoder.rb +55 -0
- data/lib/geocoder/cache.rb +85 -0
- data/lib/geocoder/calculations.rb +319 -0
- data/lib/geocoder/cli.rb +114 -0
- data/lib/geocoder/configuration.rb +130 -0
- data/lib/geocoder/configuration_hash.rb +11 -0
- data/lib/geocoder/exceptions.rb +21 -0
- data/lib/geocoder/lookup.rb +82 -0
- data/lib/geocoder/lookups/base.rb +250 -0
- data/lib/geocoder/lookups/bing.rb +47 -0
- data/lib/geocoder/lookups/freegeoip.rb +47 -0
- data/lib/geocoder/lookups/geocoder_ca.rb +54 -0
- data/lib/geocoder/lookups/google.rb +62 -0
- data/lib/geocoder/lookups/google_premier.rb +47 -0
- data/lib/geocoder/lookups/mapquest.rb +43 -0
- data/lib/geocoder/lookups/maxmind.rb +88 -0
- data/lib/geocoder/lookups/nominatim.rb +45 -0
- data/lib/geocoder/lookups/ovi.rb +52 -0
- data/lib/geocoder/lookups/test.rb +38 -0
- data/lib/geocoder/lookups/yahoo.rb +84 -0
- data/lib/geocoder/lookups/yandex.rb +54 -0
- data/lib/geocoder/models/active_record.rb +46 -0
- data/lib/geocoder/models/base.rb +42 -0
- data/lib/geocoder/models/mongo_base.rb +60 -0
- data/lib/geocoder/models/mongo_mapper.rb +26 -0
- data/lib/geocoder/models/mongoid.rb +32 -0
- data/lib/geocoder/query.rb +103 -0
- data/lib/geocoder/railtie.rb +26 -0
- data/lib/geocoder/request.rb +23 -0
- data/lib/geocoder/results/base.rb +67 -0
- data/lib/geocoder/results/bing.rb +48 -0
- data/lib/geocoder/results/freegeoip.rb +45 -0
- data/lib/geocoder/results/geocoder_ca.rb +60 -0
- data/lib/geocoder/results/google.rb +106 -0
- data/lib/geocoder/results/google_premier.rb +6 -0
- data/lib/geocoder/results/mapquest.rb +51 -0
- data/lib/geocoder/results/maxmind.rb +136 -0
- data/lib/geocoder/results/nominatim.rb +94 -0
- data/lib/geocoder/results/ovi.rb +62 -0
- data/lib/geocoder/results/test.rb +16 -0
- data/lib/geocoder/results/yahoo.rb +55 -0
- data/lib/geocoder/results/yandex.rb +80 -0
- data/lib/geocoder/sql.rb +106 -0
- data/lib/geocoder/stores/active_record.rb +259 -0
- data/lib/geocoder/stores/base.rb +120 -0
- data/lib/geocoder/stores/mongo_base.rb +85 -0
- data/lib/geocoder/stores/mongo_mapper.rb +13 -0
- data/lib/geocoder/stores/mongoid.rb +13 -0
- data/lib/geocoder/version.rb +3 -0
- data/lib/hash_recursive_merge.rb +74 -0
- data/lib/oauth_util.rb +112 -0
- data/lib/tasks/geocoder.rake +25 -0
- data/test/active_record_test.rb +15 -0
- data/test/cache_test.rb +19 -0
- data/test/calculations_test.rb +195 -0
- data/test/configuration_test.rb +78 -0
- data/test/custom_block_test.rb +32 -0
- data/test/error_handling_test.rb +43 -0
- data/test/fixtures/bing_invalid_key +1 -0
- data/test/fixtures/bing_madison_square_garden +40 -0
- data/test/fixtures/bing_no_results +16 -0
- data/test/fixtures/bing_reverse +42 -0
- data/test/fixtures/freegeoip_74_200_247_59 +12 -0
- data/test/fixtures/freegeoip_no_results +1 -0
- data/test/fixtures/geocoder_ca_madison_square_garden +1 -0
- data/test/fixtures/geocoder_ca_no_results +1 -0
- data/test/fixtures/geocoder_ca_reverse +34 -0
- data/test/fixtures/google_garbage +456 -0
- data/test/fixtures/google_madison_square_garden +57 -0
- data/test/fixtures/google_no_city_data +44 -0
- data/test/fixtures/google_no_locality +51 -0
- data/test/fixtures/google_no_results +4 -0
- data/test/fixtures/mapquest_madison_square_garden +52 -0
- data/test/fixtures/mapquest_no_results +7 -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 +150 -0
- data/test/fixtures/nominatim_no_results +1 -0
- data/test/fixtures/ovi_madison_square_garden +72 -0
- data/test/fixtures/ovi_no_results +8 -0
- data/test/fixtures/yahoo_error +1 -0
- data/test/fixtures/yahoo_invalid_key +2 -0
- data/test/fixtures/yahoo_madison_square_garden +52 -0
- data/test/fixtures/yahoo_no_results +10 -0
- data/test/fixtures/yahoo_over_limit +2 -0
- data/test/fixtures/yandex_invalid_key +1 -0
- data/test/fixtures/yandex_kremlin +48 -0
- data/test/fixtures/yandex_no_city_and_town +112 -0
- data/test/fixtures/yandex_no_results +16 -0
- data/test/geocoder_test.rb +59 -0
- data/test/https_test.rb +16 -0
- data/test/integration/smoke_test.rb +26 -0
- data/test/lookup_test.rb +116 -0
- data/test/method_aliases_test.rb +25 -0
- data/test/mongoid_test.rb +39 -0
- data/test/mongoid_test_helper.rb +43 -0
- data/test/near_test.rb +43 -0
- data/test/oauth_util_test.rb +30 -0
- data/test/proxy_test.rb +23 -0
- data/test/query_test.rb +51 -0
- data/test/request_test.rb +29 -0
- data/test/result_test.rb +42 -0
- data/test/services_test.rb +277 -0
- data/test/test_helper.rb +279 -0
- data/test/test_mode_test.rb +50 -0
- metadata +170 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"bossresponse":{"responsecode":"6000","reason":"internal error"}}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
{
|
2
|
+
"bossresponse": {
|
3
|
+
"responsecode": "200",
|
4
|
+
"placefinder": {
|
5
|
+
"start": "0",
|
6
|
+
"count": "1",
|
7
|
+
"request": "flags=JXTSR&location=Madison%20Square%20Garden%2C%20NY%2C%20NY&%unsafe%appid=%5B%22dj0yJmk9ZmZ5NXFrNGhNcEthJmQ9WVdrOVFUSlhPV2x1TjJVbWNHbzlORE0wT0RFME9UWXkmcz1jb25zdW1lcnNlY3JldCZ4PTAy%22%2C%20%22b57b1b98eb21f171231f5b441cba505261d6c9bb%22%5D&gflags=AC&locale=en_US",
|
8
|
+
"results": [
|
9
|
+
{
|
10
|
+
"quality": "90",
|
11
|
+
"latitude": "40.750381",
|
12
|
+
"longitude": "-73.993988",
|
13
|
+
"offsetlat": "40.750381",
|
14
|
+
"offsetlon": "-73.993988",
|
15
|
+
"radius": "400",
|
16
|
+
"boundingbox": {
|
17
|
+
"north": "40.750832",
|
18
|
+
"south": "40.749931",
|
19
|
+
"east": "-73.993393",
|
20
|
+
"west": "-73.994591"
|
21
|
+
},
|
22
|
+
"name": "Madison Square Garden",
|
23
|
+
"line1": "Madison Square Garden",
|
24
|
+
"line2": "New York, NY 10001",
|
25
|
+
"line3": "",
|
26
|
+
"line4": "United States",
|
27
|
+
"cross": "",
|
28
|
+
"house": "",
|
29
|
+
"street": "",
|
30
|
+
"xstreet": "",
|
31
|
+
"unittype": "",
|
32
|
+
"unit": "",
|
33
|
+
"postal": "10001",
|
34
|
+
"neighborhood": "Garment District|Midtown|Midtown West|Manhattan",
|
35
|
+
"city": "New York",
|
36
|
+
"county": "New York County",
|
37
|
+
"state": "New York",
|
38
|
+
"country": "United States",
|
39
|
+
"countrycode": "US",
|
40
|
+
"statecode": "NY",
|
41
|
+
"countycode": "",
|
42
|
+
"timezone": "America/New_York",
|
43
|
+
"areacode": "212",
|
44
|
+
"uzip": "10001",
|
45
|
+
"hash": "",
|
46
|
+
"woeid": "23617041",
|
47
|
+
"woetype": "20"
|
48
|
+
}
|
49
|
+
]
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
{
|
2
|
+
"bossresponse": {
|
3
|
+
"responsecode": "200",
|
4
|
+
"placefinder": {
|
5
|
+
"start": "0",
|
6
|
+
"count": "0",
|
7
|
+
"request": "flags=JXTSR&location=asdfasdf28394782sdfj2983&%unsafe%appid=%5B%22dj0yJmk9ZmZ5NXFrNGhNcEthJmQ9WVdrOVFUSlhPV2x1TjJVbWNHbzlORE0wT0RFME9UWXkmcz1jb25zdW1lcnNlY3JldCZ4PTAy%22%2C%20%22b57b1b98eb21f171231f5b441cba505261d6c9bb%22%5D&gflags=AC&locale=en_US"
|
8
|
+
}
|
9
|
+
}
|
10
|
+
}
|
@@ -0,0 +1,2 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?> <yahoo:error xmlns:yahoo="http://yahooapis.com/v1/base.rng\ <http://yahooapis.com/v1/base.rng%5C>" xml:lang="en-US">
|
2
|
+
<yahoo:description>Rate Limit Exceeded</yahoo:description> <yahoo:detail>Key has exceeded its configured rate limit.</yahoo:detail> </yahoo:error>
|
@@ -0,0 +1 @@
|
|
1
|
+
{"error":{"status":401,"message":"invalid key"}}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
{
|
2
|
+
"response": {
|
3
|
+
"GeoObjectCollection": {
|
4
|
+
"metaDataProperty": {
|
5
|
+
"GeocoderResponseMetaData": {
|
6
|
+
"request": "Кремль, Moscow, Russia",
|
7
|
+
"found": "1",
|
8
|
+
"results": "10"
|
9
|
+
}
|
10
|
+
},
|
11
|
+
"featureMember": [
|
12
|
+
{
|
13
|
+
"GeoObject": {
|
14
|
+
"metaDataProperty": {
|
15
|
+
"GeocoderMetaData": {
|
16
|
+
"kind": "vegetation",
|
17
|
+
"text": "Россия, Москва, Московский Кремль",
|
18
|
+
"precision": "other",
|
19
|
+
"AddressDetails": {
|
20
|
+
"Country": {
|
21
|
+
"CountryNameCode": "RU",
|
22
|
+
"CountryName": "Россия",
|
23
|
+
"Locality": {
|
24
|
+
"LocalityName": "Москва",
|
25
|
+
"Premise": {
|
26
|
+
"PremiseName": "Московский Кремль"
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
},
|
33
|
+
"name": "Московский Кремль",
|
34
|
+
"boundedBy": {
|
35
|
+
"Envelope": {
|
36
|
+
"lowerCorner": "37.584182 55.733361",
|
37
|
+
"upperCorner": "37.650064 55.770517"
|
38
|
+
}
|
39
|
+
},
|
40
|
+
"Point": {
|
41
|
+
"pos": "37.617123 55.751943"
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
]
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
@@ -0,0 +1,112 @@
|
|
1
|
+
{
|
2
|
+
"response":{
|
3
|
+
"GeoObjectCollection":{
|
4
|
+
"metaDataProperty":{
|
5
|
+
"GeocoderResponseMetaData":{
|
6
|
+
"request":"57.423359,55.892596",
|
7
|
+
"found":"3",
|
8
|
+
"results":"10",
|
9
|
+
"Point":{
|
10
|
+
"pos":"57.423359 55.892596"
|
11
|
+
}
|
12
|
+
}
|
13
|
+
},
|
14
|
+
"featureMember":[
|
15
|
+
{
|
16
|
+
"GeoObject":{
|
17
|
+
"metaDataProperty":{
|
18
|
+
"GeocoderMetaData":{
|
19
|
+
"kind":"area",
|
20
|
+
"text":"Россия, республика Башкортостан, Караидельский район",
|
21
|
+
"precision":"other",
|
22
|
+
"AddressDetails":{
|
23
|
+
"Country":{
|
24
|
+
"AddressLine":"республика Башкортостан, Караидельский район",
|
25
|
+
"CountryNameCode":"RU",
|
26
|
+
"CountryName":"Россия",
|
27
|
+
"AdministrativeArea":{
|
28
|
+
"AdministrativeAreaName":"республика Башкортостан",
|
29
|
+
"SubAdministrativeArea":{
|
30
|
+
"SubAdministrativeAreaName":"Караидельский район"
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
},
|
37
|
+
"description":"республика Башкортостан, Россия",
|
38
|
+
"name":"Караидельский район",
|
39
|
+
"boundedBy":{
|
40
|
+
"Envelope":{
|
41
|
+
"lowerCorner":"56.231384 55.462814",
|
42
|
+
"upperCorner":"57.705348 56.076117"
|
43
|
+
}
|
44
|
+
},
|
45
|
+
"Point":{
|
46
|
+
"pos":"57.423359 55.892596"
|
47
|
+
}
|
48
|
+
}
|
49
|
+
},
|
50
|
+
{
|
51
|
+
"GeoObject":{
|
52
|
+
"metaDataProperty":{
|
53
|
+
"GeocoderMetaData":{
|
54
|
+
"kind":"province",
|
55
|
+
"text":"Россия, республика Башкортостан",
|
56
|
+
"precision":"other",
|
57
|
+
"AddressDetails":{
|
58
|
+
"Country":{
|
59
|
+
"AddressLine":"республика Башкортостан",
|
60
|
+
"CountryNameCode":"RU",
|
61
|
+
"CountryName":"Россия",
|
62
|
+
"AdministrativeArea":{
|
63
|
+
"AdministrativeAreaName":"республика Башкортостан"
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}
|
68
|
+
},
|
69
|
+
"description":"Россия",
|
70
|
+
"name":"республика Башкортостан",
|
71
|
+
"boundedBy":{
|
72
|
+
"Envelope":{
|
73
|
+
"lowerCorner":"53.157475 51.571991",
|
74
|
+
"upperCorner":"60.001577 56.533651"
|
75
|
+
}
|
76
|
+
},
|
77
|
+
"Point":{
|
78
|
+
"pos":"56.579526 54.127354"
|
79
|
+
}
|
80
|
+
}
|
81
|
+
},
|
82
|
+
{
|
83
|
+
"GeoObject":{
|
84
|
+
"metaDataProperty":{
|
85
|
+
"GeocoderMetaData":{
|
86
|
+
"kind":"country",
|
87
|
+
"text":"Россия",
|
88
|
+
"precision":"other",
|
89
|
+
"AddressDetails":{
|
90
|
+
"Country":{
|
91
|
+
"CountryNameCode":"RU",
|
92
|
+
"CountryName":"Россия"
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
},
|
97
|
+
"name":"Россия",
|
98
|
+
"boundedBy":{
|
99
|
+
"Envelope":{
|
100
|
+
"lowerCorner":"19.641673 36.84312",
|
101
|
+
"upperCorner":"179.999997 81.848739"
|
102
|
+
}
|
103
|
+
},
|
104
|
+
"Point":{
|
105
|
+
"pos":"37.617761 55.755773"
|
106
|
+
}
|
107
|
+
}
|
108
|
+
}
|
109
|
+
]
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class GeocoderTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_distance_to_returns_float
|
7
|
+
v = Venue.new(*venue_params(:msg))
|
8
|
+
v.latitude, v.longitude = [40.750354, -73.993371]
|
9
|
+
assert (d = v.distance_to([30, -94])).is_a?(Float)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_coordinates_method_returns_array
|
13
|
+
assert Geocoder.coordinates("Madison Square Garden, New York, NY").is_a?(Array)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_address_method_returns_string
|
17
|
+
assert Geocoder.address([40.750354, -73.993371]).is_a?(String)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_geographic_center_doesnt_overwrite_argument_value
|
21
|
+
# test for the presence of a bug that was introduced in version 0.9.11
|
22
|
+
orig_points = [[52,8], [46,9], [42,5]]
|
23
|
+
points = orig_points.clone
|
24
|
+
Geocoder::Calculations.geographic_center(points)
|
25
|
+
assert_equal orig_points, points
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_geocode_assigns_and_returns_coordinates
|
29
|
+
v = Venue.new(*venue_params(:msg))
|
30
|
+
coords = [40.750354, -73.993371]
|
31
|
+
assert_equal coords, v.geocode
|
32
|
+
assert_equal coords, [v.latitude, v.longitude]
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_geocode_block_executed_when_no_results
|
36
|
+
v = Event.new("Nowhere", "no results")
|
37
|
+
v.geocode
|
38
|
+
assert_equal "NOT FOUND", v.coords_string
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_reverse_geocode_assigns_and_returns_address
|
42
|
+
v = Landmark.new(*landmark_params(:msg))
|
43
|
+
address = "4 Penn Plaza, New York, NY 10001, USA"
|
44
|
+
assert_equal address, v.reverse_geocode
|
45
|
+
assert_equal address, v.address
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_forward_and_reverse_geocoding_on_same_model_works
|
49
|
+
g = GasStation.new("Exxon")
|
50
|
+
g.address = "404 New St, Middletown, CT"
|
51
|
+
g.geocode
|
52
|
+
assert_not_nil g.lat
|
53
|
+
assert_not_nil g.lon
|
54
|
+
|
55
|
+
assert_nil g.location
|
56
|
+
g.reverse_geocode
|
57
|
+
assert_not_nil g.location
|
58
|
+
end
|
59
|
+
end
|
data/test/https_test.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class HttpsTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_uses_https_for_secure_query
|
7
|
+
Geocoder.configure(:use_https => true)
|
8
|
+
g = Geocoder::Lookup::Google.new
|
9
|
+
assert_match /^https:/, g.query_url(Geocoder::Query.new("test"))
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_uses_http_by_default
|
13
|
+
g = Geocoder::Lookup::Google.new
|
14
|
+
assert_match /^http:/, g.query_url(Geocoder::Query.new("test"))
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), *%w[ .. .. lib]))
|
2
|
+
require 'pathname'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'geocoder'
|
6
|
+
|
7
|
+
class SmokeTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def test_simple_zip_code_search
|
10
|
+
result = Geocoder.search "27701"
|
11
|
+
assert_not_nil (r = result.first)
|
12
|
+
assert_equal "Durham", r.city
|
13
|
+
assert_equal "North Carolina", r.state
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_simple_zip_code_search_with_ssl
|
17
|
+
Geocoder.configure(:use_https => true)
|
18
|
+
result = Geocoder.search "27701"
|
19
|
+
assert_not_nil (r = result.first)
|
20
|
+
assert_equal "Durham", r.city
|
21
|
+
assert_equal "North Carolina", r.state
|
22
|
+
ensure
|
23
|
+
Geocoder.configure(:use_https => false)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/test/lookup_test.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class LookupTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_responds_to_name_method
|
7
|
+
Geocoder::Lookup.all_services.each do |l|
|
8
|
+
lookup = Geocoder::Lookup.get(l)
|
9
|
+
assert lookup.respond_to?(:name),
|
10
|
+
"Lookup #{l} does not respond to #name method."
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_search_returns_empty_array_when_no_results
|
15
|
+
Geocoder::Lookup.all_services_except_test.each do |l|
|
16
|
+
lookup = Geocoder::Lookup.get(l)
|
17
|
+
set_api_key!(l)
|
18
|
+
assert_equal [], lookup.send(:results, Geocoder::Query.new("no results")),
|
19
|
+
"Lookup #{l} does not return empty array when no results."
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_query_url_contains_values_in_params_hash
|
24
|
+
Geocoder::Lookup.all_services_except_test.each do |l|
|
25
|
+
next if l == :freegeoip # does not use query string
|
26
|
+
set_api_key!(l)
|
27
|
+
url = Geocoder::Lookup.get(l).query_url(Geocoder::Query.new(
|
28
|
+
"test", :params => {:one_in_the_hand => "two in the bush"}
|
29
|
+
))
|
30
|
+
# should be "+"s for all lookups except Yahoo
|
31
|
+
assert_match /one_in_the_hand=two(%20|\+)in(%20|\+)the(%20|\+)bush/, url,
|
32
|
+
"Lookup #{l} does not appear to support arbitrary params in URL"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
{
|
37
|
+
:bing => :key,
|
38
|
+
:geocoder_ca => :auth,
|
39
|
+
:google => :language,
|
40
|
+
:google_premier => :language,
|
41
|
+
:mapquest => :key,
|
42
|
+
:maxmind => :l,
|
43
|
+
:nominatim => :"accept-language",
|
44
|
+
:yahoo => :locale,
|
45
|
+
:yandex => :plng
|
46
|
+
}.each do |l,p|
|
47
|
+
define_method "test_passing_param_to_#{l}_query_overrides_configuration_value" do
|
48
|
+
set_api_key!(l)
|
49
|
+
url = Geocoder::Lookup.get(l).query_url(Geocoder::Query.new(
|
50
|
+
"test", :params => {p => "xxxx"}
|
51
|
+
))
|
52
|
+
assert_match /#{p}=xxxx/, url,
|
53
|
+
"Param passed to #{l} lookup does not override configuration value"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_raises_exception_on_invalid_key
|
58
|
+
Geocoder.configure(:always_raise => [Geocoder::InvalidApiKey])
|
59
|
+
#Geocoder::Lookup.all_services_except_test.each do |l|
|
60
|
+
[:bing, :yahoo, :yandex, :maxmind].each do |l|
|
61
|
+
lookup = Geocoder::Lookup.get(l)
|
62
|
+
assert_raises Geocoder::InvalidApiKey do
|
63
|
+
lookup.send(:results, Geocoder::Query.new("invalid key"))
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_returns_empty_array_on_invalid_key
|
69
|
+
# keep test output clean: suppress timeout warning
|
70
|
+
orig = $VERBOSE; $VERBOSE = nil
|
71
|
+
#Geocoder::Lookup.all_services_except_test.each do |l|
|
72
|
+
[:bing, :yahoo, :yandex, :maxmind].each do |l|
|
73
|
+
Geocoder.configure(:lookup => l)
|
74
|
+
set_api_key!(l)
|
75
|
+
assert_equal [], Geocoder.search("invalid key")
|
76
|
+
end
|
77
|
+
ensure
|
78
|
+
$VERBOSE = orig
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_does_not_choke_on_nil_address
|
82
|
+
Geocoder::Lookup.all_services.each do |l|
|
83
|
+
Geocoder.configure(:lookup => l)
|
84
|
+
assert_nothing_raised { Venue.new("Venue", nil).geocode }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_hash_to_query
|
89
|
+
g = Geocoder::Lookup::Google.new
|
90
|
+
assert_equal "a=1&b=2", g.send(:hash_to_query, {:a => 1, :b => 2})
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_google_api_key
|
94
|
+
Geocoder.configure(:api_key => "MY_KEY")
|
95
|
+
g = Geocoder::Lookup::Google.new
|
96
|
+
assert_match "key=MY_KEY", g.query_url(Geocoder::Query.new("Madison Square Garden, New York, NY 10001, United States"))
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_geocoder_ca_showpostal
|
100
|
+
Geocoder.configure(:api_key => "MY_KEY")
|
101
|
+
g = Geocoder::Lookup::GeocoderCa.new
|
102
|
+
assert_match "showpostal=1", g.query_url(Geocoder::Query.new("Madison Square Garden, New York, NY 10001, United States"))
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_raises_configuration_error_on_missing_key
|
106
|
+
assert_raises Geocoder::ConfigurationError do
|
107
|
+
Geocoder.configure(:lookup => :bing, :api_key => nil)
|
108
|
+
Geocoder.search("Madison Square Garden, New York, NY 10001, United States")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_handle
|
113
|
+
assert_equal :google, Geocoder::Lookup::Google.new.handle
|
114
|
+
assert_equal :geocoder_ca, Geocoder::Lookup::GeocoderCa.new.handle
|
115
|
+
end
|
116
|
+
end
|