glebm-geokit 1.5.2
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.
- data/Manifest.txt +21 -0
- data/README.markdown +273 -0
- data/Rakefile +22 -0
- data/lib/geokit.rb +31 -0
- data/lib/geokit/geocoders.rb +727 -0
- data/lib/geokit/mappable.rb +531 -0
- data/test/test_base_geocoder.rb +58 -0
- data/test/test_bounds.rb +97 -0
- data/test/test_ca_geocoder.rb +41 -0
- data/test/test_geoloc.rb +72 -0
- data/test/test_geoplugin_geocoder.rb +59 -0
- data/test/test_google_geocoder.rb +227 -0
- data/test/test_google_reverse_geocoder.rb +49 -0
- data/test/test_inflector.rb +24 -0
- data/test/test_ipgeocoder.rb +110 -0
- data/test/test_latlng.rb +209 -0
- data/test/test_multi_geocoder.rb +93 -0
- data/test/test_multi_ip_geocoder.rb +38 -0
- data/test/test_us_geocoder.rb +56 -0
- data/test/test_yahoo_geocoder.rb +105 -0
- metadata +102 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_base_geocoder')
|
2
|
+
|
3
|
+
Geokit::Geocoders::ip_provider_order=[:geo_plugin,:ip]
|
4
|
+
|
5
|
+
class MultiIpGeocoderTest < BaseGeocoderTest #:nodoc: all
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@ip_address = '10.10.10.10'
|
9
|
+
@success = Geokit::GeoLoc.new({:city=>"SAN FRANCISCO", :state=>"CA", :country_code=>"US", :lat=>37.7742, :lng=>-122.417068})
|
10
|
+
@success.success = true
|
11
|
+
@failure = Geokit::GeoLoc.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_successful_first
|
15
|
+
Geokit::Geocoders::GeoPluginGeocoder.expects(:geocode).with(@ip_address, {}).returns(@success)
|
16
|
+
assert_equal @success, Geokit::Geocoders::MultiGeocoder.geocode(@ip_address)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_failover
|
20
|
+
Geokit::Geocoders::GeoPluginGeocoder.expects(:geocode).with(@ip_address, {}).returns(@failure)
|
21
|
+
Geokit::Geocoders::IpGeocoder.expects(:geocode).with(@ip_address, {}).returns(@success)
|
22
|
+
assert_equal @success, Geokit::Geocoders::MultiGeocoder.geocode(@ip_address)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_failure
|
26
|
+
Geokit::Geocoders::GeoPluginGeocoder.expects(:geocode).with(@ip_address, {}).returns(@failure)
|
27
|
+
Geokit::Geocoders::IpGeocoder.expects(:geocode).with(@ip_address, {}).returns(@failure)
|
28
|
+
assert_equal @failure, Geokit::Geocoders::MultiGeocoder.geocode(@ip_address)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_invalid_provider
|
32
|
+
temp = Geokit::Geocoders::ip_provider_order
|
33
|
+
Geokit::Geocoders.ip_provider_order = [:bogus]
|
34
|
+
assert_equal @failure, Geokit::Geocoders::MultiGeocoder.geocode(@ip_address)
|
35
|
+
Geokit::Geocoders.ip_provider_order = temp
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,56 @@
|
|
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
|
+
def test_all_method
|
39
|
+
response = MockSuccess.new
|
40
|
+
response.expects(:body).returns(GEOCODER_US_FULL)
|
41
|
+
url = "http://geocoder.us/service/csv/geocode?address=#{Geokit::Inflector.url_escape(@address)}"
|
42
|
+
Geokit::Geocoders::UsGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
43
|
+
res=Geokit::Geocoders::UsGeocoder.geocode(@address)
|
44
|
+
assert_equal 1, res.all.size
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def verify(location)
|
50
|
+
assert_equal "CA", location.state
|
51
|
+
assert_equal "San Francisco", location.city
|
52
|
+
assert_equal "37.792528,-122.393981", location.ll
|
53
|
+
assert location.is_us?
|
54
|
+
assert_equal "100 Spear St, San Francisco, CA, 94105, US", location.full_address #slightly different from yahoo
|
55
|
+
end
|
56
|
+
end
|
@@ -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,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: glebm-geokit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 7
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 5
|
9
|
+
- 2
|
10
|
+
version: 1.5.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Andre Lewis and Bill Eisenhauer, with fixes from Krzysztof Knapik
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-05-19 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Geokit Gem (glebm's fork)
|
23
|
+
email:
|
24
|
+
- andre@earthcode.com / bill_eisenhauer@yahoo.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files:
|
30
|
+
- Manifest.txt
|
31
|
+
- README.markdown
|
32
|
+
files:
|
33
|
+
- Manifest.txt
|
34
|
+
- README.markdown
|
35
|
+
- Rakefile
|
36
|
+
- lib/geokit/geocoders.rb
|
37
|
+
- lib/geokit.rb
|
38
|
+
- lib/geokit/mappable.rb
|
39
|
+
- test/test_base_geocoder.rb
|
40
|
+
- test/test_bounds.rb
|
41
|
+
- test/test_ca_geocoder.rb
|
42
|
+
- test/test_geoloc.rb
|
43
|
+
- test/test_google_geocoder.rb
|
44
|
+
- test/test_latlng.rb
|
45
|
+
- test/test_multi_geocoder.rb
|
46
|
+
- test/test_us_geocoder.rb
|
47
|
+
- test/test_yahoo_geocoder.rb
|
48
|
+
- test/test_geoplugin_geocoder.rb
|
49
|
+
- test/test_google_reverse_geocoder.rb
|
50
|
+
- test/test_inflector.rb
|
51
|
+
- test/test_ipgeocoder.rb
|
52
|
+
- test/test_multi_ip_geocoder.rb
|
53
|
+
has_rdoc: true
|
54
|
+
homepage: http://github.com/glebm/geokit-gem
|
55
|
+
licenses: []
|
56
|
+
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options:
|
59
|
+
- --main
|
60
|
+
- README.markdown
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
version: "0"
|
81
|
+
requirements: []
|
82
|
+
|
83
|
+
rubyforge_project: geokit
|
84
|
+
rubygems_version: 1.3.7
|
85
|
+
signing_key:
|
86
|
+
specification_version: 2
|
87
|
+
summary: none
|
88
|
+
test_files:
|
89
|
+
- test/test_base_geocoder.rb
|
90
|
+
- test/test_bounds.rb
|
91
|
+
- test/test_ca_geocoder.rb
|
92
|
+
- test/test_geoloc.rb
|
93
|
+
- test/test_geoplugin_geocoder.rb
|
94
|
+
- test/test_google_geocoder.rb
|
95
|
+
- test/test_google_reverse_geocoder.rb
|
96
|
+
- test/test_inflector.rb
|
97
|
+
- test/test_ipgeocoder.rb
|
98
|
+
- test/test_latlng.rb
|
99
|
+
- test/test_multi_geocoder.rb
|
100
|
+
- test/test_multi_ip_geocoder.rb
|
101
|
+
- test/test_us_geocoder.rb
|
102
|
+
- test/test_yahoo_geocoder.rb
|