graticule 0.2.12 → 1.0.0.pre
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/.autotest +13 -0
- data/.gitignore +2 -1
- data/CHANGELOG.txt +2 -0
- data/README.txt +5 -1
- data/Rakefile +31 -51
- data/VERSION +1 -1
- data/graticule.gemspec +102 -53
- data/lib/graticule/geocoder/base.rb +1 -1
- data/lib/graticule/geocoder/bogus.rb +8 -6
- data/lib/graticule/geocoder/freethepostcode.rb +38 -0
- data/lib/graticule/geocoder/geocoder_ca.rb +45 -20
- data/lib/graticule/geocoder/geocoder_us.rb +26 -14
- data/lib/graticule/geocoder/geonames.rb +51 -0
- data/lib/graticule/geocoder/google.rb +71 -44
- data/lib/graticule/geocoder/local_search_maps.rb +8 -7
- data/lib/graticule/geocoder/mapquest.rb +47 -27
- data/lib/graticule/geocoder/multi.rb +68 -8
- data/lib/graticule/geocoder/multimap.rb +49 -24
- data/lib/graticule/geocoder/yahoo.rb +57 -28
- data/lib/graticule/geocoder.rb +1 -0
- data/lib/graticule/location.rb +4 -0
- data/lib/graticule.rb +2 -4
- data/test/config.yml +32 -0
- data/test/config.yml.default +9 -12
- data/test/fixtures/responses/freethepostcode/not_found.txt +3 -0
- data/test/fixtures/responses/freethepostcode/success.txt +2 -0
- data/test/fixtures/responses/geocoder_ca/success.xml +12 -0
- data/test/fixtures/responses/geocoder_us/success.xml +3 -13
- data/test/fixtures/responses/geonames/missing.xml +4 -0
- data/test/fixtures/responses/geonames/success.xml +14 -0
- data/test/fixtures/responses/geonames/unknown.xml +4 -0
- data/test/fixtures/responses/google/partial.xml +16 -1
- data/test/fixtures/responses/google/success.xml +16 -1
- data/test/fixtures/responses/google/unknown_address.xml +8 -1
- data/test/fixtures/responses/yahoo/success.xml +2 -2
- data/test/fixtures/responses/yahoo/unknown_address.xml +1 -1
- data/test/{unit/graticule → graticule}/distance_test.rb +1 -1
- data/test/graticule/geocoder/freethepostcode_test.rb +36 -0
- data/test/graticule/geocoder/geocoder_ca_test.rb +41 -0
- data/test/{unit/graticule → graticule}/geocoder/geocoder_us_test.rb +1 -1
- data/test/{unit/graticule → graticule}/geocoder/geocoders.rb +1 -2
- data/test/graticule/geocoder/geonames_test.rb +48 -0
- data/test/{unit/graticule → graticule}/geocoder/google_test.rb +21 -26
- data/test/{unit/graticule → graticule}/geocoder/host_ip_test.rb +1 -1
- data/test/{unit/graticule → graticule}/geocoder/local_search_maps_test.rb +1 -1
- data/test/{unit/graticule → graticule}/geocoder/mapquest_test.rb +4 -2
- data/test/{unit/graticule → graticule}/geocoder/multi_test.rb +10 -2
- data/test/{unit/graticule → graticule}/geocoder/multimap_test.rb +2 -2
- data/test/{unit/graticule → graticule}/geocoder/yahoo_test.rb +6 -5
- data/test/{unit/graticule → graticule}/geocoder_test.rb +1 -5
- data/test/{unit/graticule → graticule}/location_test.rb +9 -1
- data/test/test_helper.rb +1 -2
- metadata +88 -47
- data/Manifest.txt +0 -84
- data/lib/graticule/geocoder/meta_carta.rb +0 -33
- data/lib/graticule/geocoder/postcode_anywhere.rb +0 -63
- data/lib/graticule/geocoder/rest.rb +0 -18
- data/lib/graticule/version.rb +0 -9
- data/test/fixtures/responses/meta_carta/bad_address.xml +0 -17
- data/test/fixtures/responses/meta_carta/multiple.xml +0 -33
- data/test/fixtures/responses/meta_carta/success.xml +0 -31
- data/test/fixtures/responses/postcode_anywhere/badkey.xml +0 -9
- data/test/fixtures/responses/postcode_anywhere/canada.xml +0 -16
- data/test/fixtures/responses/postcode_anywhere/empty.xml +0 -16
- data/test/fixtures/responses/postcode_anywhere/success.xml +0 -16
- data/test/fixtures/responses/postcode_anywhere/uk.xml +0 -18
- data/test/unit/graticule/geocoder/meta_carta_test.rb +0 -44
- data/test/unit/graticule/geocoder/postcode_anywhere_test.rb +0 -50
data/lib/graticule.rb
CHANGED
|
@@ -2,22 +2,20 @@ $:.unshift(File.dirname(__FILE__))
|
|
|
2
2
|
|
|
3
3
|
require 'active_support'
|
|
4
4
|
|
|
5
|
-
require 'graticule/version'
|
|
6
5
|
require 'graticule/core_ext'
|
|
7
6
|
require 'graticule/location'
|
|
8
7
|
require 'graticule/geocoder'
|
|
9
8
|
require 'graticule/geocoder/base'
|
|
10
9
|
require 'graticule/geocoder/bogus'
|
|
11
|
-
require 'graticule/geocoder/rest'
|
|
12
10
|
require 'graticule/geocoder/google'
|
|
13
11
|
require 'graticule/geocoder/host_ip'
|
|
14
12
|
require 'graticule/geocoder/multi'
|
|
15
13
|
require 'graticule/geocoder/yahoo'
|
|
16
14
|
require 'graticule/geocoder/geocoder_ca'
|
|
17
15
|
require 'graticule/geocoder/geocoder_us'
|
|
16
|
+
require 'graticule/geocoder/geonames'
|
|
18
17
|
require 'graticule/geocoder/local_search_maps'
|
|
19
|
-
require 'graticule/geocoder/
|
|
20
|
-
require 'graticule/geocoder/postcode_anywhere'
|
|
18
|
+
require 'graticule/geocoder/freethepostcode'
|
|
21
19
|
require 'graticule/geocoder/multimap'
|
|
22
20
|
require 'graticule/geocoder/mapquest'
|
|
23
21
|
require 'graticule/distance'
|
data/test/config.yml
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
google:
|
|
2
|
+
responses:
|
|
3
|
+
success: "http://maps.google.com/maps/geo?q=1600+amphitheatre+mtn+view+ca&output=xml"
|
|
4
|
+
missing_address: "http://maps.google.com/maps/geo?output=xml"
|
|
5
|
+
unknown_address: "http://maps.google.com/maps/geo?q=xxxxx&output=xml"
|
|
6
|
+
partial: "http://maps.google.com/maps/geo?q=sf+ca&output=xml"
|
|
7
|
+
multiple: "http://maps.google.com/maps/geo?output=xml&q=Queen%20St%20West,%20Toronto,%20ON%20CA"
|
|
8
|
+
#unavailable: no way to reproduce this
|
|
9
|
+
#limit: no way to reproduce this
|
|
10
|
+
#server_error: no way to reproduce this
|
|
11
|
+
geocoder_ca:
|
|
12
|
+
responses:
|
|
13
|
+
success.xml: http://geocoder.ca/?locate=200+mutcalf%2C+ottawa+on&geoit=xml&standard=1&showpostal=1
|
|
14
|
+
geocoder_us:
|
|
15
|
+
responses:
|
|
16
|
+
success.xml: http://rpc.geocoder.us/service/rest/geocode?address=1600%20Pennsylvania%20Ave%20NW,%20Washington%20DC
|
|
17
|
+
unknown.xml: http://rpc.geocoder.us/service/rest/geocode?address=1600
|
|
18
|
+
host_ip:
|
|
19
|
+
responses:
|
|
20
|
+
private.txt: http://api.hostip.info/get_html.php?ip=192.168.0.1&position=true
|
|
21
|
+
success.txt: http://api.hostip.info/get_html.php?ip=64.233.167.99&position=true
|
|
22
|
+
unknown.txt: http://api.hostip.info/get_html.php?ip=254.254.254.254&position=true
|
|
23
|
+
local_search_maps:
|
|
24
|
+
responses:
|
|
25
|
+
success.txt: http://geo.localsearchmaps.com/?street=48+Leicester+Square&city=London&country=UK
|
|
26
|
+
empty.txt: http://geo.localsearchmaps.com/
|
|
27
|
+
not_found.txt: http://geo.localsearchmaps.com/?street=48
|
|
28
|
+
yahoo:
|
|
29
|
+
key: XMfT4AnV34H8_yIPq2yGchqatp_PCTDAPpnoxr6TB54Dsscv0UjtarOVx_g8Ajd2edvR8WQ-
|
|
30
|
+
responses:
|
|
31
|
+
success.xml: http://api.local.yahoo.com/MapsService/V1/geocode?location=701%20First%20Street,%20Sunnyvale,%20CA&output=xml&appid=:key
|
|
32
|
+
unknown_address.xml: http://api.local.yahoo.com/MapsService/V1/geocode?location=thisprobablycantbefound&output=xml&appid=:key
|
data/test/config.yml.default
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
google:
|
|
2
2
|
key: PUT YOUR KEY HERE
|
|
3
3
|
responses:
|
|
4
|
-
success.xml: http://maps.google.com/maps/geo?q=1600+amphitheatre+mtn+view+ca&output=xml&key=:key
|
|
4
|
+
success.xml: "http://maps.google.com/maps/geo?q=1600+amphitheatre+mtn+view+ca&output=xml&key=:key"
|
|
5
5
|
badkey.xml: http://maps.google.com/maps/geo?q=1600+amphitheatre+mtn+view+ca&output=xml&key=this_is_a_bad_key
|
|
6
|
-
missing_address.xml: http://maps.google.com/maps/geo?output=xml&key=:key
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
missing_address.xml: "http://maps.google.com/maps/geo?output=xml&key=:key"
|
|
7
|
+
unknown_address.xml: "http://maps.google.com/maps/geo?q=xxxxx&output=xml&key=:key"
|
|
8
|
+
partial.xml: "http://maps.google.com/maps/geo?q=sf+ca&output=xml&key=:key"
|
|
9
|
+
#unavailable.xml: no way to reproduce this
|
|
10
10
|
#limit.xml: no way to reproduce this
|
|
11
11
|
#server_error.xml: no way to reproduce this
|
|
12
12
|
geocoder_us:
|
|
@@ -23,14 +23,11 @@ local_search_maps:
|
|
|
23
23
|
success.txt: http://geo.localsearchmaps.com/?street=48+Leicester+Square&city=London&country=UK
|
|
24
24
|
empty.txt: http://geo.localsearchmaps.com/
|
|
25
25
|
not_found.txt: http://geo.localsearchmaps.com/?street=48
|
|
26
|
-
meta_carta:
|
|
27
|
-
responses:
|
|
28
|
-
bad_address.xml: http://labs.metacarta.com/GeoParser/?q=aoeueou&output=locations
|
|
29
|
-
# doesn't work
|
|
30
|
-
#multiple.xml: http://labs.metacarta.com/GeoParser/?q=seattle&output=locations
|
|
31
|
-
success.xml: http://labs.metacarta.com/GeoParser/?q=baghdad&output=locations
|
|
32
26
|
yahoo:
|
|
33
27
|
key: PUT YOUR KEY HERE
|
|
34
28
|
responses:
|
|
35
29
|
success.xml: http://api.local.yahoo.com/MapsService/V1/geocode?location=701%20First%20Street,%20Sunnyvale,%20CA&output=xml&appid=:key
|
|
36
|
-
unknown_address.xml: http://api.local.yahoo.com/MapsService/V1/geocode?location=thisprobablycantbefound&output=xml&appid=:key
|
|
30
|
+
unknown_address.xml: http://api.local.yahoo.com/MapsService/V1/geocode?location=thisprobablycantbefound&output=xml&appid=:key
|
|
31
|
+
geonames:
|
|
32
|
+
responses:
|
|
33
|
+
success.xml: http://ws.geonames.org/timezone?formatted=true&lat=41.85&lng=-87.65&style=full
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<geodata>
|
|
3
|
+
<latt>45.418076</latt>
|
|
4
|
+
<longt>-75.693293</longt>
|
|
5
|
+
<postal>K2P1P6</postal>
|
|
6
|
+
<standard>
|
|
7
|
+
<stnumber>200</stnumber>
|
|
8
|
+
<staddress>MUTCALF </staddress>
|
|
9
|
+
<city>ottawa</city>
|
|
10
|
+
<prov>ON</prov>
|
|
11
|
+
</standard>
|
|
12
|
+
</geodata>
|
|
@@ -1,18 +1,8 @@
|
|
|
1
1
|
<?xml version="1.0"?>
|
|
2
|
-
<rdf:RDF
|
|
3
|
-
|
|
4
|
-
xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
|
|
5
|
-
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
|
6
|
-
>
|
|
7
|
-
|
|
8
|
-
<geo:Point rdf:nodeID="aid15626963">
|
|
9
|
-
|
|
2
|
+
<rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
|
3
|
+
<geo:Point rdf:nodeID="aid78656681">
|
|
10
4
|
<dc:description>1600 Pennsylvania Ave NW, Washington DC 20502</dc:description>
|
|
11
5
|
<geo:long>-77.037684</geo:long>
|
|
12
6
|
<geo:lat>38.898748</geo:lat>
|
|
13
|
-
|
|
14
|
-
</geo:Point>
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
</geo:Point>
|
|
17
8
|
</rdf:RDF>
|
|
18
|
-
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
2
|
+
<geonames>
|
|
3
|
+
<timezone>
|
|
4
|
+
<countryCode>US</countryCode>
|
|
5
|
+
<countryName>United States</countryName>
|
|
6
|
+
<lat>41.85</lat>
|
|
7
|
+
<lng>-87.65</lng>
|
|
8
|
+
<timezoneId>America/Chicago</timezoneId>
|
|
9
|
+
<dstOffset>-5.0</dstOffset>
|
|
10
|
+
<gmtOffset>-6.0</gmtOffset>
|
|
11
|
+
<rawOffset>-6.0</rawOffset>
|
|
12
|
+
<time>2009-10-07 15:08</time>
|
|
13
|
+
</timezone>
|
|
14
|
+
</geonames>
|
|
@@ -1 +1,16 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" ?>
|
|
2
|
+
<kml xmlns="http://earth.google.com/kml/2.0"><Response>
|
|
3
|
+
<name>sf ca</name>
|
|
4
|
+
<Status>
|
|
5
|
+
<code>200</code>
|
|
6
|
+
<request>geocode</request>
|
|
7
|
+
</Status>
|
|
8
|
+
<Placemark id="p1">
|
|
9
|
+
<address>San Francisco, CA, USA</address>
|
|
10
|
+
<AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>CA</AdministrativeAreaName><Locality><LocalityName>San Francisco</LocalityName></Locality></AdministrativeArea></Country></AddressDetails>
|
|
11
|
+
<ExtendedData>
|
|
12
|
+
<LatLonBox north="37.8457283" south="37.7046163" east="-122.2911496" west="-122.5472684" />
|
|
13
|
+
</ExtendedData>
|
|
14
|
+
<Point><coordinates>-122.4192090,37.7752060,0</coordinates></Point>
|
|
15
|
+
</Placemark>
|
|
16
|
+
</Response></kml>
|
|
@@ -1 +1,16 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" ?>
|
|
2
|
+
<kml xmlns="http://earth.google.com/kml/2.0"><Response>
|
|
3
|
+
<name>1600 amphitheatre mtn view ca</name>
|
|
4
|
+
<Status>
|
|
5
|
+
<code>200</code>
|
|
6
|
+
<request>geocode</request>
|
|
7
|
+
</Status>
|
|
8
|
+
<Placemark id="p1">
|
|
9
|
+
<address>1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA</address>
|
|
10
|
+
<AddressDetails Accuracy="8" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>CA</AdministrativeAreaName><Locality><LocalityName>Mountain View</LocalityName><Thoroughfare><ThoroughfareName>1600 Amphitheatre Pkwy</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>94043</PostalCodeNumber></PostalCode></Locality></AdministrativeArea></Country></AddressDetails>
|
|
11
|
+
<ExtendedData>
|
|
12
|
+
<LatLonBox north="37.4251196" south="37.4188244" east="-122.0809954" west="-122.0872906" />
|
|
13
|
+
</ExtendedData>
|
|
14
|
+
<Point><coordinates>-122.0850350,37.4231390,0</coordinates></Point>
|
|
15
|
+
</Placemark>
|
|
16
|
+
</Response></kml>
|
|
@@ -1 +1,8 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" ?>
|
|
2
|
+
<kml xmlns="http://earth.google.com/kml/2.0"><Response>
|
|
3
|
+
<name>xxxxx</name>
|
|
4
|
+
<Status>
|
|
5
|
+
<code>602</code>
|
|
6
|
+
<request>geocode</request>
|
|
7
|
+
</Status>
|
|
8
|
+
</Response></kml>
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
<?xml version="1.0"?>
|
|
2
|
-
<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" warning="The exact location could not be found, here is the closest match: 701
|
|
3
|
-
<!--
|
|
2
|
+
<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" warning="The exact location could not be found, here is the closest match: 701 1st Ave, Sunnyvale, CA 94089"><Latitude>37.416397</Latitude><Longitude>-122.025055</Longitude><Address>701 1st Ave</Address><City>Sunnyvale</City><State>CA</State><Zip>94089-1019</Zip><Country>US</Country></Result></ResultSet>
|
|
3
|
+
<!-- ws01.ydn.re2.yahoo.com uncompressed/chunked Sun Oct 4 17:27:51 PDT 2009 -->
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module Graticule
|
|
4
|
+
module Geocoder
|
|
5
|
+
class FreeThePostcodeTest < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
def setup
|
|
8
|
+
URI::HTTP.responses = []
|
|
9
|
+
URI::HTTP.uris = []
|
|
10
|
+
@geocoder = FreeThePostcode.new
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_success
|
|
14
|
+
return unless prepare_response(:success)
|
|
15
|
+
|
|
16
|
+
location = Location.new(
|
|
17
|
+
:latitude => 51.503172,
|
|
18
|
+
:longitude => -0.241641)
|
|
19
|
+
|
|
20
|
+
assert_equal location, @geocoder.locate('W1A 1AA')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_locate_unknown_address
|
|
24
|
+
return unless prepare_response(:not_found)
|
|
25
|
+
assert_raises(AddressError) { @geocoder.locate 'Z12 9pp' }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
protected
|
|
29
|
+
|
|
30
|
+
def prepare_response(id = :success)
|
|
31
|
+
URI::HTTP.responses << response('freethepostcode', id, 'txt')
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module Graticule
|
|
4
|
+
module Geocoder
|
|
5
|
+
class GeocoderCaTest < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
def setup
|
|
8
|
+
URI::HTTP.responses = []
|
|
9
|
+
URI::HTTP.uris = []
|
|
10
|
+
|
|
11
|
+
@geocoder = GeocoderCa.new
|
|
12
|
+
@location = Location.new(
|
|
13
|
+
:latitude => 45.418076,
|
|
14
|
+
:longitude => -75.693293,
|
|
15
|
+
:locality => "ottawa",
|
|
16
|
+
:precision => :unknown,
|
|
17
|
+
:region => "ON",
|
|
18
|
+
:street => "200 MUTCALF "
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_success
|
|
23
|
+
prepare_response(:success)
|
|
24
|
+
assert_equal @location, @geocoder.locate('200 mutcalf, ottawa on')
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_url
|
|
28
|
+
prepare_response(:success)
|
|
29
|
+
@geocoder.locate('200 mutcalf, ottawa on')
|
|
30
|
+
assert_equal 'http://geocoder.ca/?geoit=XML&locate=200%20mutcalf,%20ottawa%20on&showpostal=1&standard=1',
|
|
31
|
+
URI::HTTP.uris.first
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
protected
|
|
35
|
+
def prepare_response(id)
|
|
36
|
+
URI::HTTP.responses << response('geocoder_ca', id)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module Graticule
|
|
4
|
+
module Geocoder
|
|
5
|
+
class GeonamesTest < Test::Unit::TestCase
|
|
6
|
+
def setup
|
|
7
|
+
URI::HTTP.responses = []
|
|
8
|
+
URI::HTTP.uris = []
|
|
9
|
+
@geocoder = Geonames.new
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_time_zone
|
|
13
|
+
return unless prepare_response(:success)
|
|
14
|
+
|
|
15
|
+
chicago = Location.new(:latitude => 41.85, :longitude => -87.65)
|
|
16
|
+
assert_equal 'America/Chicago', @geocoder.time_zone(chicago)
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# def test_locate_server_error
|
|
21
|
+
# return unless prepare_response(:server_error)
|
|
22
|
+
# assert_raises(Error) { @geocoder.locate 'x' }
|
|
23
|
+
# end
|
|
24
|
+
#
|
|
25
|
+
# def test_locate_too_many_queries
|
|
26
|
+
# return unless prepare_response(:limit)
|
|
27
|
+
# assert_raises(CredentialsError) { @geocoder.locate 'x' }
|
|
28
|
+
# end
|
|
29
|
+
#
|
|
30
|
+
# def test_locate_unavailable_address
|
|
31
|
+
# return unless prepare_response(:unavailable)
|
|
32
|
+
# assert_raises(AddressError) { @geocoder.locate 'x' }
|
|
33
|
+
# end
|
|
34
|
+
#
|
|
35
|
+
# def test_locate_unknown_address
|
|
36
|
+
# return unless prepare_response(:unknown_address)
|
|
37
|
+
# assert_raises(AddressError) { @geocoder.locate 'x' }
|
|
38
|
+
# end
|
|
39
|
+
|
|
40
|
+
protected
|
|
41
|
+
|
|
42
|
+
def prepare_response(id = :success)
|
|
43
|
+
URI::HTTP.responses << response('geonames', id)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
module Graticule
|
|
4
4
|
module Geocoder
|
|
@@ -6,26 +6,25 @@ module Graticule
|
|
|
6
6
|
def setup
|
|
7
7
|
URI::HTTP.responses = []
|
|
8
8
|
URI::HTTP.uris = []
|
|
9
|
-
@geocoder = Google.new(
|
|
9
|
+
@geocoder = Google.new('APP_ID')
|
|
10
10
|
end
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
def test_success
|
|
13
13
|
return unless prepare_response(:success)
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
location = Location.new(
|
|
16
16
|
:street => "1600 Amphitheatre Pkwy",
|
|
17
17
|
:locality => "Mountain View",
|
|
18
18
|
:region => "CA",
|
|
19
19
|
:postal_code => "94043",
|
|
20
20
|
:country => "US",
|
|
21
|
-
:longitude => -122.
|
|
22
|
-
:latitude => 37.
|
|
21
|
+
:longitude => -122.0850350,
|
|
22
|
+
:latitude => 37.4231390,
|
|
23
23
|
:precision => :address
|
|
24
24
|
)
|
|
25
25
|
assert_equal location, @geocoder.locate('1600 Amphitheatre Parkway, Mountain View, CA')
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
|
|
29
28
|
# The #locate parameters are broad, so the XML response contains
|
|
30
29
|
# multiple results at street-level precision. We expect to get the
|
|
31
30
|
# first result back, and it should not contain a postal code.
|
|
@@ -44,18 +43,14 @@ module Graticule
|
|
|
44
43
|
)
|
|
45
44
|
assert_equal location, @geocoder.locate('Queen St West, Toronto, ON CA')
|
|
46
45
|
end
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def test_only_coordinates
|
|
51
|
-
return unless prepare_response(:only_coordinates)
|
|
52
|
-
|
|
53
|
-
location = Location.new(:longitude => -17.000000, :latitude => 15.000000)
|
|
54
|
-
assert_equal location, @geocoder.locate('15-17 & 16 Railroad Square, Nashua, NH, 03064')
|
|
55
|
-
end
|
|
46
|
+
|
|
47
|
+
def test_only_coordinates
|
|
48
|
+
return unless prepare_response(:only_coordinates)
|
|
56
49
|
|
|
57
|
-
|
|
58
|
-
|
|
50
|
+
location = Location.new(:longitude => -17.000000, :latitude => 15.000000)
|
|
51
|
+
assert_equal location, @geocoder.locate('15-17 & 16 Railroad Square, Nashua, NH, 03064')
|
|
52
|
+
end
|
|
53
|
+
|
|
59
54
|
def test_partial
|
|
60
55
|
return unless prepare_response(:partial)
|
|
61
56
|
|
|
@@ -63,19 +58,14 @@ module Graticule
|
|
|
63
58
|
:locality => "San Francisco",
|
|
64
59
|
:region => "CA",
|
|
65
60
|
:country => "US",
|
|
66
|
-
:longitude => -122.
|
|
67
|
-
:latitude => 37.
|
|
68
|
-
:precision => :
|
|
61
|
+
:longitude => -122.419209,
|
|
62
|
+
:latitude => 37.775206,
|
|
63
|
+
:precision => :locality
|
|
69
64
|
)
|
|
70
65
|
|
|
71
66
|
assert_equal location, @geocoder.locate('sf ca')
|
|
72
67
|
end
|
|
73
68
|
|
|
74
|
-
def test_bad_key
|
|
75
|
-
return unless prepare_response(:badkey)
|
|
76
|
-
assert_raises(CredentialsError) { @geocoder.locate('x') }
|
|
77
|
-
end
|
|
78
|
-
|
|
79
69
|
def test_locate_missing_address
|
|
80
70
|
return unless prepare_response(:missing_address)
|
|
81
71
|
assert_raises(AddressError) { @geocoder.locate 'x' }
|
|
@@ -100,6 +90,11 @@ module Graticule
|
|
|
100
90
|
return unless prepare_response(:unknown_address)
|
|
101
91
|
assert_raises(AddressError) { @geocoder.locate 'x' }
|
|
102
92
|
end
|
|
93
|
+
|
|
94
|
+
def test_bad_key
|
|
95
|
+
return unless prepare_response(:badkey)
|
|
96
|
+
assert_raises(CredentialsError) { @geocoder.locate('x') }
|
|
97
|
+
end
|
|
103
98
|
|
|
104
99
|
protected
|
|
105
100
|
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
module Graticule
|
|
4
4
|
module Geocoder
|
|
5
5
|
class MapquestTest < Test::Unit::TestCase
|
|
6
6
|
def setup
|
|
7
|
+
URI::HTTP.responses = []
|
|
8
|
+
URI::HTTP.uris = []
|
|
7
9
|
@geocoder = Mapquest.new('client_id', 'password')
|
|
8
10
|
end
|
|
9
11
|
|
|
@@ -30,7 +32,7 @@ module Graticule
|
|
|
30
32
|
:locality => "Stony Brook",
|
|
31
33
|
:longitude => -73.141403,
|
|
32
34
|
:postal_code => nil,
|
|
33
|
-
:precision => :
|
|
35
|
+
:precision => :locality,
|
|
34
36
|
:region => "NY",
|
|
35
37
|
:street => nil
|
|
36
38
|
)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
module Graticule
|
|
4
4
|
module Geocoder
|
|
@@ -37,7 +37,15 @@ module Graticule
|
|
|
37
37
|
@geocoder = Multi.new(*@mock_geocoders) {|r| r == 3 }
|
|
38
38
|
assert_raises(Graticule::AddressError) { @geocoder.locate('test') }
|
|
39
39
|
end
|
|
40
|
-
|
|
40
|
+
|
|
41
|
+
def test_timeout
|
|
42
|
+
@mock = @mock_geocoders.first
|
|
43
|
+
def @mock.locate(*x)
|
|
44
|
+
sleep 1
|
|
45
|
+
end
|
|
46
|
+
@geocoder = Multi.new(@mock, :timeout => 0.1)
|
|
47
|
+
assert_raise(Timeout::Error) { @geocoder.locate('foo') }
|
|
48
|
+
end
|
|
41
49
|
end
|
|
42
50
|
end
|
|
43
51
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
module Graticule
|
|
4
4
|
module Geocoder
|
|
@@ -10,7 +10,7 @@ module Graticule
|
|
|
10
10
|
@geocoder = Multimap.new 'API_KEY'
|
|
11
11
|
@location = Location.new(
|
|
12
12
|
:street => "Oxford Street",
|
|
13
|
-
:locality => "
|
|
13
|
+
:locality => "LONDON",
|
|
14
14
|
:postal_code => "W1",
|
|
15
15
|
:country => "GB",
|
|
16
16
|
:longitude => -0.14839,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
module Graticule
|
|
4
4
|
module Geocoder
|
|
@@ -9,14 +9,15 @@ module Graticule
|
|
|
9
9
|
URI::HTTP.uris = []
|
|
10
10
|
@geocoder = Yahoo.new 'APP_ID'
|
|
11
11
|
@location = Location.new(
|
|
12
|
-
:street => "701
|
|
12
|
+
:street => "701 1st Ave",
|
|
13
13
|
:locality => "Sunnyvale",
|
|
14
14
|
:region => "CA",
|
|
15
15
|
:postal_code => "94089-1019",
|
|
16
16
|
:country => "US",
|
|
17
|
-
:longitude => -122.
|
|
18
|
-
:latitude => 37.
|
|
19
|
-
:precision => :address
|
|
17
|
+
:longitude => -122.025055,
|
|
18
|
+
:latitude => 37.416397,
|
|
19
|
+
:precision => :address,
|
|
20
|
+
:warning => "The exact location could not be found, here is the closest match: 701 First Ave, Sunnyvale, CA 94089"
|
|
20
21
|
)
|
|
21
22
|
end
|
|
22
23
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
module Graticule
|
|
4
4
|
class GeocoderTest < Test::Unit::TestCase
|
|
@@ -19,9 +19,5 @@ module Graticule
|
|
|
19
19
|
assert_equal Geocoder::GeocoderUs, Graticule.service(:geocoder_us)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
def test_meta_carta_service
|
|
23
|
-
assert_equal Geocoder::MetaCarta, Graticule.service(:meta_carta)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
22
|
end
|
|
27
23
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
module Graticule
|
|
4
4
|
class LocationTest < Test::Unit::TestCase
|
|
@@ -69,5 +69,13 @@ module Graticule
|
|
|
69
69
|
assert !Location.new(attr => 'Foo').blank?
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
|
+
|
|
73
|
+
def test_time_zone
|
|
74
|
+
URI::HTTP.uris = []
|
|
75
|
+
URI::HTTP.responses = []
|
|
76
|
+
URI::HTTP.responses << response('geonames', :success)
|
|
77
|
+
chicago = Location.new(:latitude => 41.85, :longitude => -87.65)
|
|
78
|
+
assert_equal 'America/Chicago', chicago.time_zone
|
|
79
|
+
end
|
|
72
80
|
end
|
|
73
81
|
end
|
data/test/test_helper.rb
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
|
2
|
-
$:.unshift(File.dirname(__FILE__) + '/mocks')
|
|
3
2
|
|
|
4
3
|
require 'rubygems'
|
|
5
|
-
require 'yaml'
|
|
6
4
|
require 'test/unit'
|
|
7
5
|
require 'graticule'
|
|
8
6
|
require 'mocha'
|
|
7
|
+
require 'mocks/uri'
|
|
9
8
|
|
|
10
9
|
TEST_RESPONSE_PATH = File.dirname(__FILE__) + '/fixtures/responses'
|
|
11
10
|
|