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
data/test/test_polygon.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require File.join(File.dirname(__FILE__),
|
2
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
3
3
|
|
4
4
|
class PolygonTest < Test::Unit::TestCase #:nodoc: all
|
5
5
|
def setup
|
@@ -53,30 +53,20 @@ class PolygonTest < Test::Unit::TestCase #:nodoc: all
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def test_point_inside_poly
|
56
|
-
# puts "\n\nTesting point inside poly... {@polygon.contains?(@point_inside)}\n\n"
|
57
56
|
assert @polygon.contains?(@point_inside)
|
58
57
|
end
|
59
58
|
|
60
59
|
def test_point_outside_poly
|
61
|
-
# puts "\n\nTesting point outside poly... {@polygon.contains?(@point_outside)}\n\n"
|
62
60
|
assert !@polygon.contains?(@point_outside)
|
63
61
|
end
|
64
62
|
|
65
63
|
def test_points_inside_complex_poly
|
66
|
-
# puts "\n\nTesting points INSIDE complex poly..."
|
67
|
-
# puts "\tone: {@complex_polygon.contains?(@complex_inside_one)}"
|
68
|
-
# puts "\ttwo: {@complex_polygon.contains?(@complex_inside_two)}"
|
69
|
-
# puts "\tthree: {@complex_polygon.contains?(@complex_inside_three)}\n\n"
|
70
64
|
assert @complex_polygon.contains?(@complex_inside_one)
|
71
65
|
assert @complex_polygon.contains?(@complex_inside_two)
|
72
66
|
assert @complex_polygon.contains?(@complex_inside_three)
|
73
67
|
end
|
74
68
|
|
75
69
|
def test_points_outside_complex_poly
|
76
|
-
# puts "\n\nTesting points OUTSIDE complex poly..."
|
77
|
-
# puts "\tone: {@complex_polygon.contains?(@complex_outside_one)}"
|
78
|
-
# puts "\ttwo: {@complex_polygon.contains?(@complex_outside_two)}"
|
79
|
-
# puts "\tthree: {@complex_polygon.contains?(@complex_outside_three)}\n\n"
|
80
70
|
assert !@complex_polygon.contains?(@complex_outside_one)
|
81
71
|
assert !@complex_polygon.contains?(@complex_outside_two)
|
82
72
|
assert !@complex_polygon.contains?(@complex_outside_three)
|
@@ -85,27 +75,19 @@ class PolygonTest < Test::Unit::TestCase #:nodoc: all
|
|
85
75
|
def test_open_polygon
|
86
76
|
# A polygon can only exist of the last point is equal to the first
|
87
77
|
# Otherwise, it would just be a line of points.
|
88
|
-
|
89
|
-
# puts "\n\nTesting intialize function to close an open polygon..."
|
90
|
-
# puts "\t Does poly_x[0] (#{@open_polygon.poly_x[0]}) == poly_x[-1] (#{@open_polygon.poly_x[-1]}) ?"
|
91
|
-
# puts "\t Does poly_y[0] (#{@open_polygon.poly_y[0]}) == poly_y[-1] (#{@open_polygon.poly_y[-1]}) ?"
|
92
|
-
|
93
78
|
assert @open_polygon.points[0].lng == @open_polygon.points[-1].lng
|
94
79
|
assert @open_polygon.points[0].lat == @open_polygon.points[-1].lat
|
95
80
|
end
|
96
81
|
|
97
82
|
def test_centroid_for_simple_poly
|
98
|
-
@
|
99
|
-
assert_equal(@polygon.centroid, @polygon_centroid)
|
83
|
+
assert_ll @polygon.centroid, 45.27463866133501, -93.41400121829719
|
100
84
|
end
|
101
85
|
|
102
86
|
def test_centroid_for_complex_poly
|
103
|
-
@
|
104
|
-
assert_equal(@complex_polygon.centroid, @complex_polygon_centroid)
|
87
|
+
assert_ll @complex_polygon.centroid, 45.43622702936517, -93.5352210389731
|
105
88
|
end
|
106
89
|
|
107
90
|
def test_centroid_for_open_poly
|
108
|
-
@
|
109
|
-
assert_equal(@open_polygon.centroid, @open_polygon_centroid)
|
91
|
+
assert_ll @open_polygon.centroid, 44.95912726688109, -92.7068888186181
|
110
92
|
end
|
111
93
|
end
|
data/test/test_ripe_geocoder.rb
CHANGED
@@ -1,44 +1,39 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__),
|
1
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
2
2
|
|
3
3
|
class RipeGeocoderTest < BaseGeocoderTest #:nodoc: all
|
4
4
|
def setup
|
5
5
|
super
|
6
|
-
@ip =
|
7
|
-
@ip_au =
|
6
|
+
@ip = '74.125.237.209'
|
7
|
+
@ip_au = '118.210.24.54'
|
8
|
+
@base_url = 'http://stat.ripe.net/data/geoloc/data.json'
|
8
9
|
end
|
9
10
|
|
10
11
|
def assert_url(expected_url)
|
11
|
-
assert_equal expected_url, TestHelper.
|
12
|
+
assert_equal expected_url, TestHelper.last_url.gsub(/&oauth_[a-z_]+=[a-zA-Z0-9\-. %]+/, '').gsub('%20', '+')
|
12
13
|
end
|
13
14
|
|
14
15
|
def test_45
|
15
|
-
|
16
|
-
|
17
|
-
assert !res.success
|
18
|
-
end
|
16
|
+
res = geocode('45.45.45.45', :ripe_geocode_45)
|
17
|
+
assert !res.success
|
19
18
|
end
|
20
19
|
|
21
20
|
def test_ripe_geocode
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
assert_equal res.country_code, "US"
|
30
|
-
end
|
21
|
+
url = "#{@base_url}?resource=#{@ip}"
|
22
|
+
res = geocode(@ip, :ripe_geocode)
|
23
|
+
assert_url url
|
24
|
+
assert_equal res.city, 'Mountain View'
|
25
|
+
assert_equal res.state, 'CA'
|
26
|
+
assert_equal res.state_code, 'CA'
|
27
|
+
assert_equal res.country_code, 'US'
|
31
28
|
end
|
32
29
|
|
33
30
|
def test_ripe_geocode_au
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
assert_equal res.country_code, "AU"
|
42
|
-
end
|
31
|
+
url = "#{@base_url}?resource=#{@ip_au}"
|
32
|
+
res = geocode(@ip_au, :ripe_geocode_au)
|
33
|
+
assert_url url
|
34
|
+
assert_equal res.city, 'Adelaide'
|
35
|
+
assert_equal res.state, nil
|
36
|
+
assert_equal res.state_code, nil
|
37
|
+
assert_equal res.country_code, 'AU'
|
43
38
|
end
|
44
39
|
end
|
data/test/test_us_geocoder.rb
CHANGED
@@ -1,55 +1,55 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__),
|
2
|
-
|
3
|
-
Geokit::Geocoders::UsGeocoder.key = nil
|
1
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
4
2
|
|
5
3
|
class UsGeocoderTest < BaseGeocoderTest #:nodoc: all
|
6
|
-
GEOCODER_US_FULL =
|
4
|
+
GEOCODER_US_FULL = '37.792528,-122.393981,100 Spear St,San Francisco,CA,94105'
|
7
5
|
|
8
6
|
def setup
|
7
|
+
geocoder_class.key = nil
|
9
8
|
super
|
10
|
-
@us_full_hash = {city:
|
9
|
+
@us_full_hash = {city: 'San Francisco', state: 'CA'}
|
11
10
|
@us_full_loc = Geokit::GeoLoc.new(@us_full_hash)
|
11
|
+
@base_url = 'http://geocoder.us/service/csv/geocode'
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_geocoder_us
|
15
15
|
response = MockSuccess.new
|
16
16
|
response.expects(:body).returns(GEOCODER_US_FULL)
|
17
|
-
url = "
|
18
|
-
|
19
|
-
verify(
|
17
|
+
url = "#{@base_url}?address=#{escape(@address)}"
|
18
|
+
geocoder_class.expects(:call_geocoder_service).with(url).returns(response)
|
19
|
+
verify(geocode(@address))
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_geocoder_with_geo_loc
|
23
23
|
response = MockSuccess.new
|
24
24
|
response.expects(:body).returns(GEOCODER_US_FULL)
|
25
|
-
url = "
|
26
|
-
|
27
|
-
verify(
|
25
|
+
url = "#{@base_url}?address=#{escape(@address)}"
|
26
|
+
geocoder_class.expects(:call_geocoder_service).with(url).returns(response)
|
27
|
+
verify(geocode(@us_full_loc))
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_service_unavailable
|
31
31
|
response = MockFailure.new
|
32
|
-
url = "
|
33
|
-
|
34
|
-
assert !
|
32
|
+
url = "#{@base_url}?address=#{escape(@address)}"
|
33
|
+
geocoder_class.expects(:call_geocoder_service).with(url).returns(response)
|
34
|
+
assert !geocode(@us_full_loc).success
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_all_method
|
38
38
|
response = MockSuccess.new
|
39
39
|
response.expects(:body).returns(GEOCODER_US_FULL)
|
40
|
-
url = "
|
41
|
-
|
42
|
-
res =
|
40
|
+
url = "#{@base_url}?address=#{escape(@address)}"
|
41
|
+
geocoder_class.expects(:call_geocoder_service).with(url).returns(response)
|
42
|
+
res = geocode(@address)
|
43
43
|
assert_equal 1, res.all.size
|
44
44
|
end
|
45
45
|
|
46
46
|
private
|
47
47
|
|
48
48
|
def verify(location)
|
49
|
-
assert_equal
|
50
|
-
assert_equal
|
51
|
-
assert_equal
|
49
|
+
assert_equal 'CA', location.state
|
50
|
+
assert_equal 'San Francisco', location.city
|
51
|
+
assert_equal '37.792528,-122.393981', location.ll
|
52
52
|
assert location.is_us?
|
53
|
-
assert_equal
|
53
|
+
assert_equal '100 Spear St, San Francisco, CA, 94105, US', location.full_address # slightly different from yahoo
|
54
54
|
end
|
55
55
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'webmock/test_unit'
|
3
|
+
|
4
|
+
require File.join(File.dirname(__FILE__), '../lib/geokit.rb')
|
5
|
+
|
6
|
+
class UserAgentTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
NETHTTPDEFAULT = 'Ruby'
|
9
|
+
NETHTTPDEFAULTHEADERS = {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'}
|
10
|
+
TYPHOEUSDEFAULT = 'Typhoeus - https://github.com/typhoeus/typhoeus'
|
11
|
+
TYPHOEUSDEFAULTHEADERS = {}
|
12
|
+
TESTAGENT = 'MyAgent'
|
13
|
+
URL = 'http://www.example.com'
|
14
|
+
|
15
|
+
def test_nethttp_useragent_set_to_testagent
|
16
|
+
stub_request(:get, URL).with(:headers => NETHTTPDEFAULTHEADERS.merge('User-Agent' => TESTAGENT))
|
17
|
+
|
18
|
+
Geokit::Geocoders::useragent = TESTAGENT
|
19
|
+
Geokit::NetAdapter::NetHttp.do_get(URL)
|
20
|
+
assert_requested :get, URL
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_nethttp_useragent_set_to_default
|
24
|
+
stub_request(:get, URL).with(:headers => NETHTTPDEFAULTHEADERS.merge('User-Agent' => NETHTTPDEFAULT))
|
25
|
+
|
26
|
+
Geokit::Geocoders::useragent = nil
|
27
|
+
Geokit::NetAdapter::NetHttp.do_get(URL)
|
28
|
+
assert_requested :get, URL
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_typhoeus_set_to_testagent
|
32
|
+
stub_request(:get, URL).with(:headers => TYPHOEUSDEFAULTHEADERS.merge('User-Agent' => TESTAGENT))
|
33
|
+
|
34
|
+
Geokit::Geocoders::useragent = TESTAGENT
|
35
|
+
Geokit::NetAdapter::Typhoeus.do_get(URL)
|
36
|
+
assert_requested :get, URL
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_typhoeus_set_to_default
|
40
|
+
stub_request(:get, URL).with(:headers => TYPHOEUSDEFAULTHEADERS.merge('User-Agent' => TYPHOEUSDEFAULT))
|
41
|
+
|
42
|
+
Geokit::Geocoders::useragent = nil
|
43
|
+
Geokit::NetAdapter::Typhoeus.do_get(URL)
|
44
|
+
assert_requested :get, URL
|
45
|
+
end
|
46
|
+
end
|
data/test/test_yahoo_geocoder.rb
CHANGED
@@ -1,107 +1,95 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__),
|
2
|
-
|
3
|
-
Geokit::Geocoders::YahooGeocoder.key = "dj0yJmk9cXByQVN2WHZmTVhDJmQ9WVdrOVZscG1WVWhOTldrbWNHbzlNakF6TlRJME16UTJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD0zNg--"
|
4
|
-
Geokit::Geocoders::YahooGeocoder.secret = "SECRET"
|
1
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
5
2
|
|
6
3
|
class YahooGeocoderTest < BaseGeocoderTest #:nodoc: all
|
7
4
|
def setup
|
8
5
|
super
|
9
|
-
@yahoo_full_hash = {street_address:
|
10
|
-
@yahoo_city_hash = {city:
|
6
|
+
@yahoo_full_hash = {street_address: '100 Spear St', city: 'San Francisco', state: 'CA', zip: '94105-1522', country_code: 'US'}
|
7
|
+
@yahoo_city_hash = {city: 'San Francisco', state: 'CA'}
|
11
8
|
@yahoo_full_loc = Geokit::GeoLoc.new(@yahoo_full_hash)
|
12
9
|
@yahoo_city_loc = Geokit::GeoLoc.new(@yahoo_city_hash)
|
10
|
+
|
11
|
+
key = @keys['yahoo']
|
12
|
+
geocoder_class.key = key['key']
|
13
|
+
geocoder_class.secret = key['secret']
|
14
|
+
@base_url = 'https://yboss.yahooapis.com/geo/placefinder'
|
13
15
|
end
|
14
16
|
|
15
17
|
def assert_yahoo_url(expected_url)
|
16
|
-
assert_equal expected_url, TestHelper.
|
18
|
+
assert_equal expected_url, TestHelper.last_url.gsub(/&oauth_[a-z_]+=[a-zA-Z0-9\-. %]+/, '').gsub('%20', '+')
|
17
19
|
end
|
18
20
|
|
19
21
|
# the testing methods themselves
|
20
22
|
def test_yahoo_full_address
|
21
|
-
|
22
|
-
|
23
|
-
do_full_address_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@full_address))
|
23
|
+
url = "#{@base_url}?flags=J&q=#{escape(@full_address)}"
|
24
|
+
do_full_address_assertions(geocode(@full_address, :yahoo_full))
|
24
25
|
assert_yahoo_url url
|
25
|
-
end
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_yahoo_full_address_accuracy
|
29
|
-
|
30
|
-
|
31
|
-
res = Geokit::Geocoders::YahooGeocoder.geocode(@full_address)
|
29
|
+
url = "#{@base_url}?flags=J&q=#{escape(@full_address)}"
|
30
|
+
res = geocode(@full_address, :yahoo_full)
|
32
31
|
assert_yahoo_url url
|
33
32
|
assert_equal 8, res.accuracy
|
34
|
-
end
|
35
33
|
end
|
36
34
|
|
37
35
|
def test_yahoo_full_address_with_geo_loc
|
38
|
-
|
39
|
-
|
40
|
-
do_full_address_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@yahoo_full_loc))
|
36
|
+
url = "#{@base_url}?flags=J&q=#{escape(@full_address)}"
|
37
|
+
do_full_address_assertions(geocode(@yahoo_full_loc, :yahoo_full))
|
41
38
|
assert_yahoo_url url
|
42
|
-
end
|
43
39
|
end
|
44
40
|
|
45
41
|
def test_yahoo_city
|
46
|
-
|
47
|
-
|
48
|
-
do_city_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@address))
|
42
|
+
url = "#{@base_url}?flags=J&q=#{escape(@address)}"
|
43
|
+
do_city_assertions(geocode(@address, :yahoo_city))
|
49
44
|
assert_yahoo_url url
|
50
|
-
end
|
51
45
|
end
|
52
46
|
|
53
47
|
def test_yahoo_city_accuracy
|
54
|
-
|
55
|
-
|
56
|
-
res = Geokit::Geocoders::YahooGeocoder.geocode(@address)
|
48
|
+
url = "#{@base_url}?flags=J&q=#{escape(@address)}"
|
49
|
+
res = geocode(@address, :yahoo_city)
|
57
50
|
assert_yahoo_url url
|
58
51
|
assert_equal 4, res.accuracy
|
59
|
-
end
|
60
52
|
end
|
61
53
|
|
62
54
|
def test_yahoo_city_with_geo_loc
|
63
|
-
|
64
|
-
|
65
|
-
do_city_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@yahoo_city_loc))
|
55
|
+
url = "#{@base_url}?flags=J&q=#{escape(@address)}"
|
56
|
+
do_city_assertions(geocode(@yahoo_city_loc, :yahoo_city))
|
66
57
|
assert_yahoo_url url
|
67
|
-
end
|
68
58
|
end
|
69
59
|
|
70
60
|
def test_no_results
|
71
|
-
no_results_address =
|
72
|
-
|
73
|
-
|
74
|
-
result = Geokit::Geocoders::YahooGeocoder.geocode(no_results_address)
|
61
|
+
no_results_address = 'ZZ, ZZ, ZZ'
|
62
|
+
url = "#{@base_url}?flags=J&q=#{escape(no_results_address)}"
|
63
|
+
result = geocode(no_results_address, :yahoo_no_results)
|
75
64
|
assert_yahoo_url url
|
76
|
-
assert_equal
|
77
|
-
end
|
65
|
+
assert_equal ',', result.ll
|
78
66
|
end
|
79
67
|
|
80
68
|
def test_service_unavailable
|
81
69
|
response = MockFailure.new
|
82
|
-
|
83
|
-
assert !
|
70
|
+
geocoder_class.expects(:call_geocoder_service).returns(response)
|
71
|
+
assert !geocode(@yahoo_city_loc).success
|
84
72
|
end
|
85
73
|
|
86
74
|
private
|
87
75
|
|
88
76
|
# next two methods do the assertions for both address-level and city-level lookups
|
89
77
|
def do_full_address_assertions(res)
|
90
|
-
assert_equal
|
91
|
-
assert_equal
|
78
|
+
assert_equal 'CA', res.state
|
79
|
+
assert_equal 'San Francisco', res.city
|
92
80
|
assert_array_in_delta [37.792332, -122.393791], res.to_a
|
93
81
|
assert res.is_us?
|
94
|
-
assert_equal
|
95
|
-
assert_equal
|
82
|
+
assert_equal '100 Spear St, San Francisco, CA, 94105-1578, US', res.full_address
|
83
|
+
assert_equal 'yahoo', res.provider
|
96
84
|
end
|
97
85
|
|
98
86
|
def do_city_assertions(res)
|
99
|
-
assert_equal
|
100
|
-
assert_equal
|
87
|
+
assert_equal 'CA', res.state
|
88
|
+
assert_equal 'San Francisco', res.city
|
101
89
|
assert_array_in_delta [37.77713, -122.41964], res.to_a
|
102
90
|
assert res.is_us?
|
103
|
-
assert_equal
|
91
|
+
assert_equal 'San Francisco, CA, US', res.full_address
|
104
92
|
assert_nil res.street_address
|
105
|
-
assert_equal
|
93
|
+
assert_equal 'yahoo', res.provider
|
106
94
|
end
|
107
95
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
require File.join(File.dirname(__FILE__),
|
2
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
3
3
|
|
4
4
|
class YandexGeocoderTest < BaseGeocoderTest #:nodoc: all
|
5
5
|
YANDEX_FULL = <<-EOF.strip
|
@@ -7,7 +7,7 @@ class YandexGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
7
7
|
EOF
|
8
8
|
|
9
9
|
YANDEX_REGION = <<-EOF.strip
|
10
|
-
{"response":{"GeoObjectCollection":{"metaDataProperty":{"GeocoderResponseMetaData":{"request":"Ростов-на-Дону, ул. Станиславского, д.21","found":"
|
10
|
+
{"response":{"GeoObjectCollection":{"metaDataProperty":{"GeocoderResponseMetaData":{"request":"Ростов-на-Дону, ул. Станиславского, д.21","found":"2","results":"10"}},"featureMember":[{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"house","text":"Россия, Ростов-на-Дону, улица Станиславского, 21","precision":"exact","AddressDetails":{"Country":{"AddressLine":"Ростов-на-Дону, улица Станиславского, 21","CountryNameCode":"RU","CountryName":"Россия","AdministrativeArea":{"AdministrativeAreaName":"Ростовская область","SubAdministrativeArea":{"SubAdministrativeAreaName":"городской округ Ростов-на-Дону","Locality":{"LocalityName":"Ростов-на-Дону","Thoroughfare":{"ThoroughfareName":"улица Станиславского","Premise":{"PremiseNumber":"21"}}}}}}}}},"description":"Ростов-на-Дону, Россия","name":"улица Станиславского, 21","boundedBy":{"Envelope":{"lowerCorner":"39.695043 47.210284","upperCorner":"39.7115 47.221497"}},"Point":{"pos":"39.703272 47.21589"}}}]}}}
|
11
11
|
EOF
|
12
12
|
|
13
13
|
YANDEX_CITY = <<-EOF.strip
|
@@ -22,69 +22,71 @@ class YandexGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
22
22
|
super
|
23
23
|
@full_address = "Москва, улица Новый Арбат, дом 24"
|
24
24
|
@address = "город Москва"
|
25
|
+
@base_url = 'https://geocode-maps.yandex.ru/1.x'
|
25
26
|
end
|
26
27
|
|
27
28
|
# the testing methods themselves
|
28
29
|
def test_yandex_full_address
|
29
30
|
response = MockSuccess.new
|
30
31
|
response.expects(:body).returns(YANDEX_FULL)
|
31
|
-
url = "
|
32
|
-
|
33
|
-
res =
|
32
|
+
url = "#{@base_url}/?geocode=#{escape(@full_address)}&format=json"
|
33
|
+
geocoder_class.expects(:call_geocoder_service).with(url).returns(response)
|
34
|
+
res = geocode(@full_address)
|
34
35
|
|
35
|
-
assert_equal
|
36
|
+
assert_equal 'yandex', res.provider
|
36
37
|
assert_equal "улица Новый Арбат, 24", res.street_address
|
37
38
|
assert_equal "Москва", res.city
|
38
39
|
assert_equal 55.753083, res.lat
|
39
40
|
assert_equal 37.587614, res.lng
|
40
|
-
assert_equal
|
41
|
+
assert_equal 'RU', res.country_code
|
41
42
|
assert res.success
|
42
43
|
end
|
43
44
|
|
44
|
-
def
|
45
|
+
def test_yandex_full_address_with_region_and_district
|
45
46
|
region_address = "Ростов-на-Дону, ул. Станиславского, д.21"
|
46
47
|
response = MockSuccess.new
|
47
48
|
response.expects(:body).returns(YANDEX_REGION)
|
48
|
-
url = "
|
49
|
-
|
50
|
-
res =
|
49
|
+
url = "#{@base_url}/?geocode=#{escape(region_address)}&format=json"
|
50
|
+
geocoder_class.expects(:call_geocoder_service).with(url).returns(response)
|
51
|
+
res = geocode(region_address)
|
51
52
|
|
52
|
-
assert_equal
|
53
|
+
assert_equal 'yandex', res.provider
|
53
54
|
assert_equal "улица Станиславского, 21", res.street_address
|
54
|
-
assert_equal "
|
55
|
+
assert_equal "Ростов на Дону", res.city
|
55
56
|
assert_equal "Ростовская область", res.state
|
56
|
-
assert_equal
|
57
|
-
assert_equal
|
58
|
-
assert_equal
|
57
|
+
assert_equal "городской округ Ростов-на-Дону", res.district
|
58
|
+
assert_equal 47.21589, res.lat
|
59
|
+
assert_equal 39.703272, res.lng
|
60
|
+
assert_equal 'RU', res.country_code
|
59
61
|
assert res.success
|
60
62
|
end
|
61
63
|
|
62
64
|
def test_yandex_city
|
63
65
|
response = MockSuccess.new
|
64
66
|
response.expects(:body).returns(YANDEX_CITY)
|
65
|
-
url = "
|
66
|
-
|
67
|
-
res =
|
67
|
+
url = "#{@base_url}/?geocode=#{escape(@address)}&format=json"
|
68
|
+
geocoder_class.expects(:call_geocoder_service).with(url).returns(response)
|
69
|
+
res = geocode(@address)
|
68
70
|
|
69
|
-
assert_equal
|
70
|
-
assert_equal
|
71
|
+
assert_equal 'yandex', res.provider
|
72
|
+
assert_equal 'city', res.precision
|
71
73
|
assert_equal "Москва", res.city
|
72
74
|
assert_equal 55.755773, res.lat
|
73
75
|
assert_equal 37.617761, res.lng
|
74
|
-
assert_equal
|
76
|
+
assert_equal 'RU', res.country_code
|
75
77
|
assert res.success
|
76
78
|
end
|
77
79
|
|
78
80
|
def test_no_results
|
79
|
-
no_results_address =
|
81
|
+
no_results_address = 'ZZ, ZZ, ZZ'
|
80
82
|
# no_results_full_hash = {:street_address=>"ZZ", :city=>"ZZ", :state=>"ZZ"}
|
81
83
|
# no_results_full_loc = Geokit::GeoLoc.new(no_results_full_hash)
|
82
84
|
|
83
85
|
response = MockSuccess.new
|
84
86
|
response.expects(:body).returns(YANDEX_NO_RESULTS)
|
85
|
-
url = "
|
86
|
-
|
87
|
-
result =
|
88
|
-
assert_equal
|
87
|
+
url = "#{@base_url}/?geocode=#{escape(no_results_address)}&format=json"
|
88
|
+
geocoder_class.expects(:call_geocoder_service).with(url).returns(response)
|
89
|
+
result = geocode(no_results_address)
|
90
|
+
assert_equal ',', result.ll
|
89
91
|
end
|
90
92
|
end
|