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.
Files changed (68) hide show
  1. data/.autotest +13 -0
  2. data/.gitignore +2 -1
  3. data/CHANGELOG.txt +2 -0
  4. data/README.txt +5 -1
  5. data/Rakefile +31 -51
  6. data/VERSION +1 -1
  7. data/graticule.gemspec +102 -53
  8. data/lib/graticule/geocoder/base.rb +1 -1
  9. data/lib/graticule/geocoder/bogus.rb +8 -6
  10. data/lib/graticule/geocoder/freethepostcode.rb +38 -0
  11. data/lib/graticule/geocoder/geocoder_ca.rb +45 -20
  12. data/lib/graticule/geocoder/geocoder_us.rb +26 -14
  13. data/lib/graticule/geocoder/geonames.rb +51 -0
  14. data/lib/graticule/geocoder/google.rb +71 -44
  15. data/lib/graticule/geocoder/local_search_maps.rb +8 -7
  16. data/lib/graticule/geocoder/mapquest.rb +47 -27
  17. data/lib/graticule/geocoder/multi.rb +68 -8
  18. data/lib/graticule/geocoder/multimap.rb +49 -24
  19. data/lib/graticule/geocoder/yahoo.rb +57 -28
  20. data/lib/graticule/geocoder.rb +1 -0
  21. data/lib/graticule/location.rb +4 -0
  22. data/lib/graticule.rb +2 -4
  23. data/test/config.yml +32 -0
  24. data/test/config.yml.default +9 -12
  25. data/test/fixtures/responses/freethepostcode/not_found.txt +3 -0
  26. data/test/fixtures/responses/freethepostcode/success.txt +2 -0
  27. data/test/fixtures/responses/geocoder_ca/success.xml +12 -0
  28. data/test/fixtures/responses/geocoder_us/success.xml +3 -13
  29. data/test/fixtures/responses/geonames/missing.xml +4 -0
  30. data/test/fixtures/responses/geonames/success.xml +14 -0
  31. data/test/fixtures/responses/geonames/unknown.xml +4 -0
  32. data/test/fixtures/responses/google/partial.xml +16 -1
  33. data/test/fixtures/responses/google/success.xml +16 -1
  34. data/test/fixtures/responses/google/unknown_address.xml +8 -1
  35. data/test/fixtures/responses/yahoo/success.xml +2 -2
  36. data/test/fixtures/responses/yahoo/unknown_address.xml +1 -1
  37. data/test/{unit/graticule → graticule}/distance_test.rb +1 -1
  38. data/test/graticule/geocoder/freethepostcode_test.rb +36 -0
  39. data/test/graticule/geocoder/geocoder_ca_test.rb +41 -0
  40. data/test/{unit/graticule → graticule}/geocoder/geocoder_us_test.rb +1 -1
  41. data/test/{unit/graticule → graticule}/geocoder/geocoders.rb +1 -2
  42. data/test/graticule/geocoder/geonames_test.rb +48 -0
  43. data/test/{unit/graticule → graticule}/geocoder/google_test.rb +21 -26
  44. data/test/{unit/graticule → graticule}/geocoder/host_ip_test.rb +1 -1
  45. data/test/{unit/graticule → graticule}/geocoder/local_search_maps_test.rb +1 -1
  46. data/test/{unit/graticule → graticule}/geocoder/mapquest_test.rb +4 -2
  47. data/test/{unit/graticule → graticule}/geocoder/multi_test.rb +10 -2
  48. data/test/{unit/graticule → graticule}/geocoder/multimap_test.rb +2 -2
  49. data/test/{unit/graticule → graticule}/geocoder/yahoo_test.rb +6 -5
  50. data/test/{unit/graticule → graticule}/geocoder_test.rb +1 -5
  51. data/test/{unit/graticule → graticule}/location_test.rb +9 -1
  52. data/test/test_helper.rb +1 -2
  53. metadata +88 -47
  54. data/Manifest.txt +0 -84
  55. data/lib/graticule/geocoder/meta_carta.rb +0 -33
  56. data/lib/graticule/geocoder/postcode_anywhere.rb +0 -63
  57. data/lib/graticule/geocoder/rest.rb +0 -18
  58. data/lib/graticule/version.rb +0 -9
  59. data/test/fixtures/responses/meta_carta/bad_address.xml +0 -17
  60. data/test/fixtures/responses/meta_carta/multiple.xml +0 -33
  61. data/test/fixtures/responses/meta_carta/success.xml +0 -31
  62. data/test/fixtures/responses/postcode_anywhere/badkey.xml +0 -9
  63. data/test/fixtures/responses/postcode_anywhere/canada.xml +0 -16
  64. data/test/fixtures/responses/postcode_anywhere/empty.xml +0 -16
  65. data/test/fixtures/responses/postcode_anywhere/success.xml +0 -16
  66. data/test/fixtures/responses/postcode_anywhere/uk.xml +0 -18
  67. data/test/unit/graticule/geocoder/meta_carta_test.rb +0 -44
  68. 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/meta_carta'
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
@@ -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
- unavailable.xml: http://maps.google.com/maps/geo?q=42-44+Hanway+Street,+London&output=xml&key=:key
8
- unknown_address.xml: http://maps.google.com/maps/geo?q=1600&output=xml&key=:key
9
- partial.xml: http://maps.google.com/maps/geo?q=sf+ca&output=xml&key=:key
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,3 @@
1
+ # looking up postcode z12 9pp
2
+
3
+
@@ -0,0 +1,2 @@
1
+ # looking up postcode w12 1aa
2
+ 51.503172 -0.241641 W12 9AE
@@ -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
- xmlns:dc="http://purl.org/dc/elements/1.1/"
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,4 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <geonames>
3
+ <status message="missing lat/lng" value="14"/>
4
+ </geonames>
@@ -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>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <geonames>
3
+ <status message="no timezone information found for lat/lng" value="12"/>
4
+ </geonames>
@@ -1 +1,16 @@
1
- <?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.1"><Response><name>sf ca</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>
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"?><kml xmlns="http://earth.google.com/kml/2.1"><Response><name>1600 amphitheatre mtn view ca</name><Status><code>200</code><request>geocode</request></Status><Placemark><address>1600 Amphitheatre Pkwy, Mountain View, CA 94043, 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>Santa Clara</SubAdministrativeAreaName><Locality><LocalityName>Mountain View</LocalityName><Thoroughfare><ThoroughfareName>1600 Amphitheatre Pkwy</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>94043</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails><Point><coordinates>-122.083739,37.423021,0</coordinates></Point></Placemark></Response></kml>
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"?><kml xmlns="http://earth.google.com/kml/2.1"><Response><name>1600</name><Status><code>602</code><request>geocode</request></Status></Response></kml>
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 First Ave, Sunnyvale, CA 94089"><Latitude>37.416384</Latitude><Longitude>-122.024853</Longitude><Address>701 FIRST AVE</Address><City>SUNNYVALE</City><State>CA</State><Zip>94089-1019</Zip><Country>US</Country></Result></ResultSet>
3
- <!-- ws06.search.re2.yahoo.com uncompressed/chunked Wed Apr 25 15:13:01 PDT 2007 -->
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 -->
@@ -3,4 +3,4 @@
3
3
  The following errors were detected:
4
4
  <Message>unable to parse location</Message>
5
5
  </Error>
6
- <!-- ws05.search.re2.yahoo.com uncompressed/chunked Wed Apr 25 15:13:01 PDT 2007 -->
6
+ <!-- ws03.ydn.re2.yahoo.com uncompressed/chunked Sun Oct 4 17:27:52 PDT 2009 -->
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
1
+ require 'test_helper'
2
2
 
3
3
  module Graticule
4
4
  module Distance
@@ -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
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
1
+ require 'test_helper'
2
2
 
3
3
  module Graticule
4
4
  module Geocoder
@@ -1,5 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
2
-
1
+ require 'test_helper'
3
2
 
4
3
  module Graticule
5
4
 
@@ -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 File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
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(:key => 'APP_ID')
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.083739,
22
- :latitude => 37.423021,
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
- # <?xml version='1.0' encoding='UTF-8'?><kml xmlns='http://earth.google.com/kml/2.0'><Response><name>15-17 </name><Status><code>200</code><request>geocode</request></Status><Placemark id='p1'><Point><coordinates>-17.000000,15.000000,0</coordinates></Point></Placemark></Response></kml>
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.418333,
67
- :latitude => 37.775000,
68
- :precision => :city
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,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
1
+ require 'test_helper'
2
2
 
3
3
  module Graticule
4
4
  module Geocoder
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
1
+ require 'test_helper'
2
2
 
3
3
  module Graticule
4
4
  module Geocoder
@@ -1,9 +1,11 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
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 => :city,
35
+ :precision => :locality,
34
36
  :region => "NY",
35
37
  :street => nil
36
38
  )
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
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 File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
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 => "London",
13
+ :locality => "LONDON",
14
14
  :postal_code => "W1",
15
15
  :country => "GB",
16
16
  :longitude => -0.14839,
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
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 First Ave",
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.024853,
18
- :latitude => 37.416384,
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 File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
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 File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
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