geocoder 1.1.9 → 1.2.0
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +9 -5
- data/CHANGELOG.md +19 -0
- data/README.md +175 -10
- data/Rakefile +1 -1
- data/gemfiles/Gemfile.mongoid-2.4.x +1 -0
- data/lib/generators/geocoder/maxmind/geolite_city_generator.rb +28 -0
- data/lib/generators/geocoder/maxmind/geolite_country_generator.rb +28 -0
- data/lib/generators/geocoder/maxmind/templates/migration/geolite_city.rb +27 -0
- data/lib/generators/geocoder/maxmind/templates/migration/geolite_country.rb +17 -0
- data/lib/geocoder.rb +4 -12
- data/lib/geocoder/cache.rb +3 -2
- data/lib/geocoder/calculations.rb +39 -0
- data/lib/geocoder/configuration.rb +1 -7
- data/lib/geocoder/ip_address.rb +12 -0
- data/lib/geocoder/lookup.rb +10 -1
- data/lib/geocoder/lookups/baidu.rb +7 -6
- data/lib/geocoder/lookups/baidu_ip.rb +54 -0
- data/lib/geocoder/lookups/base.rb +37 -9
- data/lib/geocoder/lookups/bing.rb +10 -5
- data/lib/geocoder/lookups/cloudmade.rb +35 -0
- data/lib/geocoder/lookups/freegeoip.rb +5 -1
- data/lib/geocoder/lookups/geocodio.rb +42 -0
- data/lib/geocoder/lookups/google_premier.rb +1 -1
- data/lib/geocoder/lookups/here.rb +62 -0
- data/lib/geocoder/lookups/mapquest.rb +2 -1
- data/lib/geocoder/lookups/maxmind_local.rb +58 -0
- data/lib/geocoder/lookups/nominatim.rb +8 -0
- data/lib/geocoder/lookups/smarty_streets.rb +45 -0
- data/lib/geocoder/lookups/yahoo.rb +1 -1
- data/lib/geocoder/models/active_record.rb +5 -3
- data/lib/geocoder/models/base.rb +1 -4
- data/lib/geocoder/models/mongo_base.rb +4 -2
- data/lib/geocoder/query.rb +4 -4
- data/lib/geocoder/railtie.rb +1 -1
- data/lib/geocoder/request.rb +10 -8
- data/lib/geocoder/results/baidu_ip.rb +62 -0
- data/lib/geocoder/results/cloudmade.rb +39 -0
- data/lib/geocoder/results/geocodio.rb +66 -0
- data/lib/geocoder/results/here.rb +62 -0
- data/lib/geocoder/results/maxmind_local.rb +49 -0
- data/lib/geocoder/results/smarty_streets.rb +106 -0
- data/lib/geocoder/results/test.rb +20 -3
- data/lib/geocoder/results/yandex.rb +7 -3
- data/lib/geocoder/sql.rb +16 -15
- data/lib/geocoder/stores/active_record.rb +6 -2
- data/lib/geocoder/stores/base.rb +8 -1
- data/lib/geocoder/version.rb +1 -1
- data/lib/maxmind_database.rb +109 -0
- data/lib/oauth_util.rb +1 -1
- data/lib/tasks/geocoder.rake +3 -1
- data/lib/tasks/maxmind.rake +73 -0
- data/test/fixtures/baidu_ip_202_198_16_3 +19 -0
- data/test/fixtures/baidu_ip_invalid_key +1 -0
- data/test/fixtures/baidu_ip_no_results +1 -0
- data/test/fixtures/cloudmade_invalid_key +1 -0
- data/test/fixtures/cloudmade_madison_square_garden +1 -0
- data/test/fixtures/cloudmade_no_results +1 -0
- data/test/fixtures/geocodio_1101_pennsylvania_ave +1 -0
- data/test/fixtures/geocodio_bad_api_key +3 -0
- data/test/fixtures/geocodio_invalid +4 -0
- data/test/fixtures/geocodio_no_results +1 -0
- data/test/fixtures/geocodio_over_query_limit +4 -0
- data/test/fixtures/here_madison_square_garden +72 -0
- data/test/fixtures/here_no_results +8 -0
- data/test/fixtures/nominatim_over_limit +1 -0
- data/test/fixtures/smarty_streets_11211 +1 -0
- data/test/fixtures/smarty_streets_madison_square_garden +47 -0
- data/test/fixtures/smarty_streets_no_results +1 -0
- data/test/fixtures/yandex_canada_rue_dupuis_14 +446 -0
- data/test/fixtures/yandex_new_york +1 -0
- data/test/integration/http_client_test.rb +25 -0
- data/test/mongoid_test_helper.rb +2 -2
- data/test/test_helper.rb +98 -30
- data/test/{active_record_test.rb → unit/active_record_test.rb} +4 -3
- data/test/{cache_test.rb → unit/cache_test.rb} +3 -1
- data/test/{calculations_test.rb → unit/calculations_test.rb} +22 -13
- data/test/{configuration_test.rb → unit/configuration_test.rb} +4 -27
- data/test/{error_handling_test.rb → unit/error_handling_test.rb} +10 -9
- data/test/{geocoder_test.rb → unit/geocoder_test.rb} +26 -7
- data/test/{https_test.rb → unit/https_test.rb} +4 -3
- data/test/unit/ip_address_test.rb +24 -0
- data/test/{lookup_test.rb → unit/lookup_test.rb} +33 -20
- data/test/unit/lookups/bing_test.rb +68 -0
- data/test/unit/lookups/dstk_test.rb +26 -0
- data/test/unit/lookups/esri_test.rb +48 -0
- data/test/unit/lookups/freegeoip_test.rb +27 -0
- data/test/unit/lookups/geocoder_ca_test.rb +17 -0
- data/test/unit/lookups/geocodio_test.rb +55 -0
- data/test/unit/lookups/google_premier_test.rb +22 -0
- data/test/unit/lookups/google_test.rb +84 -0
- data/test/unit/lookups/mapquest_test.rb +60 -0
- data/test/unit/lookups/maxmind_local_test.rb +28 -0
- data/test/unit/lookups/maxmind_test.rb +63 -0
- data/test/unit/lookups/nominatim_test.rb +31 -0
- data/test/unit/lookups/smarty_streets_test.rb +71 -0
- data/test/unit/lookups/yahoo_test.rb +35 -0
- data/test/{method_aliases_test.rb → unit/method_aliases_test.rb} +5 -4
- data/test/unit/model_test.rb +38 -0
- data/test/{mongoid_test.rb → unit/mongoid_test.rb} +10 -9
- data/test/unit/near_test.rb +87 -0
- data/test/{oauth_util_test.rb → unit/oauth_util_test.rb} +3 -2
- data/test/{proxy_test.rb → unit/proxy_test.rb} +2 -1
- data/test/{query_test.rb → unit/query_test.rb} +7 -8
- data/test/unit/rake_task_test.rb +21 -0
- data/test/{request_test.rb → unit/request_test.rb} +8 -2
- data/test/{result_test.rb → unit/result_test.rb} +29 -1
- data/test/{test_mode_test.rb → unit/test_mode_test.rb} +12 -1
- metadata +80 -27
- data/test/custom_block_test.rb +0 -32
- data/test/integration/smoke_test.rb +0 -26
- data/test/near_test.rb +0 -61
- data/test/services_test.rb +0 -393
data/test/custom_block_test.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'test_helper'
|
3
|
-
|
4
|
-
class CustomBlockTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def test_geocode_with_block_runs_block
|
7
|
-
e = Event.new(*venue_params(:msg))
|
8
|
-
coords = [40.750354, -73.993371]
|
9
|
-
e.geocode
|
10
|
-
assert_equal coords.map{ |c| c.to_s }.join(','), e.coords_string
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_geocode_with_block_doesnt_auto_assign_coordinates
|
14
|
-
e = Event.new(*venue_params(:msg))
|
15
|
-
e.geocode
|
16
|
-
assert_nil e.latitude
|
17
|
-
assert_nil e.longitude
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_reverse_geocode_with_block_runs_block
|
21
|
-
e = Party.new(*landmark_params(:msg))
|
22
|
-
e.reverse_geocode
|
23
|
-
assert_equal "US", e.country
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_reverse_geocode_with_block_doesnt_auto_assign_address
|
27
|
-
e = Party.new(*landmark_params(:msg))
|
28
|
-
e.reverse_geocode
|
29
|
-
assert_nil e.address
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
@@ -1,26 +0,0 @@
|
|
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/near_test.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class NearTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def test_near_scope_options_without_sqlite_includes_bounding_box_condition
|
6
|
-
result = Event.send(:near_scope_options, 1.0, 2.0, 5)
|
7
|
-
|
8
|
-
assert_match /test_table_name.latitude BETWEEN 0.9276\d* AND 1.0723\d* AND test_table_name.longitude BETWEEN 1.9276\d* AND 2.0723\d* AND /,
|
9
|
-
result[:conditions][0]
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_near_scope_options_with_defaults
|
13
|
-
result = Event.send(:near_scope_options, 1.0, 2.0, 5)
|
14
|
-
|
15
|
-
assert_match /AS distance/, result[:select]
|
16
|
-
assert_match /AS bearing/, result[:select]
|
17
|
-
assert_no_consecutive_comma(result[:select])
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_near_scope_options_with_no_distance
|
21
|
-
result = Event.send(:near_scope_options, 1.0, 2.0, 5, :select_distance => false)
|
22
|
-
|
23
|
-
assert_no_match /AS distance/, result[:select]
|
24
|
-
assert_match /AS bearing/, result[:select]
|
25
|
-
assert_no_match /distance/, result[:condition]
|
26
|
-
assert_no_match /distance/, result[:order]
|
27
|
-
assert_no_consecutive_comma(result[:select])
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_near_scope_options_with_no_bearing
|
31
|
-
result = Event.send(:near_scope_options, 1.0, 2.0, 5, :select_bearing => false)
|
32
|
-
|
33
|
-
assert_match /AS distance/, result[:select]
|
34
|
-
assert_no_match /AS bearing/, result[:select]
|
35
|
-
assert_no_consecutive_comma(result[:select])
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_near_scope_options_with_custom_distance_column
|
39
|
-
result = Event.send(:near_scope_options, 1.0, 2.0, 5, :distance_column => 'calculated_distance')
|
40
|
-
|
41
|
-
assert_no_match /AS distance/, result[:select]
|
42
|
-
assert_match /AS calculated_distance/, result[:select]
|
43
|
-
assert_no_match /\bdistance\b/, result[:order]
|
44
|
-
assert_match /calculated_distance/, result[:order]
|
45
|
-
assert_no_consecutive_comma(result[:select])
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_near_scope_options_with_custom_bearing_column
|
49
|
-
result = Event.send(:near_scope_options, 1.0, 2.0, 5, :bearing_column => 'calculated_bearing')
|
50
|
-
|
51
|
-
assert_no_match /AS bearing/, result[:select]
|
52
|
-
assert_match /AS calculated_bearing/, result[:select]
|
53
|
-
assert_no_consecutive_comma(result[:select])
|
54
|
-
end
|
55
|
-
|
56
|
-
private
|
57
|
-
|
58
|
-
def assert_no_consecutive_comma(string)
|
59
|
-
assert_no_match /, *,/, string, "two consecutive commas"
|
60
|
-
end
|
61
|
-
end
|
data/test/services_test.rb
DELETED
@@ -1,393 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'test_helper'
|
3
|
-
|
4
|
-
class ServicesTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
# --- Google ---
|
7
|
-
|
8
|
-
def test_google_result_components
|
9
|
-
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
10
|
-
assert_equal "Manhattan",
|
11
|
-
result.address_components_of_type(:sublocality).first['long_name']
|
12
|
-
end
|
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
|
-
|
20
|
-
def test_google_result_components_contains_street_number
|
21
|
-
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
22
|
-
assert_equal "4",
|
23
|
-
result.address_components_of_type(:street_number).first['long_name']
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_google_returns_city_when_no_locality_in_result
|
27
|
-
result = Geocoder.search("no locality").first
|
28
|
-
assert_equal "Haram", result.city
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_google_city_results_returns_nil_if_no_matching_component_types
|
32
|
-
result = Geocoder.search("no city data").first
|
33
|
-
assert_equal nil, result.city
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_google_street_address_returns_formatted_street_address
|
37
|
-
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
38
|
-
assert_equal "4 Penn Plaza", result.street_address
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_google_precision
|
42
|
-
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
43
|
-
assert_equal "ROOFTOP",
|
44
|
-
result.precision
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_google_query_url_contains_bounds
|
48
|
-
lookup = Geocoder::Lookup::Google.new
|
49
|
-
url = lookup.query_url(Geocoder::Query.new(
|
50
|
-
"Some Intersection",
|
51
|
-
:bounds => [[40.0, -120.0], [39.0, -121.0]]
|
52
|
-
))
|
53
|
-
assert_match /bounds=40.0+%2C-120.0+%7C39.0+%2C-121.0+/, url
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_google_query_url_contains_region
|
57
|
-
lookup = Geocoder::Lookup::Google.new
|
58
|
-
url = lookup.query_url(Geocoder::Query.new(
|
59
|
-
"Some Intersection",
|
60
|
-
:region => "gb"
|
61
|
-
))
|
62
|
-
assert_match /region=gb/, url
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_google_query_url_contains_components_when_given_as_string
|
66
|
-
lookup = Geocoder::Lookup::Google.new
|
67
|
-
url = lookup.query_url(Geocoder::Query.new(
|
68
|
-
"Some Intersection",
|
69
|
-
:components => "locality:ES"
|
70
|
-
))
|
71
|
-
formatted = "components=" + CGI.escape("locality:ES")
|
72
|
-
assert url.include?(formatted), "Expected #{formatted} to be included in #{url}"
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_google_query_url_contains_components_when_given_as_array
|
76
|
-
lookup = Geocoder::Lookup::Google.new
|
77
|
-
url = lookup.query_url(Geocoder::Query.new(
|
78
|
-
"Some Intersection",
|
79
|
-
:components => ["country:ES", "locality:ES"]
|
80
|
-
))
|
81
|
-
formatted = "components=" + CGI.escape("country:ES|locality:ES")
|
82
|
-
assert url.include?(formatted), "Expected #{formatted} to be included in #{url}"
|
83
|
-
end
|
84
|
-
|
85
|
-
# --- Google Premier ---
|
86
|
-
|
87
|
-
def test_google_premier_result_components
|
88
|
-
Geocoder.configure(:lookup => :google_premier)
|
89
|
-
set_api_key!(:google_premier)
|
90
|
-
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
91
|
-
assert_equal "Manhattan",
|
92
|
-
result.address_components_of_type(:sublocality).first['long_name']
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_google_premier_query_url
|
96
|
-
Geocoder.configure(:api_key => ["deadbeef", "gme-test", "test-dev"])
|
97
|
-
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=",
|
98
|
-
Geocoder::Lookup::GooglePremier.new.query_url(Geocoder::Query.new("Madison Square Garden, New York, NY"))
|
99
|
-
end
|
100
|
-
|
101
|
-
# --- DSTK (Data Science Toolkit) ---
|
102
|
-
|
103
|
-
def test_dstk_result_components
|
104
|
-
Geocoder.configure(:lookup => :dstk, :dstk => { :host => 'NOT_AN_ACTUAL_HOST' })
|
105
|
-
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
106
|
-
assert_equal "Manhattan",
|
107
|
-
result.address_components_of_type(:sublocality).first['long_name']
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_dstk_query_url
|
111
|
-
Geocoder.configure(:lookup => :dstk, :dstk => { :host => 'NOT_AN_ACTUAL_HOST' })
|
112
|
-
assert_equal "http://NOT_AN_ACTUAL_HOST/maps/api/geocode/json?address=Madison+Square+Garden%2C+New+York%2C+NY&language=en&sensor=false",
|
113
|
-
Geocoder::Lookup::Dstk.new.query_url(Geocoder::Query.new("Madison Square Garden, New York, NY"))
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_dstk_default_query_url
|
117
|
-
Geocoder.configure(:lookup => :dstk)
|
118
|
-
assert_equal "http://www.datasciencetoolkit.org/maps/api/geocode/json?address=Madison+Square+Garden%2C+New+York%2C+NY&language=en&sensor=false",
|
119
|
-
Geocoder::Lookup::Dstk.new.query_url(Geocoder::Query.new("Madison Square Garden, New York, NY"))
|
120
|
-
end
|
121
|
-
|
122
|
-
# --- Yahoo ---
|
123
|
-
|
124
|
-
def test_yahoo_no_results
|
125
|
-
Geocoder.configure(:lookup => :yahoo)
|
126
|
-
set_api_key!(:yahoo)
|
127
|
-
assert_equal [], Geocoder.search("no results")
|
128
|
-
end
|
129
|
-
|
130
|
-
def test_yahoo_error
|
131
|
-
Geocoder.configure(:lookup => :yahoo)
|
132
|
-
set_api_key!(:yahoo)
|
133
|
-
# keep test output clean: suppress timeout warning
|
134
|
-
orig = $VERBOSE; $VERBOSE = nil
|
135
|
-
assert_equal [], Geocoder.search("error")
|
136
|
-
ensure
|
137
|
-
$VERBOSE = orig
|
138
|
-
end
|
139
|
-
|
140
|
-
def test_yahoo_result_components
|
141
|
-
Geocoder.configure(:lookup => :yahoo)
|
142
|
-
set_api_key!(:yahoo)
|
143
|
-
result = Geocoder.search("madison square garden").first
|
144
|
-
assert_equal "10001", result.postal_code
|
145
|
-
end
|
146
|
-
|
147
|
-
def test_yahoo_address_formatting
|
148
|
-
Geocoder.configure(:lookup => :yahoo)
|
149
|
-
set_api_key!(:yahoo)
|
150
|
-
result = Geocoder.search("madison square garden").first
|
151
|
-
assert_equal "Madison Square Garden, New York, NY 10001, United States", result.address
|
152
|
-
end
|
153
|
-
|
154
|
-
def test_yahoo_raises_exception_when_over_query_limit
|
155
|
-
Geocoder.configure(:always_raise => [Geocoder::OverQueryLimitError])
|
156
|
-
l = Geocoder::Lookup.get(:yahoo)
|
157
|
-
assert_raises Geocoder::OverQueryLimitError do
|
158
|
-
l.send(:results, Geocoder::Query.new("over limit"))
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
# --- Geocoder.ca ---
|
163
|
-
|
164
|
-
def test_geocoder_ca_result_components
|
165
|
-
Geocoder.configure(:lookup => :geocoder_ca)
|
166
|
-
set_api_key!(:geocoder_ca)
|
167
|
-
result = Geocoder.search([45.423733, -75.676333]).first
|
168
|
-
assert_equal "CA", result.country_code
|
169
|
-
assert_equal "289 Somerset ST E, Ottawa, ON K1N6W1, Canada", result.address
|
170
|
-
end
|
171
|
-
|
172
|
-
|
173
|
-
# --- FreeGeoIp ---
|
174
|
-
|
175
|
-
def test_freegeoip_result_on_ip_address_search
|
176
|
-
result = Geocoder.search("74.200.247.59").first
|
177
|
-
assert result.is_a?(Geocoder::Result::Freegeoip)
|
178
|
-
end
|
179
|
-
|
180
|
-
def test_freegeoip_result_components
|
181
|
-
result = Geocoder.search("74.200.247.59").first
|
182
|
-
assert_equal "Plano, TX 75093, United States", result.address
|
183
|
-
end
|
184
|
-
|
185
|
-
# --- MaxMind ---
|
186
|
-
|
187
|
-
def test_maxmind_result_on_ip_address_search
|
188
|
-
Geocoder.configure(:ip_lookup => :maxmind, :maxmind => {:service => :city_isp_org})
|
189
|
-
result = Geocoder.search("74.200.247.59").first
|
190
|
-
assert result.is_a?(Geocoder::Result::Maxmind)
|
191
|
-
end
|
192
|
-
|
193
|
-
def test_maxmind_result_knows_country_service_name
|
194
|
-
Geocoder.configure(:ip_lookup => :maxmind, :maxmind => {:service => :country})
|
195
|
-
assert_equal :country, Geocoder.search("24.24.24.21").first.service_name
|
196
|
-
end
|
197
|
-
|
198
|
-
def test_maxmind_result_knows_city_service_name
|
199
|
-
Geocoder.configure(:ip_lookup => :maxmind, :maxmind => {:service => :city})
|
200
|
-
assert_equal :city, Geocoder.search("24.24.24.22").first.service_name
|
201
|
-
end
|
202
|
-
|
203
|
-
def test_maxmind_result_knows_city_isp_org_service_name
|
204
|
-
Geocoder.configure(:ip_lookup => :maxmind, :maxmind => {:service => :city_isp_org})
|
205
|
-
assert_equal :city_isp_org, Geocoder.search("24.24.24.23").first.service_name
|
206
|
-
end
|
207
|
-
|
208
|
-
def test_maxmind_result_knows_omni_service_name
|
209
|
-
Geocoder.configure(:ip_lookup => :maxmind, :maxmind => {:service => :omni})
|
210
|
-
assert_equal :omni, Geocoder.search("24.24.24.24").first.service_name
|
211
|
-
end
|
212
|
-
|
213
|
-
def test_maxmind_special_result_components
|
214
|
-
Geocoder.configure(:ip_lookup => :maxmind, :maxmind => {:service => :omni})
|
215
|
-
result = Geocoder.search("24.24.24.24").first
|
216
|
-
assert_equal "Road Runner", result.isp_name
|
217
|
-
assert_equal "Cable/DSL", result.netspeed
|
218
|
-
assert_equal "rr.com", result.domain
|
219
|
-
end
|
220
|
-
|
221
|
-
def test_maxmind_raises_exception_when_service_not_configured
|
222
|
-
Geocoder.configure(:ip_lookup => :maxmind)
|
223
|
-
Geocoder.configure(:maxmind => {:service => nil})
|
224
|
-
assert_raises Geocoder::ConfigurationError do
|
225
|
-
Geocoder::Query.new("24.24.24.24").url
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
def test_maxmind_works_when_loopback_address_on_omni
|
230
|
-
Geocoder.configure(:ip_lookup => :maxmind, :maxmind => { :service => :omni })
|
231
|
-
result = Geocoder.search("127.0.0.1").first
|
232
|
-
assert_equal "", result.country_code
|
233
|
-
end
|
234
|
-
|
235
|
-
def test_maxmind_works_when_loopback_address_on_country
|
236
|
-
Geocoder.configure(:ip_lookup => :maxmind, :maxmind => { :service => :country })
|
237
|
-
result = Geocoder.search("127.0.0.1").first
|
238
|
-
assert_equal "", result.country_code
|
239
|
-
end
|
240
|
-
|
241
|
-
|
242
|
-
# --- Bing ---
|
243
|
-
|
244
|
-
def test_bing_result_components
|
245
|
-
Geocoder.configure(:lookup => :bing)
|
246
|
-
set_api_key!(:bing)
|
247
|
-
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
248
|
-
assert_equal "Madison Square Garden, NY", result.address
|
249
|
-
assert_equal "NY", result.state
|
250
|
-
assert_equal "New York", result.city
|
251
|
-
end
|
252
|
-
|
253
|
-
def test_bing_no_results
|
254
|
-
Geocoder.configure(:lookup => :bing)
|
255
|
-
set_api_key!(:bing)
|
256
|
-
results = Geocoder.search("no results")
|
257
|
-
assert_equal 0, results.length
|
258
|
-
end
|
259
|
-
|
260
|
-
# --- Nominatim ---
|
261
|
-
|
262
|
-
def test_nominatim_result_components
|
263
|
-
Geocoder.configure(:lookup => :nominatim)
|
264
|
-
set_api_key!(:nominatim)
|
265
|
-
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
266
|
-
assert_equal "10001", result.postal_code
|
267
|
-
end
|
268
|
-
|
269
|
-
def test_nominatim_address_formatting
|
270
|
-
Geocoder.configure(:lookup => :nominatim)
|
271
|
-
set_api_key!(:nominatim)
|
272
|
-
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
273
|
-
assert_equal "Madison Square Garden, West 31st Street, Long Island City, New York City, New York, 10001, United States of America",
|
274
|
-
result.address
|
275
|
-
end
|
276
|
-
|
277
|
-
def test_nominatim_host_config
|
278
|
-
Geocoder.configure(:lookup => :nominatim, :nominatim => {:host => "local.com"})
|
279
|
-
lookup = Geocoder::Lookup::Nominatim.new
|
280
|
-
query = Geocoder::Query.new("Bluffton, SC")
|
281
|
-
assert_match %r(http://local\.com), lookup.query_url(query)
|
282
|
-
end
|
283
|
-
|
284
|
-
# --- MapQuest ---
|
285
|
-
|
286
|
-
def test_api_route
|
287
|
-
Geocoder.configure(:lookup => :mapquest, :api_key => "abc123")
|
288
|
-
lookup = Geocoder::Lookup::Mapquest.new
|
289
|
-
query = Geocoder::Query.new("Bluffton, SC")
|
290
|
-
res = lookup.query_url(query)
|
291
|
-
assert_equal "http://open.mapquestapi.com/geocoding/v1/address?key=abc123&location=Bluffton%2C+SC",
|
292
|
-
res
|
293
|
-
end
|
294
|
-
|
295
|
-
def test_api_route_licensed
|
296
|
-
Geocoder.configure(:lookup => :mapquest, :api_key => "abc123", :mapquest => {:licensed => true, :version => 2})
|
297
|
-
lookup = Geocoder::Lookup::Mapquest.new
|
298
|
-
query = Geocoder::Query.new("Bluffton, SC")
|
299
|
-
res = lookup.query_url(query)
|
300
|
-
assert_equal "http://www.mapquestapi.com/geocoding/v2/address?key=abc123&location=Bluffton%2C+SC",
|
301
|
-
res
|
302
|
-
end
|
303
|
-
|
304
|
-
def test_mapquest_result_components
|
305
|
-
Geocoder.configure(:lookup => :mapquest)
|
306
|
-
set_api_key!(:mapquest)
|
307
|
-
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
308
|
-
assert_equal "10001", result.postal_code
|
309
|
-
end
|
310
|
-
|
311
|
-
def test_mapquest_address_formatting
|
312
|
-
Geocoder.configure(:lookup => :mapquest)
|
313
|
-
set_api_key!(:mapquest)
|
314
|
-
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
315
|
-
assert_equal "46 West 31st Street, New York, NY, 10001, US",
|
316
|
-
result.address
|
317
|
-
end
|
318
|
-
|
319
|
-
def test_mapquest_no_results
|
320
|
-
Geocoder.configure(:lookup => :mapquest)
|
321
|
-
set_api_key!(:mapquest)
|
322
|
-
assert_equal [], Geocoder.search("no results")
|
323
|
-
end
|
324
|
-
|
325
|
-
def test_mapquest_raises_exception_when_invalid_request
|
326
|
-
Geocoder.configure(:always_raise => [Geocoder::InvalidRequest])
|
327
|
-
l = Geocoder::Lookup.get(:mapquest)
|
328
|
-
assert_raises Geocoder::InvalidRequest do
|
329
|
-
l.send(:results, Geocoder::Query.new("invalid request"))
|
330
|
-
end
|
331
|
-
end
|
332
|
-
|
333
|
-
def test_mapquest_raises_exception_when_invalid_api_key
|
334
|
-
Geocoder.configure(:always_raise => [Geocoder::InvalidApiKey])
|
335
|
-
l = Geocoder::Lookup.get(:mapquest)
|
336
|
-
assert_raises Geocoder::InvalidApiKey do
|
337
|
-
l.send(:results, Geocoder::Query.new("invalid api key"))
|
338
|
-
end
|
339
|
-
end
|
340
|
-
|
341
|
-
def test_mapquest_raises_exception_when_error
|
342
|
-
Geocoder.configure(:always_raise => [Geocoder::Error])
|
343
|
-
l = Geocoder::Lookup.get(:mapquest)
|
344
|
-
assert_raises Geocoder::Error do
|
345
|
-
l.send(:results, Geocoder::Query.new("error"))
|
346
|
-
end
|
347
|
-
end
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
# --- Esri ---
|
352
|
-
|
353
|
-
def test_esri_query_for_geocode
|
354
|
-
query = Geocoder::Query.new("Bluffton, SC")
|
355
|
-
lookup = Geocoder::Lookup.get(:esri)
|
356
|
-
res = lookup.query_url(query)
|
357
|
-
assert_equal "http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find?f=pjson&outFields=%2A&text=Bluffton%2C+SC",
|
358
|
-
res
|
359
|
-
end
|
360
|
-
|
361
|
-
def test_esri_query_for_reverse_geocode
|
362
|
-
query = Geocoder::Query.new([45.423733, -75.676333])
|
363
|
-
lookup = Geocoder::Lookup.get(:esri)
|
364
|
-
res = lookup.query_url(query)
|
365
|
-
assert_equal "http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode?f=pjson&location=-75.676333%2C45.423733&outFields=%2A",
|
366
|
-
res
|
367
|
-
end
|
368
|
-
|
369
|
-
def test_esri_results_component
|
370
|
-
Geocoder.configure(:lookup => :esri)
|
371
|
-
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
372
|
-
assert_equal "10001", result.postal_code
|
373
|
-
assert_equal "USA", result.country
|
374
|
-
assert_equal "Madison Square Garden", result.address
|
375
|
-
assert_equal "New York", result.city
|
376
|
-
assert_equal "New York", result.state
|
377
|
-
assert_equal 40.75004981300049, result.coordinates[0]
|
378
|
-
assert_equal -73.99423889799965, result.coordinates[1]
|
379
|
-
end
|
380
|
-
|
381
|
-
def test_esri_results_component_when_reverse_geocoding
|
382
|
-
Geocoder.configure(:lookup => :esri)
|
383
|
-
result = Geocoder.search([45.423733, -75.676333]).first
|
384
|
-
assert_equal "75007", result.postal_code
|
385
|
-
assert_equal "FRA", result.country
|
386
|
-
assert_equal "4 Avenue Gustave Eiffel", result.address
|
387
|
-
assert_equal "Paris", result.city
|
388
|
-
assert_equal "Île-de-France", result.state
|
389
|
-
assert_equal 48.858129997357558, result.coordinates[0]
|
390
|
-
assert_equal 2.2956200048981574, result.coordinates[1]
|
391
|
-
end
|
392
|
-
|
393
|
-
end
|