soey-geokit 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +19 -0
- data/README.markdown +166 -0
- data/Rakefile +20 -0
- data/lib/geokit/geocoders.rb +549 -0
- data/lib/geokit/mappable.rb +459 -0
- data/lib/geokit.rb +28 -0
- data/test/test_base_geocoder.rb +56 -0
- data/test/test_bounds.rb +74 -0
- data/test/test_ca_geocoder.rb +41 -0
- data/test/test_geoloc.rb +49 -0
- data/test/test_google_geocoder.rb +88 -0
- data/test/test_latlng.rb +132 -0
- data/test/test_multi_geocoder.rb +44 -0
- data/test/test_us_geocoder.rb +47 -0
- data/test/test_yahoo_geocoder.rb +87 -0
- metadata +78 -0
data/test/test_geoloc.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'lib/geokit'
|
3
|
+
|
4
|
+
class GeoLocTest < Test::Unit::TestCase #:nodoc: all
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@loc = Geokit::GeoLoc.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_is_us
|
11
|
+
assert !@loc.is_us?
|
12
|
+
@loc.country_code = 'US'
|
13
|
+
assert @loc.is_us?
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_street_number
|
17
|
+
@loc.street_address = '123 Spear St.'
|
18
|
+
assert_equal '123', @loc.street_number
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_street_name
|
22
|
+
@loc.street_address = '123 Spear St.'
|
23
|
+
assert_equal 'Spear St.', @loc.street_name
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_city
|
27
|
+
@loc.city = "san francisco"
|
28
|
+
assert_equal 'San Francisco', @loc.city
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_full_address
|
32
|
+
@loc.city = 'San Francisco'
|
33
|
+
@loc.state = 'CA'
|
34
|
+
@loc.zip = '94105'
|
35
|
+
@loc.country_code = 'US'
|
36
|
+
assert_equal 'San Francisco, CA, 94105, US', @loc.full_address
|
37
|
+
@loc.full_address = 'Irving, TX, 75063, US'
|
38
|
+
assert_equal 'Irving, TX, 75063, US', @loc.full_address
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_hash
|
42
|
+
@loc.city = 'San Francisco'
|
43
|
+
@loc.state = 'CA'
|
44
|
+
@loc.zip = '94105'
|
45
|
+
@loc.country_code = 'US'
|
46
|
+
@another = Geokit::GeoLoc.new @loc.to_hash
|
47
|
+
assert_equal @loc, @another
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_base_geocoder')
|
2
|
+
|
3
|
+
Geokit::Geocoders::google = 'Google'
|
4
|
+
|
5
|
+
class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
6
|
+
|
7
|
+
GOOGLE_FULL=<<-EOF.strip
|
8
|
+
<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.0"><Response><name>100 spear st, san francisco, ca</name><Status><code>200</code><request>geocode</request></Status><Placemark><address>100 Spear St, San Francisco, CA 94105, USA</address><AddressDetails Accuracy="8" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><AdministrativeArea><AdministrativeAreaName>CA</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>San Francisco</SubAdministrativeAreaName><Locality><LocalityName>San Francisco</LocalityName><Thoroughfare><ThoroughfareName>100 Spear St</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>94105</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails><Point><coordinates>-122.393985,37.792501,0</coordinates></Point></Placemark></Response></kml>
|
9
|
+
EOF
|
10
|
+
|
11
|
+
GOOGLE_CITY=<<-EOF.strip
|
12
|
+
<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.0"><Response><name>San Francisco</name><Status><code>200</code><request>geocode</request></Status><Placemark><address>San Francisco, CA, USA</address><AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><AdministrativeArea><AdministrativeAreaName>CA</AdministrativeAreaName><Locality><LocalityName>San Francisco</LocalityName></Locality></AdministrativeArea></Country></AddressDetails><Point><coordinates>-122.418333,37.775000,0</coordinates></Point></Placemark></Response></kml>
|
13
|
+
EOF
|
14
|
+
|
15
|
+
def setup
|
16
|
+
super
|
17
|
+
@google_full_hash = {:street_address=>"100 Spear St", :city=>"San Francisco", :state=>"CA", :zip=>"94105", :country_code=>"US"}
|
18
|
+
@google_city_hash = {:city=>"San Francisco", :state=>"CA"}
|
19
|
+
|
20
|
+
@google_full_loc = Geokit::GeoLoc.new(@google_full_hash)
|
21
|
+
@google_city_loc = Geokit::GeoLoc.new(@google_city_hash)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_google_full_address
|
25
|
+
response = MockSuccess.new
|
26
|
+
response.expects(:body).returns(GOOGLE_FULL)
|
27
|
+
url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape(@address)}&output=xml&key=Google&oe=utf-8"
|
28
|
+
Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
29
|
+
res=Geokit::Geocoders::GoogleGeocoder.geocode(@address)
|
30
|
+
assert_equal "CA", res.state
|
31
|
+
assert_equal "San Francisco", res.city
|
32
|
+
assert_equal "37.792501,-122.393985", res.ll # slightly dif from yahoo
|
33
|
+
assert res.is_us?
|
34
|
+
assert_equal "100 Spear St, San Francisco, CA 94105, USA", res.full_address #slightly different from yahoo
|
35
|
+
assert_equal "google", res.provider
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_google_full_address_with_geo_loc
|
39
|
+
response = MockSuccess.new
|
40
|
+
response.expects(:body).returns(GOOGLE_FULL)
|
41
|
+
url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape(@full_address_short_zip)}&output=xml&key=Google&oe=utf-8"
|
42
|
+
Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
43
|
+
res=Geokit::Geocoders::GoogleGeocoder.geocode(@google_full_loc)
|
44
|
+
assert_equal "CA", res.state
|
45
|
+
assert_equal "San Francisco", res.city
|
46
|
+
assert_equal "37.792501,-122.393985", res.ll # slightly dif from yahoo
|
47
|
+
assert res.is_us?
|
48
|
+
assert_equal "100 Spear St, San Francisco, CA 94105, USA", res.full_address #slightly different from yahoo
|
49
|
+
assert_equal "google", res.provider
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_google_city
|
53
|
+
response = MockSuccess.new
|
54
|
+
response.expects(:body).returns(GOOGLE_CITY)
|
55
|
+
url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape(@address)}&output=xml&key=Google&oe=utf-8"
|
56
|
+
Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
57
|
+
res=Geokit::Geocoders::GoogleGeocoder.geocode(@address)
|
58
|
+
assert_equal "CA", res.state
|
59
|
+
assert_equal "San Francisco", res.city
|
60
|
+
assert_equal "37.775,-122.418333", res.ll
|
61
|
+
assert res.is_us?
|
62
|
+
assert_equal "San Francisco, CA, USA", res.full_address
|
63
|
+
assert_nil res.street_address
|
64
|
+
assert_equal "google", res.provider
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_google_city_with_geo_loc
|
68
|
+
response = MockSuccess.new
|
69
|
+
response.expects(:body).returns(GOOGLE_CITY)
|
70
|
+
url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape(@address)}&output=xml&key=Google&oe=utf-8"
|
71
|
+
Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
72
|
+
res=Geokit::Geocoders::GoogleGeocoder.geocode(@google_city_loc)
|
73
|
+
assert_equal "CA", res.state
|
74
|
+
assert_equal "San Francisco", res.city
|
75
|
+
assert_equal "37.775,-122.418333", res.ll
|
76
|
+
assert res.is_us?
|
77
|
+
assert_equal "San Francisco, CA, USA", res.full_address
|
78
|
+
assert_nil res.street_address
|
79
|
+
assert_equal "google", res.provider
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_service_unavailable
|
83
|
+
response = MockFailure.new
|
84
|
+
url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape(@address)}&output=xml&key=Google&oe=utf-8"
|
85
|
+
Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
86
|
+
assert !Geokit::Geocoders::GoogleGeocoder.geocode(@google_city_loc).success
|
87
|
+
end
|
88
|
+
end
|
data/test/test_latlng.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'lib/geokit'
|
3
|
+
|
4
|
+
class LatLngTest < Test::Unit::TestCase #:nodoc: all
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@loc_a = Geokit::LatLng.new(32.918593,-96.958444)
|
8
|
+
@loc_e = Geokit::LatLng.new(32.969527,-96.990159)
|
9
|
+
@point = Geokit::LatLng.new(@loc_a.lat, @loc_a.lng)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_distance_between_same_using_defaults
|
13
|
+
assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a)
|
14
|
+
assert_equal 0, @loc_a.distance_to(@loc_a)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_distance_between_same_with_miles_and_flat
|
18
|
+
assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :miles, :formula => :flat)
|
19
|
+
assert_equal 0, @loc_a.distance_to(@loc_a, :units => :miles, :formula => :flat)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_distance_between_same_with_kms_and_flat
|
23
|
+
assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :kms, :formula => :flat)
|
24
|
+
assert_equal 0, @loc_a.distance_to(@loc_a, :units => :kms, :formula => :flat)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_distance_between_same_with_nms_and_flat
|
28
|
+
assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :nms, :formula => :flat)
|
29
|
+
assert_equal 0, @loc_a.distance_to(@loc_a, :units => :nms, :formula => :flat)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_distance_between_same_with_miles_and_sphere
|
33
|
+
assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :miles, :formula => :sphere)
|
34
|
+
assert_equal 0, @loc_a.distance_to(@loc_a, :units => :miles, :formula => :sphere)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_distance_between_same_with_kms_and_sphere
|
38
|
+
assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :kms, :formula => :sphere)
|
39
|
+
assert_equal 0, @loc_a.distance_to(@loc_a, :units => :kms, :formula => :sphere)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_distance_between_same_with_nms_and_sphere
|
43
|
+
assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :nms, :formula => :sphere)
|
44
|
+
assert_equal 0, @loc_a.distance_to(@loc_a, :units => :nms, :formula => :sphere)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_distance_between_diff_using_defaults
|
48
|
+
assert_in_delta 3.97, Geokit::LatLng.distance_between(@loc_a, @loc_e), 0.01
|
49
|
+
assert_in_delta 3.97, @loc_a.distance_to(@loc_e), 0.01
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_distance_between_diff_with_miles_and_flat
|
53
|
+
assert_in_delta 3.97, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :miles, :formula => :flat), 0.2
|
54
|
+
assert_in_delta 3.97, @loc_a.distance_to(@loc_e, :units => :miles, :formula => :flat), 0.2
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_distance_between_diff_with_kms_and_flat
|
58
|
+
assert_in_delta 6.39, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :kms, :formula => :flat), 0.4
|
59
|
+
assert_in_delta 6.39, @loc_a.distance_to(@loc_e, :units => :kms, :formula => :flat), 0.4
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_distance_between_diff_with_nms_and_flat
|
63
|
+
assert_in_delta 3.334, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :nms, :formula => :flat), 0.4
|
64
|
+
assert_in_delta 3.334, @loc_a.distance_to(@loc_e, :units => :nms, :formula => :flat), 0.4
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_distance_between_diff_with_miles_and_sphere
|
68
|
+
assert_in_delta 3.97, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :miles, :formula => :sphere), 0.01
|
69
|
+
assert_in_delta 3.97, @loc_a.distance_to(@loc_e, :units => :miles, :formula => :sphere), 0.01
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_distance_between_diff_with_kms_and_sphere
|
73
|
+
assert_in_delta 6.39, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :kms, :formula => :sphere), 0.01
|
74
|
+
assert_in_delta 6.39, @loc_a.distance_to(@loc_e, :units => :kms, :formula => :sphere), 0.01
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_distance_between_diff_with_nms_and_sphere
|
78
|
+
assert_in_delta 3.454, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :nms, :formula => :sphere), 0.01
|
79
|
+
assert_in_delta 3.454, @loc_a.distance_to(@loc_e, :units => :nms, :formula => :sphere), 0.01
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_manually_mixed_in
|
83
|
+
assert_equal 0, Geokit::LatLng.distance_between(@point, @point)
|
84
|
+
assert_equal 0, @point.distance_to(@point)
|
85
|
+
assert_equal 0, @point.distance_to(@loc_a)
|
86
|
+
assert_in_delta 3.97, @point.distance_to(@loc_e, :units => :miles, :formula => :flat), 0.2
|
87
|
+
assert_in_delta 6.39, @point.distance_to(@loc_e, :units => :kms, :formula => :flat), 0.4
|
88
|
+
assert_in_delta 3.334, @point.distance_to(@loc_e, :units => :nms, :formula => :flat), 0.4
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_heading_between
|
92
|
+
assert_in_delta 332, Geokit::LatLng.heading_between(@loc_a,@loc_e), 0.5
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_heading_to
|
96
|
+
assert_in_delta 332, @loc_a.heading_to(@loc_e), 0.5
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_class_endpoint
|
100
|
+
endpoint=Geokit::LatLng.endpoint(@loc_a, 332, 3.97)
|
101
|
+
assert_in_delta @loc_e.lat, endpoint.lat, 0.0005
|
102
|
+
assert_in_delta @loc_e.lng, endpoint.lng, 0.0005
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_instance_endpoint
|
106
|
+
endpoint=@loc_a.endpoint(332, 3.97)
|
107
|
+
assert_in_delta @loc_e.lat, endpoint.lat, 0.0005
|
108
|
+
assert_in_delta @loc_e.lng, endpoint.lng, 0.0005
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_midpoint
|
112
|
+
midpoint=@loc_a.midpoint_to(@loc_e)
|
113
|
+
assert_in_delta 32.944061, midpoint.lat, 0.0005
|
114
|
+
assert_in_delta(-96.974296, midpoint.lng, 0.0005)
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_normalize
|
118
|
+
lat=37.7690
|
119
|
+
lng=-122.443
|
120
|
+
res=Geokit::LatLng.normalize(lat,lng)
|
121
|
+
assert_equal res,Geokit::LatLng.new(lat,lng)
|
122
|
+
res=Geokit::LatLng.normalize("#{lat}, #{lng}")
|
123
|
+
assert_equal res,Geokit::LatLng.new(lat,lng)
|
124
|
+
res=Geokit::LatLng.normalize("#{lat} #{lng}")
|
125
|
+
assert_equal res,Geokit::LatLng.new(lat,lng)
|
126
|
+
res=Geokit::LatLng.normalize("#{lat.to_i} #{lng.to_i}")
|
127
|
+
assert_equal res,Geokit::LatLng.new(lat.to_i,lng.to_i)
|
128
|
+
res=Geokit::LatLng.normalize([lat,lng])
|
129
|
+
assert_equal res,Geokit::LatLng.new(lat,lng)
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_base_geocoder')
|
2
|
+
|
3
|
+
Geokit::Geocoders::provider_order=[:google,:yahoo,:us]
|
4
|
+
|
5
|
+
class MultiGeocoderTest < BaseGeocoderTest #:nodoc: all
|
6
|
+
|
7
|
+
def setup
|
8
|
+
super
|
9
|
+
@failure = Geokit::GeoLoc.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_successful_first
|
13
|
+
Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address).returns(@success)
|
14
|
+
assert_equal @success, Geokit::Geocoders::MultiGeocoder.geocode(@address)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_failover
|
18
|
+
Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address).returns(@failure)
|
19
|
+
Geokit::Geocoders::YahooGeocoder.expects(:geocode).with(@address).returns(@success)
|
20
|
+
assert_equal @success, Geokit::Geocoders::MultiGeocoder.geocode(@address)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_double_failover
|
24
|
+
Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address).returns(@failure)
|
25
|
+
Geokit::Geocoders::YahooGeocoder.expects(:geocode).with(@address).returns(@failure)
|
26
|
+
Geokit::Geocoders::UsGeocoder.expects(:geocode).with(@address).returns(@success)
|
27
|
+
assert_equal @success, Geokit::Geocoders::MultiGeocoder.geocode(@address)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_failure
|
31
|
+
Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address).returns(@failure)
|
32
|
+
Geokit::Geocoders::YahooGeocoder.expects(:geocode).with(@address).returns(@failure)
|
33
|
+
Geokit::Geocoders::UsGeocoder.expects(:geocode).with(@address).returns(@failure)
|
34
|
+
assert_equal @failure, Geokit::Geocoders::MultiGeocoder.geocode(@address)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_invalid_provider
|
38
|
+
temp = Geokit::Geocoders::provider_order
|
39
|
+
Geokit::Geocoders.provider_order = [:bogus]
|
40
|
+
assert_equal @failure, Geokit::Geocoders::MultiGeocoder.geocode(@address)
|
41
|
+
Geokit::Geocoders.provider_order = temp
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_base_geocoder')
|
2
|
+
|
3
|
+
Geokit::Geocoders::geocoder_us = nil
|
4
|
+
|
5
|
+
class UsGeocoderTest < BaseGeocoderTest #:nodoc: all
|
6
|
+
|
7
|
+
GEOCODER_US_FULL='37.792528,-122.393981,100 Spear St,San Francisco,CA,94105'
|
8
|
+
|
9
|
+
def setup
|
10
|
+
super
|
11
|
+
@us_full_hash = {:city=>"San Francisco", :state=>"CA"}
|
12
|
+
@us_full_loc = Geokit::GeoLoc.new(@us_full_hash)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_geocoder_us
|
16
|
+
response = MockSuccess.new
|
17
|
+
response.expects(:body).returns(GEOCODER_US_FULL)
|
18
|
+
url = "http://geocoder.us/service/csv/geocode?address=#{Geokit::Inflector.url_escape(@address)}"
|
19
|
+
Geokit::Geocoders::UsGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
20
|
+
verify(Geokit::Geocoders::UsGeocoder.geocode(@address))
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_geocoder_with_geo_loc
|
24
|
+
response = MockSuccess.new
|
25
|
+
response.expects(:body).returns(GEOCODER_US_FULL)
|
26
|
+
url = "http://geocoder.us/service/csv/geocode?address=#{Geokit::Inflector.url_escape(@address)}"
|
27
|
+
Geokit::Geocoders::UsGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
28
|
+
verify(Geokit::Geocoders::UsGeocoder.geocode(@us_full_loc))
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_service_unavailable
|
32
|
+
response = MockFailure.new
|
33
|
+
url = "http://geocoder.us/service/csv/geocode?address=#{Geokit::Inflector.url_escape(@address)}"
|
34
|
+
Geokit::Geocoders::UsGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
35
|
+
assert !Geokit::Geocoders::UsGeocoder.geocode(@us_full_loc).success
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def verify(location)
|
41
|
+
assert_equal "CA", location.state
|
42
|
+
assert_equal "San Francisco", location.city
|
43
|
+
assert_equal "37.792528,-122.393981", location.ll
|
44
|
+
assert location.is_us?
|
45
|
+
assert_equal "100 Spear St, San Francisco, CA, 94105, US", location.full_address #slightly different from yahoo
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_base_geocoder')
|
2
|
+
|
3
|
+
Geokit::Geocoders::yahoo = 'Yahoo'
|
4
|
+
|
5
|
+
class YahooGeocoderTest < BaseGeocoderTest #:nodoc: all
|
6
|
+
YAHOO_FULL=<<-EOF.strip
|
7
|
+
<?xml version="1.0"?>
|
8
|
+
<ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:yahoo:maps" xsi:schemaLocation="urn:yahoo:maps http://api.local.yahoo.com/MapsService/V1/GeocodeResponse.xsd"><Result precision="address"><Latitude>37.792406</Latitude><Longitude>-122.39411</Longitude><Address>100 SPEAR ST</Address><City>SAN FRANCISCO</City><State>CA</State><Zip>94105-1522</Zip><Country>US</Country></Result></ResultSet>
|
9
|
+
<!-- ws01.search.scd.yahoo.com uncompressed/chunked Mon Jan 29 16:23:43 PST 2007 -->
|
10
|
+
EOF
|
11
|
+
|
12
|
+
YAHOO_CITY=<<-EOF.strip
|
13
|
+
<?xml version="1.0"?>
|
14
|
+
<ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:yahoo:maps" xsi:schemaLocation="urn:yahoo:maps http://api.local.yahoo.com/MapsService/V1/GeocodeResponse.xsd"><Result precision="city"><Latitude>37.7742</Latitude><Longitude>-122.417068</Longitude><Address></Address><City>SAN FRANCISCO</City><State>CA</State><Zip></Zip><Country>US</Country></Result></ResultSet>
|
15
|
+
<!-- ws02.search.scd.yahoo.com uncompressed/chunked Mon Jan 29 18:00:28 PST 2007 -->
|
16
|
+
EOF
|
17
|
+
|
18
|
+
def setup
|
19
|
+
super
|
20
|
+
@yahoo_full_hash = {:street_address=>"100 Spear St", :city=>"San Francisco", :state=>"CA", :zip=>"94105-1522", :country_code=>"US"}
|
21
|
+
@yahoo_city_hash = {:city=>"San Francisco", :state=>"CA"}
|
22
|
+
@yahoo_full_loc = Geokit::GeoLoc.new(@yahoo_full_hash)
|
23
|
+
@yahoo_city_loc = Geokit::GeoLoc.new(@yahoo_city_hash)
|
24
|
+
end
|
25
|
+
|
26
|
+
# the testing methods themselves
|
27
|
+
def test_yahoo_full_address
|
28
|
+
response = MockSuccess.new
|
29
|
+
response.expects(:body).returns(YAHOO_FULL)
|
30
|
+
url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{Geokit::Inflector.url_escape(@address)}"
|
31
|
+
Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
32
|
+
do_full_address_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@address))
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_yahoo_full_address_with_geo_loc
|
36
|
+
response = MockSuccess.new
|
37
|
+
response.expects(:body).returns(YAHOO_FULL)
|
38
|
+
url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{Geokit::Inflector.url_escape(@full_address)}"
|
39
|
+
Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
40
|
+
do_full_address_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@yahoo_full_loc))
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_yahoo_city
|
44
|
+
response = MockSuccess.new
|
45
|
+
response.expects(:body).returns(YAHOO_CITY)
|
46
|
+
url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{Geokit::Inflector.url_escape(@address)}"
|
47
|
+
Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
48
|
+
do_city_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@address))
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_yahoo_city_with_geo_loc
|
52
|
+
response = MockSuccess.new
|
53
|
+
response.expects(:body).returns(YAHOO_CITY)
|
54
|
+
url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{Geokit::Inflector.url_escape(@address)}"
|
55
|
+
Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
56
|
+
do_city_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@yahoo_city_loc))
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_service_unavailable
|
60
|
+
response = MockFailure.new
|
61
|
+
url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{Geokit::Inflector.url_escape(@address)}"
|
62
|
+
Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
63
|
+
assert !Geokit::Geocoders::YahooGeocoder.geocode(@yahoo_city_loc).success
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
# next two methods do the assertions for both address-level and city-level lookups
|
69
|
+
def do_full_address_assertions(res)
|
70
|
+
assert_equal "CA", res.state
|
71
|
+
assert_equal "San Francisco", res.city
|
72
|
+
assert_equal "37.792406,-122.39411", res.ll
|
73
|
+
assert res.is_us?
|
74
|
+
assert_equal "100 Spear St, San Francisco, CA, 94105-1522, US", res.full_address
|
75
|
+
assert_equal "yahoo", res.provider
|
76
|
+
end
|
77
|
+
|
78
|
+
def do_city_assertions(res)
|
79
|
+
assert_equal "CA", res.state
|
80
|
+
assert_equal "San Francisco", res.city
|
81
|
+
assert_equal "37.7742,-122.417068", res.ll
|
82
|
+
assert res.is_us?
|
83
|
+
assert_equal "San Francisco, CA, US", res.full_address
|
84
|
+
assert_nil res.street_address
|
85
|
+
assert_equal "yahoo", res.provider
|
86
|
+
end
|
87
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: soey-geokit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andre Lewis and Bill Eisenhauer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-02-09 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Geokit Gem
|
17
|
+
email:
|
18
|
+
- andre@earthcode.com / bill_eisenhauer@yahoo.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- Manifest.txt
|
25
|
+
- README.markdown
|
26
|
+
files:
|
27
|
+
- Manifest.txt
|
28
|
+
- README.markdown
|
29
|
+
- Rakefile
|
30
|
+
- lib/geokit/geocoders.rb
|
31
|
+
- lib/geokit.rb
|
32
|
+
- lib/geokit/mappable.rb
|
33
|
+
- test/test_base_geocoder.rb
|
34
|
+
- test/test_bounds.rb
|
35
|
+
- test/test_ca_geocoder.rb
|
36
|
+
- test/test_geoloc.rb
|
37
|
+
- test/test_google_geocoder.rb
|
38
|
+
- test/test_latlng.rb
|
39
|
+
- test/test_multi_geocoder.rb
|
40
|
+
- test/test_us_geocoder.rb
|
41
|
+
- test/test_yahoo_geocoder.rb
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://geokit.rubyforge.org
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options:
|
46
|
+
- --main
|
47
|
+
- README.markdown
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project: geokit
|
65
|
+
rubygems_version: 1.2.0
|
66
|
+
signing_key:
|
67
|
+
specification_version: 2
|
68
|
+
summary: none
|
69
|
+
test_files:
|
70
|
+
- test/test_base_geocoder.rb
|
71
|
+
- test/test_bounds.rb
|
72
|
+
- test/test_ca_geocoder.rb
|
73
|
+
- test/test_geoloc.rb
|
74
|
+
- test/test_google_geocoder.rb
|
75
|
+
- test/test_latlng.rb
|
76
|
+
- test/test_multi_geocoder.rb
|
77
|
+
- test/test_us_geocoder.rb
|
78
|
+
- test/test_yahoo_geocoder.rb
|