geokit 1.8.5 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +0 -1
- data/CHANGELOG.md +7 -0
- data/README.markdown +31 -14
- data/fixtures/vcr_cassettes/geonames_geocode.yml +1 -1
- data/fixtures/vcr_cassettes/geonames_geocode_premium.yml +42 -0
- data/fixtures/vcr_cassettes/google_country_code_biased_result_orly.yml +160 -0
- data/fixtures/vcr_cassettes/google_country_code_biased_result_toledo.yml +111 -0
- data/fixtures/vcr_cassettes/google_result_toledo_default_bias.yml +275 -0
- data/fixtures/vcr_cassettes/google_sublocality.yml +126 -0
- data/fixtures/vcr_cassettes/mapbox_forward_geocode.yml +59 -0
- data/fixtures/vcr_cassettes/mapbox_reverse_geocode.yml +63 -0
- data/fixtures/vcr_cassettes/opencage_city.yml +51 -0
- data/fixtures/vcr_cassettes/opencage_full.yml +65 -0
- data/fixtures/vcr_cassettes/opencage_language_response_es.yml +66 -0
- data/fixtures/vcr_cassettes/opencage_reverse_madrid.yml +51 -0
- data/fixtures/vcr_cassettes/opencage_reverse_prilep.yml +53 -0
- data/geokit.gemspec +5 -3
- data/lib/geokit/bounds.rb +40 -31
- data/lib/geokit/core_ext.rb +1 -1
- data/lib/geokit/geo_loc.rb +63 -41
- data/lib/geokit/geocoders.rb +13 -13
- data/lib/geokit/geocoders/bing.rb +9 -9
- data/lib/geokit/geocoders/ca_geocoder.rb +29 -29
- data/lib/geokit/geocoders/fcc.rb +4 -4
- data/lib/geokit/geocoders/free_geo_ip.rb +6 -7
- data/lib/geokit/geocoders/geo_plugin.rb +5 -6
- data/lib/geokit/geocoders/geocodio.rb +2 -2
- data/lib/geokit/geocoders/geonames.rb +18 -12
- data/lib/geokit/geocoders/google.rb +31 -30
- data/lib/geokit/geocoders/ip.rb +3 -4
- data/lib/geokit/geocoders/mapbox.rb +94 -0
- data/lib/geokit/geocoders/mapquest.rb +5 -5
- data/lib/geokit/geocoders/opencage.rb +93 -0
- data/lib/geokit/geocoders/openstreetmap.rb +9 -6
- data/lib/geokit/geocoders/ripe.rb +3 -3
- data/lib/geokit/geocoders/us_geocoder.rb +10 -9
- data/lib/geokit/geocoders/yahoo.rb +33 -34
- data/lib/geokit/geocoders/yandex.rb +17 -17
- data/lib/geokit/inflectors.rb +4 -10
- data/lib/geokit/lat_lng.rb +50 -26
- data/lib/geokit/mappable.rb +83 -83
- data/lib/geokit/multi_geocoder.rb +25 -20
- data/lib/geokit/net_adapter/net_http.rb +7 -4
- data/lib/geokit/polygon.rb +36 -4
- data/lib/geokit/version.rb +1 -1
- data/test/helper.rb +15 -13
- data/test/test_base_geocoder.rb +6 -7
- data/test/test_bing_geocoder.rb +20 -21
- data/test/test_bounds.rb +26 -28
- data/test/test_ca_geocoder.rb +9 -10
- data/test/test_fcc_geocoder.rb +1 -1
- data/test/test_free_geo_ip_geocoder.rb +1 -1
- data/test/test_geo_plugin_geocoder.rb +9 -9
- data/test/test_geoloc.rb +7 -6
- data/test/test_geonames_geocoder.rb +28 -6
- data/test/test_google_geocoder.rb +210 -176
- data/test/test_inflector.rb +0 -1
- data/test/test_ipgeocoder.rb +17 -18
- data/test/test_latlng.rb +105 -85
- data/test/test_map_quest.rb +18 -21
- data/test/test_mapbox_geocoder.rb +31 -0
- data/test/test_mappable.rb +46 -0
- data/test/test_maxmind_geocoder.rb +1 -3
- data/test/test_multi_geocoder.rb +8 -9
- data/test/test_multi_ip_geocoder.rb +3 -5
- data/test/test_net_adapter.rb +4 -4
- data/test/test_opencage_geocoder.rb +108 -0
- data/test/test_openstreetmap_geocoder.rb +62 -44
- data/test/{test_polygon_contains.rb → test_polygon.rb} +30 -20
- data/test/test_ripe_geocoder.rb +2 -0
- data/test/test_us_geocoder.rb +7 -8
- data/test/test_yahoo_geocoder.rb +20 -21
- data/test/test_yandex_geocoder.rb +34 -35
- metadata +79 -56
- data/fixtures/vcr_cassettes/google_country_code_biased_result.yml +0 -401
data/lib/geokit/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -17,7 +17,10 @@ if ENV['COVERAGE']
|
|
17
17
|
require 'coveralls'
|
18
18
|
Coveralls.wear!
|
19
19
|
|
20
|
-
SimpleCov.formatter =
|
20
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
21
|
+
SimpleCov::Formatter::RcovFormatter,
|
22
|
+
Coveralls::SimpleCov::Formatter
|
23
|
+
]
|
21
24
|
SimpleCov.start do
|
22
25
|
add_filter '/test/'
|
23
26
|
add_group 'lib', 'lib'
|
@@ -26,7 +29,7 @@ if ENV['COVERAGE']
|
|
26
29
|
SimpleCov.result.format!
|
27
30
|
percent = SimpleCov.result.covered_percent
|
28
31
|
unless percent >= COVERAGE_THRESHOLD
|
29
|
-
puts "Coverage must be above #{COVERAGE_THRESHOLD}%. It is #{
|
32
|
+
puts "Coverage must be above #{COVERAGE_THRESHOLD}%. It is #{'%.2f' % percent}%"
|
30
33
|
Kernel.exit(1)
|
31
34
|
end
|
32
35
|
end
|
@@ -36,7 +39,7 @@ require 'test/unit'
|
|
36
39
|
require 'mocha/setup'
|
37
40
|
require 'net/http'
|
38
41
|
|
39
|
-
require File.join(File.dirname(__FILE__),
|
42
|
+
require File.join(File.dirname(__FILE__), '../lib/geokit.rb')
|
40
43
|
|
41
44
|
class MockSuccess < Net::HTTPSuccess #:nodoc: all
|
42
45
|
def initialize
|
@@ -75,7 +78,7 @@ Geokit::Geocoders::Geocoder.class_eval do
|
|
75
78
|
end
|
76
79
|
end
|
77
80
|
|
78
|
-
def assert_array_in_delta(expected_array, actual_array, delta = 0.001, message='')
|
81
|
+
def assert_array_in_delta(expected_array, actual_array, delta = 0.001, message = '')
|
79
82
|
full_message = build_message(message, "<?> and\n<?> expected to be within\n<?> of each other.\n", expected_array, actual_array, delta)
|
80
83
|
assert_block(full_message) do
|
81
84
|
expected_array.zip(actual_array).all?{|expected_item, actual_item|
|
@@ -91,7 +94,7 @@ VCR.configure do |c|
|
|
91
94
|
c.hook_into :webmock # or :fakeweb
|
92
95
|
# Yahoo BOSS Ignore changing params
|
93
96
|
c.default_cassette_options = {
|
94
|
-
:
|
97
|
+
match_requests_on: [:method,
|
95
98
|
VCR.request_matchers.uri_without_params(
|
96
99
|
:oauth_nonce, :oauth_timestamp, :oauth_signature
|
97
100
|
)
|
@@ -101,7 +104,6 @@ end
|
|
101
104
|
|
102
105
|
# Base class for testing geocoders.
|
103
106
|
class BaseGeocoderTest < Test::Unit::TestCase #:nodoc: all
|
104
|
-
|
105
107
|
class Geokit::Geocoders::TestGeocoder < Geokit::Geocoders::Geocoder
|
106
108
|
def self.do_get(url)
|
107
109
|
sleep(2)
|
@@ -110,25 +112,25 @@ class BaseGeocoderTest < Test::Unit::TestCase #:nodoc: all
|
|
110
112
|
|
111
113
|
# Defines common test fixtures.
|
112
114
|
def setup
|
113
|
-
Geokit::Geocoders
|
115
|
+
Geokit::Geocoders.request_timeout = 10
|
114
116
|
@address = 'San Francisco, CA'
|
115
117
|
@full_address = '100 Spear St, San Francisco, CA, 94105-1522, US'
|
116
118
|
@full_address_short_zip = '100 Spear St, San Francisco, CA, 94105, US'
|
117
119
|
|
118
120
|
@latlng = Geokit::LatLng.new(37.7742, -122.417068)
|
119
|
-
@success = Geokit::GeoLoc.new({:
|
121
|
+
@success = Geokit::GeoLoc.new({city: 'SAN FRANCISCO', state: 'CA', country_code: 'US', lat: @latlng.lat, lng: @latlng.lng})
|
120
122
|
@success.success = true
|
121
123
|
end
|
122
124
|
|
123
125
|
def test_timeout_call_web_service
|
124
|
-
url =
|
125
|
-
Geokit::Geocoders
|
126
|
+
url = 'http://www.anything.com'
|
127
|
+
Geokit::Geocoders.request_timeout = 1
|
126
128
|
assert_nil Geokit::Geocoders::TestGeocoder.call_geocoder_service(url)
|
127
129
|
end
|
128
130
|
|
129
131
|
def test_successful_call_web_service
|
130
|
-
url =
|
131
|
-
Geokit::Geocoders::Geocoder.expects(:do_get).with(url).returns(
|
132
|
-
assert_equal
|
132
|
+
url = 'http://www.anything.com'
|
133
|
+
Geokit::Geocoders::Geocoder.expects(:do_get).with(url).returns('SUCCESS')
|
134
|
+
assert_equal 'SUCCESS', Geokit::Geocoders::Geocoder.call_geocoder_service(url)
|
133
135
|
end
|
134
136
|
end
|
data/test/test_base_geocoder.rb
CHANGED
@@ -2,7 +2,6 @@ require File.join(File.dirname(__FILE__), 'helper')
|
|
2
2
|
|
3
3
|
# Base class for testing geocoders.
|
4
4
|
class BaseGeocoderTest < Test::Unit::TestCase #:nodoc: all
|
5
|
-
|
6
5
|
class Geokit::Geocoders::TestGeocoder < Geokit::Geocoders::Geocoder
|
7
6
|
def self.do_get(url)
|
8
7
|
sleep(2)
|
@@ -16,19 +15,19 @@ class BaseGeocoderTest < Test::Unit::TestCase #:nodoc: all
|
|
16
15
|
@full_address_short_zip = '100 Spear St, San Francisco, CA, 94105, US'
|
17
16
|
|
18
17
|
@latlng = Geokit::LatLng.new(37.7742, -122.417068)
|
19
|
-
@success = Geokit::GeoLoc.new({:
|
18
|
+
@success = Geokit::GeoLoc.new({city: 'SAN FRANCISCO', state: 'CA', country_code: 'US', lat: @latlng.lat, lng: @latlng.lng})
|
20
19
|
@success.success = true
|
21
20
|
end
|
22
21
|
|
23
22
|
def test_timeout_call_web_service
|
24
|
-
url =
|
25
|
-
Geokit::Geocoders
|
23
|
+
url = 'http://www.anything.com'
|
24
|
+
Geokit::Geocoders.request_timeout = 1
|
26
25
|
assert_nil Geokit::Geocoders::TestGeocoder.call_geocoder_service(url)
|
27
26
|
end
|
28
27
|
|
29
28
|
def test_successful_call_web_service
|
30
|
-
url =
|
31
|
-
Geokit::Geocoders::Geocoder.expects(:do_get).with(url).returns(
|
32
|
-
assert_equal
|
29
|
+
url = 'http://www.anything.com'
|
30
|
+
Geokit::Geocoders::Geocoder.expects(:do_get).with(url).returns('SUCCESS')
|
31
|
+
assert_equal 'SUCCESS', Geokit::Geocoders::Geocoder.call_geocoder_service(url)
|
33
32
|
end
|
34
33
|
end
|
data/test/test_bing_geocoder.rb
CHANGED
@@ -3,7 +3,6 @@ require File.join(File.dirname(__FILE__), 'helper')
|
|
3
3
|
Geokit::Geocoders::BingGeocoder.key = 'AuWcmtBIoPeOubm9BtcN44hTmWw_wNoJ5NEO2L0RaKrGAUE_nlwciKAqwapdq7k7'
|
4
4
|
|
5
5
|
class BingGeocoderTest < BaseGeocoderTest #:nodoc: all
|
6
|
-
|
7
6
|
def setup
|
8
7
|
super
|
9
8
|
end
|
@@ -15,15 +14,15 @@ class BingGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
15
14
|
# the testing methods themselves
|
16
15
|
def test_bing_full_address
|
17
16
|
VCR.use_cassette('bing_full') do
|
18
|
-
|
17
|
+
key = Geokit::Geocoders::BingGeocoder.key
|
19
18
|
url = "https://dev.virtualearth.net/REST/v1/Locations/#{URI.escape(@full_address)}?key=#{key}&o=xml"
|
20
19
|
res = Geokit::Geocoders::BingGeocoder.geocode(@full_address)
|
21
|
-
assert_equal
|
22
|
-
assert_equal
|
20
|
+
assert_equal 'CA', res.state
|
21
|
+
assert_equal 'San Francisco', res.city
|
23
22
|
assert_array_in_delta [37.792332, -122.393791], res.to_a
|
24
23
|
assert res.country == 'United States'
|
25
|
-
assert_equal
|
26
|
-
assert_equal
|
24
|
+
assert_equal '100 Spear St, San Francisco, CA 94105', res.full_address
|
25
|
+
assert_equal 'bing', res.provider
|
27
26
|
assert_url url
|
28
27
|
end
|
29
28
|
end
|
@@ -31,32 +30,32 @@ class BingGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
31
30
|
def test_bing_full_address_au
|
32
31
|
address = '440 King William Street, Adelaide, Australia'
|
33
32
|
VCR.use_cassette('bing_full_au') do
|
34
|
-
|
33
|
+
key = Geokit::Geocoders::BingGeocoder.key
|
35
34
|
url = "https://dev.virtualearth.net/REST/v1/Locations/#{URI.escape(address)}?key=#{key}&o=xml"
|
36
35
|
res = Geokit::Geocoders::BingGeocoder.geocode(address)
|
37
|
-
assert_equal
|
38
|
-
assert_equal
|
36
|
+
assert_equal 'SA', res.state
|
37
|
+
assert_equal 'Adelaide', res.city
|
39
38
|
assert_array_in_delta [-34.934582, 138.600784], res.to_a
|
40
39
|
assert res.country == 'Australia'
|
41
|
-
assert_equal
|
42
|
-
assert_equal
|
43
|
-
assert_equal
|
40
|
+
assert_equal '402-440 King William St, Adelaide, SA 5000', res.full_address
|
41
|
+
assert_equal 'Australia', res.country
|
42
|
+
assert_equal 'bing', res.provider
|
44
43
|
assert_url url
|
45
44
|
end
|
46
45
|
end
|
47
46
|
|
48
47
|
def test_bing_full_address_de
|
49
|
-
address =
|
48
|
+
address = 'Platz der Republik 1, 11011 Berlin, Germany'
|
50
49
|
VCR.use_cassette('bing_full_de') do
|
51
|
-
|
50
|
+
key = Geokit::Geocoders::BingGeocoder.key
|
52
51
|
url = "https://dev.virtualearth.net/REST/v1/Locations/#{URI.escape(address)}?key=#{key}&o=xml"
|
53
52
|
res = Geokit::Geocoders::BingGeocoder.geocode(address)
|
54
|
-
assert_equal
|
55
|
-
assert_equal
|
53
|
+
assert_equal 'BE', res.state
|
54
|
+
assert_equal 'Berlin', res.city
|
56
55
|
assert_array_in_delta [52.518596, 13.375502], res.to_a
|
57
56
|
assert res.country == 'Germany'
|
58
|
-
assert_equal
|
59
|
-
assert_equal
|
57
|
+
assert_equal 'Platz der Republik 1, 10557 Berlin', res.full_address
|
58
|
+
assert_equal 'bing', res.provider
|
60
59
|
assert_equal 'address', res.precision
|
61
60
|
assert_equal 8, res.accuracy
|
62
61
|
assert_url url
|
@@ -64,9 +63,9 @@ class BingGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
64
63
|
end
|
65
64
|
|
66
65
|
def test_bing_country
|
67
|
-
address =
|
66
|
+
address = 'Australia'
|
68
67
|
VCR.use_cassette('bing_au') do
|
69
|
-
|
68
|
+
key = Geokit::Geocoders::BingGeocoder.key
|
70
69
|
url = "https://dev.virtualearth.net/REST/v1/Locations/#{URI.escape(address)}?key=#{key}&o=xml"
|
71
70
|
res = Geokit::Geocoders::BingGeocoder.geocode(address)
|
72
71
|
assert_equal nil, res.state
|
@@ -74,7 +73,7 @@ class BingGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
74
73
|
assert_array_in_delta [-25.585, 134.504], res.to_a
|
75
74
|
assert res.country == 'Australia'
|
76
75
|
assert_equal 'Australia', res.full_address
|
77
|
-
assert_equal
|
76
|
+
assert_equal 'bing', res.provider
|
78
77
|
assert_equal 'country', res.precision
|
79
78
|
assert_equal 8, res.accuracy
|
80
79
|
assert_url url
|
data/test/test_bounds.rb
CHANGED
@@ -1,37 +1,35 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'helper')
|
2
2
|
|
3
3
|
class BoundsTest < Test::Unit::TestCase #:nodoc: all
|
4
|
-
|
5
4
|
def setup
|
6
5
|
# This is the area in Texas
|
7
|
-
@sw = Geokit::LatLng.new(32.91663
|
8
|
-
@ne = Geokit::LatLng.new(32.96302
|
9
|
-
@bounds=Geokit::Bounds.new(@sw
|
10
|
-
@loc_a=Geokit::LatLng.new(32.918593
|
11
|
-
@loc_b=Geokit::LatLng.new(32.914144
|
6
|
+
@sw = Geokit::LatLng.new(32.91663, -96.982841)
|
7
|
+
@ne = Geokit::LatLng.new(32.96302, -96.919495)
|
8
|
+
@bounds = Geokit::Bounds.new(@sw, @ne)
|
9
|
+
@loc_a = Geokit::LatLng.new(32.918593, -96.958444) # inside bounds
|
10
|
+
@loc_b = Geokit::LatLng.new(32.914144, -96.958444) # outside bouds
|
12
11
|
|
13
12
|
# this is a cross-meridan area
|
14
|
-
@cross_meridian=Geokit::Bounds.normalize([30,170],[40
|
15
|
-
@inside_cm=Geokit::LatLng.new(35,175)
|
16
|
-
@inside_cm_2=Geokit::LatLng.new(35
|
17
|
-
@east_of_cm=Geokit::LatLng.new(35
|
18
|
-
@west_of_cm=Geokit::LatLng.new(35,165)
|
19
|
-
|
13
|
+
@cross_meridian = Geokit::Bounds.normalize([30, 170], [40, -170])
|
14
|
+
@inside_cm = Geokit::LatLng.new(35, 175)
|
15
|
+
@inside_cm_2 = Geokit::LatLng.new(35, -175)
|
16
|
+
@east_of_cm = Geokit::LatLng.new(35, -165)
|
17
|
+
@west_of_cm = Geokit::LatLng.new(35, 165)
|
20
18
|
end
|
21
19
|
|
22
20
|
def test_equality
|
23
|
-
assert_equal Geokit::Bounds.new(@sw
|
21
|
+
assert_equal Geokit::Bounds.new(@sw, @ne), Geokit::Bounds.new(@sw, @ne)
|
24
22
|
end
|
25
23
|
|
26
24
|
def test_normalize
|
27
|
-
res=Geokit::Bounds.normalize(@sw
|
28
|
-
assert_equal res,Geokit::Bounds.new(@sw
|
29
|
-
res=Geokit::Bounds.normalize([@sw
|
30
|
-
assert_equal res,Geokit::Bounds.new(@sw
|
31
|
-
res=Geokit::Bounds.normalize([@sw.lat
|
32
|
-
assert_equal res,Geokit::Bounds.new(@sw
|
33
|
-
res=Geokit::Bounds.normalize([[@sw.lat
|
34
|
-
assert_equal res,Geokit::Bounds.new(@sw
|
25
|
+
res = Geokit::Bounds.normalize(@sw, @ne)
|
26
|
+
assert_equal res, Geokit::Bounds.new(@sw, @ne)
|
27
|
+
res = Geokit::Bounds.normalize([@sw, @ne])
|
28
|
+
assert_equal res, Geokit::Bounds.new(@sw, @ne)
|
29
|
+
res = Geokit::Bounds.normalize([@sw.lat, @sw.lng], [@ne.lat, @ne.lng])
|
30
|
+
assert_equal res, Geokit::Bounds.new(@sw, @ne)
|
31
|
+
res = Geokit::Bounds.normalize([[@sw.lat, @sw.lng], [@ne.lat, @ne.lng]])
|
32
|
+
assert_equal res, Geokit::Bounds.new(@sw, @ne)
|
35
33
|
end
|
36
34
|
|
37
35
|
def test_point_inside_bounds
|
@@ -53,19 +51,19 @@ class BoundsTest < Test::Unit::TestCase #:nodoc: all
|
|
53
51
|
end
|
54
52
|
|
55
53
|
def test_center
|
56
|
-
assert_in_delta 32.939828
|
57
|
-
assert_in_delta(-96.9511763
|
54
|
+
assert_in_delta 32.939828, @bounds.center.lat, 0.00005
|
55
|
+
assert_in_delta(-96.9511763, @bounds.center.lng, 0.00005)
|
58
56
|
end
|
59
57
|
|
60
58
|
def test_center_cross_meridian
|
61
|
-
assert_in_delta 35.41160, @cross_meridian.center.lat,0.00005
|
62
|
-
assert_in_delta 179.38112, @cross_meridian.center.lng,0.00005
|
59
|
+
assert_in_delta 35.41160, @cross_meridian.center.lat, 0.00005
|
60
|
+
assert_in_delta 179.38112, @cross_meridian.center.lng, 0.00005
|
63
61
|
end
|
64
62
|
|
65
63
|
def test_creation_from_circle
|
66
|
-
bounds=Geokit::Bounds.from_point_and_radius([32.939829, -96.951176],2.5)
|
67
|
-
inside=Geokit::LatLng.new 32.9695270000
|
68
|
-
outside=Geokit::LatLng.new 32.8951550000
|
64
|
+
bounds = Geokit::Bounds.from_point_and_radius([32.939829, -96.951176], 2.5)
|
65
|
+
inside = Geokit::LatLng.new 32.9695270000, -96.9901590000
|
66
|
+
outside = Geokit::LatLng.new 32.8951550000, -96.9584440000
|
69
67
|
assert bounds.contains?(inside)
|
70
68
|
assert !bounds.contains?(outside)
|
71
69
|
end
|
data/test/test_ca_geocoder.rb
CHANGED
@@ -1,31 +1,30 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'helper')
|
2
2
|
|
3
|
-
Geokit::Geocoders::CaGeocoder
|
3
|
+
Geokit::Geocoders::CaGeocoder.key = 'SOMEKEYVALUE'
|
4
4
|
|
5
5
|
class CaGeocoderTest < BaseGeocoderTest #:nodoc: all
|
6
|
-
|
7
|
-
CA_SUCCESS=<<-EOF
|
6
|
+
CA_SUCCESS = <<-EOF
|
8
7
|
<?xml version="1.0" encoding="UTF-8" ?>
|
9
8
|
<geodata><latt>49.243086</latt><longt>-123.153684</longt></geodata>
|
10
9
|
EOF
|
11
10
|
|
12
11
|
def setup
|
13
|
-
@ca_full_hash = {:
|
12
|
+
@ca_full_hash = {street_address: '2105 West 32nd Avenue', city: 'Vancouver', state: 'BC'}
|
14
13
|
@ca_full_loc = Geokit::GeoLoc.new(@ca_full_hash)
|
15
14
|
end
|
16
15
|
|
17
16
|
def test_geocoder_with_geo_loc_with_account
|
18
17
|
response = MockSuccess.new
|
19
18
|
response.expects(:body).returns(CA_SUCCESS)
|
20
|
-
url =
|
19
|
+
url = 'http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml'
|
21
20
|
Geokit::Geocoders::CaGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
22
21
|
verify(Geokit::Geocoders::CaGeocoder.geocode(@ca_full_loc))
|
23
22
|
end
|
24
23
|
|
25
24
|
def test_service_unavailable
|
26
25
|
response = MockFailure.new
|
27
|
-
#Net::HTTP.expects(:get_response).with(URI.parse("http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml")).returns(response)
|
28
|
-
url =
|
26
|
+
# Net::HTTP.expects(:get_response).with(URI.parse("http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml")).returns(response)
|
27
|
+
url = 'http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml'
|
29
28
|
Geokit::Geocoders::CaGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
30
29
|
assert !Geokit::Geocoders::CaGeocoder.geocode(@ca_full_loc).success
|
31
30
|
end
|
@@ -33,9 +32,9 @@ class CaGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
33
32
|
private
|
34
33
|
|
35
34
|
def verify(location)
|
36
|
-
assert_equal
|
37
|
-
assert_equal
|
38
|
-
assert_equal
|
35
|
+
assert_equal 'BC', location.state
|
36
|
+
assert_equal 'Vancouver', location.city
|
37
|
+
assert_equal '49.243086,-123.153684', location.ll
|
39
38
|
assert !location.is_us?
|
40
39
|
end
|
41
40
|
end
|
data/test/test_fcc_geocoder.rb
CHANGED
@@ -12,7 +12,7 @@ class FCCGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
12
12
|
|
13
13
|
def test_fcc_reverse_geocode
|
14
14
|
VCR.use_cassette('fcc_reverse_geocode') do
|
15
|
-
|
15
|
+
url = 'https://data.fcc.gov/api/block/find?format=json&latitude=34.05&longitude=-118.25'
|
16
16
|
res = Geokit::Geocoders::FCCGeocoder.reverse_geocode(@la)
|
17
17
|
assert_url url
|
18
18
|
assert_equal res.country_code, 'US'
|
@@ -12,7 +12,7 @@ class FreeGeoIpGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
12
12
|
|
13
13
|
def test_free_geo_ip_geocode
|
14
14
|
VCR.use_cassette('free_geo_ip_geocode') do
|
15
|
-
|
15
|
+
url = "http://freegeoip.net/xml/#{@ip}"
|
16
16
|
res = Geokit::Geocoders::FreeGeoIpGeocoder.geocode(@ip)
|
17
17
|
assert_url url
|
18
18
|
assert_equal res.city, 'Mountain View'
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'helper')
|
2
2
|
|
3
3
|
class GeoPluginGeocoderTest < BaseGeocoderTest #:nodoc: all
|
4
|
-
IP_SUCCESS
|
4
|
+
IP_SUCCESS = <<-EOF
|
5
5
|
<?xml version="1.0" encoding="UTF-8"?>
|
6
6
|
<geoPlugin>
|
7
7
|
<geoplugin_city>Belo Horizonte</geoplugin_city>
|
@@ -22,7 +22,7 @@ class GeoPluginGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
22
22
|
def setup
|
23
23
|
super
|
24
24
|
@ip = '74.125.237.209'
|
25
|
-
@success.provider =
|
25
|
+
@success.provider = 'geo_plugin'
|
26
26
|
end
|
27
27
|
|
28
28
|
def assert_url(expected_url)
|
@@ -31,7 +31,7 @@ class GeoPluginGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
31
31
|
|
32
32
|
def test_geo_plugin_geocode
|
33
33
|
VCR.use_cassette('geo_plugin_geocode') do
|
34
|
-
|
34
|
+
url = "http://www.geoplugin.net/xml.gp?ip=#{@ip}"
|
35
35
|
res = Geokit::Geocoders::GeoPluginGeocoder.geocode(@ip)
|
36
36
|
assert_url url
|
37
37
|
assert_equal res.city, 'Mountain View'
|
@@ -49,15 +49,15 @@ class GeoPluginGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
49
49
|
assert_not_nil location
|
50
50
|
assert_equal(-19.916700, location.lat)
|
51
51
|
assert_equal(-43.933300, location.lng)
|
52
|
-
assert_equal
|
53
|
-
assert_equal
|
54
|
-
assert_equal
|
55
|
-
assert_equal
|
52
|
+
assert_equal 'Belo Horizonte', location.city
|
53
|
+
assert_equal 'Minas Gerais', location.state
|
54
|
+
assert_equal 'BR', location.country_code
|
55
|
+
assert_equal 'geo_plugin', location.provider
|
56
56
|
assert location.success?
|
57
57
|
end
|
58
58
|
|
59
59
|
def test_invalid_ip
|
60
|
-
location = Geokit::Geocoders::GeoPluginGeocoder.geocode(
|
60
|
+
location = Geokit::Geocoders::GeoPluginGeocoder.geocode('pixrum')
|
61
61
|
assert_not_nil location
|
62
62
|
assert !location.success?
|
63
63
|
end
|
@@ -66,7 +66,7 @@ class GeoPluginGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
66
66
|
failure = MockFailure.new
|
67
67
|
url = 'http://www.geoplugin.net/xml.gp?ip=69.10.10.10'
|
68
68
|
Geokit::Geocoders::GeoPluginGeocoder.expects(:call_geocoder_service).with(url).returns(failure)
|
69
|
-
location = Geokit::Geocoders::GeoPluginGeocoder.geocode(
|
69
|
+
location = Geokit::Geocoders::GeoPluginGeocoder.geocode('69.10.10.10')
|
70
70
|
assert_not_nil location
|
71
71
|
assert !location.success?
|
72
72
|
end
|
data/test/test_geoloc.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'helper')
|
2
2
|
|
3
3
|
class GeoLocTest < Test::Unit::TestCase #:nodoc: all
|
4
|
-
|
5
4
|
def setup
|
6
5
|
@loc = Geokit::GeoLoc.new
|
7
6
|
end
|
@@ -31,7 +30,7 @@ class GeoLocTest < Test::Unit::TestCase #:nodoc: all
|
|
31
30
|
end
|
32
31
|
|
33
32
|
def test_city
|
34
|
-
@loc.city =
|
33
|
+
@loc.city = 'san francisco'
|
35
34
|
assert_equal 'San Francisco', @loc.city
|
36
35
|
end
|
37
36
|
|
@@ -60,11 +59,11 @@ class GeoLocTest < Test::Unit::TestCase #:nodoc: all
|
|
60
59
|
|
61
60
|
def test_to_yaml
|
62
61
|
@loc.city = 'San Francisco'
|
63
|
-
@loc.
|
62
|
+
@loc.state_code = 'CA'
|
64
63
|
@loc.zip = '94105'
|
65
64
|
@loc.country_code = 'US'
|
66
65
|
|
67
|
-
yaml = YAML
|
66
|
+
yaml = YAML.parse(@loc.to_yaml)
|
68
67
|
case yaml.class.to_s
|
69
68
|
when 'YAML::Syck::Map', 'Syck::Map'
|
70
69
|
tag = yaml.type_id
|
@@ -85,7 +84,9 @@ class GeoLocTest < Test::Unit::TestCase #:nodoc: all
|
|
85
84
|
'lng', '',
|
86
85
|
'precision', 'unknown',
|
87
86
|
'province', '',
|
88
|
-
'state', '
|
87
|
+
'state', '',
|
88
|
+
'state_code', 'CA',
|
89
|
+
'state_name', '',
|
89
90
|
'street_address', '',
|
90
91
|
'street_name', '',
|
91
92
|
'street_number', '',
|
@@ -96,7 +97,7 @@ class GeoLocTest < Test::Unit::TestCase #:nodoc: all
|
|
96
97
|
end
|
97
98
|
|
98
99
|
def test_neighborhood
|
99
|
-
@loc.neighborhood =
|
100
|
+
@loc.neighborhood = 'SoMa'
|
100
101
|
assert_equal @loc.neighborhood, 'SoMa'
|
101
102
|
end
|
102
103
|
end
|