eugenebolshakov-geokit 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,105 @@
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_accuracy
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(@address)}"
39
+ Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
40
+ res = Geokit::Geocoders::YahooGeocoder.geocode(@address)
41
+ assert_equal 8, res.accuracy
42
+ end
43
+
44
+ def test_yahoo_full_address_with_geo_loc
45
+ response = MockSuccess.new
46
+ response.expects(:body).returns(YAHOO_FULL)
47
+ url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{Geokit::Inflector.url_escape(@full_address)}"
48
+ Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
49
+ do_full_address_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@yahoo_full_loc))
50
+ end
51
+
52
+ def test_yahoo_city
53
+ response = MockSuccess.new
54
+ response.expects(:body).returns(YAHOO_CITY)
55
+ url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{Geokit::Inflector.url_escape(@address)}"
56
+ Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
57
+ do_city_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@address))
58
+ end
59
+
60
+ def test_yahoo_city_accuracy
61
+ response = MockSuccess.new
62
+ response.expects(:body).returns(YAHOO_CITY)
63
+ url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{Geokit::Inflector.url_escape(@address)}"
64
+ Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
65
+ res = Geokit::Geocoders::YahooGeocoder.geocode(@address)
66
+ assert_equal 4, res.accuracy
67
+ end
68
+
69
+ def test_yahoo_city_with_geo_loc
70
+ response = MockSuccess.new
71
+ response.expects(:body).returns(YAHOO_CITY)
72
+ url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{Geokit::Inflector.url_escape(@address)}"
73
+ Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
74
+ do_city_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@yahoo_city_loc))
75
+ end
76
+
77
+ def test_service_unavailable
78
+ response = MockFailure.new
79
+ url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{Geokit::Inflector.url_escape(@address)}"
80
+ Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
81
+ assert !Geokit::Geocoders::YahooGeocoder.geocode(@yahoo_city_loc).success
82
+ end
83
+
84
+ private
85
+
86
+ # next two methods do the assertions for both address-level and city-level lookups
87
+ def do_full_address_assertions(res)
88
+ assert_equal "CA", res.state
89
+ assert_equal "San Francisco", res.city
90
+ assert_equal "37.792406,-122.39411", res.ll
91
+ assert res.is_us?
92
+ assert_equal "100 Spear St, San Francisco, CA, 94105-1522, US", res.full_address
93
+ assert_equal "yahoo", res.provider
94
+ end
95
+
96
+ def do_city_assertions(res)
97
+ assert_equal "CA", res.state
98
+ assert_equal "San Francisco", res.city
99
+ assert_equal "37.7742,-122.417068", res.ll
100
+ assert res.is_us?
101
+ assert_equal "San Francisco, CA, US", res.full_address
102
+ assert_nil res.street_address
103
+ assert_equal "yahoo", res.provider
104
+ end
105
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eugenebolshakov-geokit
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Andre Lewis and Bill Eisenhauer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-02 00:00:00 +04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Geokit Gem with Geonames search support
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
+ - test/test_geonames_geocoder.rb
43
+ has_rdoc: true
44
+ homepage: http://geokit.rubyforge.org
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --main
50
+ - README.markdown
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements: []
66
+
67
+ rubyforge_project: geokit
68
+ rubygems_version: 1.3.5
69
+ signing_key:
70
+ specification_version: 2
71
+ summary: none
72
+ test_files:
73
+ - test/test_base_geocoder.rb
74
+ - test/test_bounds.rb
75
+ - test/test_ca_geocoder.rb
76
+ - test/test_geoloc.rb
77
+ - test/test_geoplugin_geocoder.rb
78
+ - test/test_google_geocoder.rb
79
+ - test/test_google_reverse_geocoder.rb
80
+ - test/test_inflector.rb
81
+ - test/test_ipgeocoder.rb
82
+ - test/test_latlng.rb
83
+ - test/test_multi_geocoder.rb
84
+ - test/test_multi_ip_geocoder.rb
85
+ - test/test_us_geocoder.rb
86
+ - test/test_yahoo_geocoder.rb
87
+ - test/test_geonames_geocoder.rb