andre-geokit 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/Manifest.txt +20 -0
- data/README.markdown +66 -0
- data/Rakefile +20 -0
- data/lib/geocoders.rb +386 -0
- data/lib/geokit.rb +30 -0
- data/lib/mappable.rb +432 -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 +111 -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 +88 -0
@@ -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,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: andre-geokit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andre Lewis and Bill Eisenhauer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-11-30 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.8.2
|
23
|
+
version:
|
24
|
+
description: Geokit Gem
|
25
|
+
email:
|
26
|
+
- andre@earthcode.com / bill_eisenhauer@yahoo.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- History.txt
|
33
|
+
- Manifest.txt
|
34
|
+
- README.markdown
|
35
|
+
files:
|
36
|
+
- History.txt
|
37
|
+
- Manifest.txt
|
38
|
+
- README.markdown
|
39
|
+
- Rakefile
|
40
|
+
- lib/geocoders.rb
|
41
|
+
- lib/geokit.rb
|
42
|
+
- lib/mappable.rb
|
43
|
+
- test/test_base_geocoder.rb
|
44
|
+
- test/test_bounds.rb
|
45
|
+
- test/test_ca_geocoder.rb
|
46
|
+
- test/test_geoloc.rb
|
47
|
+
- test/test_google_geocoder.rb
|
48
|
+
- test/test_latlng.rb
|
49
|
+
- test/test_multi_geocoder.rb
|
50
|
+
- test/test_us_geocoder.rb
|
51
|
+
- test/test_yahoo_geocoder.rb
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://geokit.rubyforge.org
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options:
|
56
|
+
- --main
|
57
|
+
- README.txt
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project: geokit
|
75
|
+
rubygems_version: 1.2.0
|
76
|
+
signing_key:
|
77
|
+
specification_version: 2
|
78
|
+
summary: none
|
79
|
+
test_files:
|
80
|
+
- test/test_base_geocoder.rb
|
81
|
+
- test/test_bounds.rb
|
82
|
+
- test/test_ca_geocoder.rb
|
83
|
+
- test/test_geoloc.rb
|
84
|
+
- test/test_google_geocoder.rb
|
85
|
+
- test/test_latlng.rb
|
86
|
+
- test/test_multi_geocoder.rb
|
87
|
+
- test/test_us_geocoder.rb
|
88
|
+
- test/test_yahoo_geocoder.rb
|