graticule 0.2.7 → 0.2.8

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/CHANGELOG.txt CHANGED
@@ -1,3 +1,6 @@
1
+ 0.2.8 (2008-10-03)
2
+ * fixed missing files from gem
3
+
1
4
  0.2.7 (2008-10-03)
2
5
  * Adding Multimap geocoder [Tom Taylor]
3
6
  * Added MapQuest geocoder [Andrew Selder]
data/Manifest.txt CHANGED
@@ -22,6 +22,7 @@ lib/graticule/geocoder/local_search_maps.rb
22
22
  lib/graticule/geocoder/map_quest.rb
23
23
  lib/graticule/geocoder/meta_carta.rb
24
24
  lib/graticule/geocoder/multi.rb
25
+ lib/graticule/geocoder/multimap.rb
25
26
  lib/graticule/geocoder/postcode_anywhere.rb
26
27
  lib/graticule/geocoder/rest.rb
27
28
  lib/graticule/geocoder/yahoo.rb
@@ -51,6 +52,9 @@ test/fixtures/responses/local_search_maps/success.txt
51
52
  test/fixtures/responses/meta_carta/bad_address.xml
52
53
  test/fixtures/responses/meta_carta/multiple.xml
53
54
  test/fixtures/responses/meta_carta/success.xml
55
+ test/fixtures/responses/multimap/missing_params.xml
56
+ test/fixtures/responses/multimap/no_matches.xml
57
+ test/fixtures/responses/multimap/success.xml
54
58
  test/fixtures/responses/postcode_anywhere/badkey.xml
55
59
  test/fixtures/responses/postcode_anywhere/canada.xml
56
60
  test/fixtures/responses/postcode_anywhere/empty.xml
@@ -62,11 +66,13 @@ test/mocks/uri.rb
62
66
  test/test_helper.rb
63
67
  test/unit/graticule/distance_test.rb
64
68
  test/unit/graticule/geocoder/geocoder_us_test.rb
69
+ test/unit/graticule/geocoder/geocoders.rb
65
70
  test/unit/graticule/geocoder/google_test.rb
66
71
  test/unit/graticule/geocoder/host_ip_test.rb
67
72
  test/unit/graticule/geocoder/local_search_maps_test.rb
68
73
  test/unit/graticule/geocoder/meta_carta_test.rb
69
74
  test/unit/graticule/geocoder/multi_test.rb
75
+ test/unit/graticule/geocoder/multimap_test.rb
70
76
  test/unit/graticule/geocoder/postcode_anywhere_test.rb
71
77
  test/unit/graticule/geocoder/yahoo_test.rb
72
78
  test/unit/graticule/geocoder_test.rb
@@ -0,0 +1,73 @@
1
+ module Graticule #:nodoc:
2
+ module Geocoder #:nodoc:
3
+
4
+ # Multimap geocoding API
5
+
6
+ class Multimap < Rest
7
+
8
+ # This precision information is not complete.
9
+ # More details should be implemented from:
10
+ # http://www.multimap.com/share/documentation/clientzone/gqcodes.htm
11
+
12
+ PRECISION = {
13
+ "6"=> :country,
14
+ "5" => :state,
15
+ "4" => :postal_code,
16
+ "3" => :city,
17
+ "2" => :street,
18
+ "1" => :address
19
+ }
20
+
21
+ # Web services initializer.
22
+ #
23
+ # The +api_key+ is the Open API key that uniquely identifies your
24
+ # application.
25
+ #
26
+ # See http://www.multimap.com/openapi/
27
+
28
+ def initialize(api_key)
29
+ @api_key = api_key
30
+ @url = URI.parse "http://clients.multimap.com/API/geocode/1.2/#{@api_key}"
31
+ end
32
+
33
+ # Returns a location for an address in the form of a String, Hash or Location.
34
+
35
+ def locate(address)
36
+ location = address.is_a?(String) ? address : location_from_params(address)
37
+ case location
38
+ when String
39
+ get :qs => location
40
+ when Location
41
+ get "street" => location.street,
42
+ "region" => location.region,
43
+ "city" => location.city,
44
+ "postalCode" => location.postal_code,
45
+ "countryCode" => location.country
46
+ end
47
+ end
48
+
49
+ def parse_response(xml)
50
+ r = xml.elements['Results/Location[1]']
51
+ returning Location.new do |location|
52
+
53
+ location.precision = PRECISION[r.attributes['geocodeQuality']] || :unknown
54
+
55
+ location.street = r.elements['Address/Street'].text.titleize unless r.elements['Address/Street'].nil?
56
+ location.locality = r.elements['Address/Areas/Area'].text.titleize unless r.elements['Address/Areas/Area'].nil?
57
+ location.region = r.elements['Address/State'].text.titleize unless r.elements['Address/State'].nil?
58
+ location.postal_code = r.elements['Address/PostalCode'].text unless r.elements['Address/PostalCode'].nil?
59
+ location.country = r.elements['Address/CountryCode'].text
60
+
61
+ location.latitude = r.elements['Point/Lat'].text.to_f
62
+ location.longitude = r.elements['Point/Lon'].text.to_f
63
+ end
64
+ end
65
+
66
+ def check_error(xml)
67
+ error = xml.elements['Results'].attributes['errorCode']
68
+ raise Error, error unless error.nil?
69
+ end
70
+
71
+ end
72
+ end
73
+ end
@@ -2,7 +2,7 @@ module Graticule #:nodoc:
2
2
  module Version #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 7
5
+ TINY = 8
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <Results xmlns="http://clients.multimap.com/API" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+ xsi:schemaLocation="http://clients.multimap.com/API http://clients.multimap.com/Schema/geocode_1.2.xsd"
4
+ errorCode="MM_GEOCODE_REQUIRED_PARAMETERS_MISSING" locationCount="0" />
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <Results xmlns="http://clients.multimap.com/API" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+ xsi:schemaLocation="http://clients.multimap.com/API http://clients.multimap.com/Schema/geocode_1.2.xsd"
4
+ errorCode="MM_GEOCODE_NO_MATCHES" locationCount="0" />
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <Results xmlns="http://clients.multimap.com/API" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+ xsi:schemaLocation="http://clients.multimap.com/API http://clients.multimap.com/Schema/geocode_1.2.xsd" locationCount="1">
4
+ <Location geocodeQuality="1">
5
+ <Address>
6
+ <Street>Oxford Street</Street>
7
+ <Areas>
8
+ <Area>LONDON</Area>
9
+ </Areas>
10
+ <PostalCode>W1</PostalCode>
11
+ <DisplayName>Oxford Street, LONDON, W1</DisplayName>
12
+ <CountryCode>GB</CountryCode>
13
+ </Address>
14
+ <Point>
15
+ <Lat>51.51452</Lat>
16
+ <Lon>-0.14839</Lon>
17
+ </Point>
18
+ </Location>
19
+ </Results>
@@ -0,0 +1,56 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
2
+
3
+
4
+ module Graticule
5
+
6
+ # Generic tests for all geocoders (theoretically)
7
+ module GeocodersTestCase
8
+
9
+ def test_success
10
+ return unless prepare_response(:success)
11
+
12
+ location = Location.new(
13
+ :street => "1600 Amphitheatre Pkwy",
14
+ :city => "Mountain View",
15
+ :state => "CA",
16
+ :zip => "94043",
17
+ :country => "US",
18
+ :longitude => -122.083739,
19
+ :latitude => 37.423021,
20
+ :precision => :address
21
+ )
22
+ assert_equal location, @geocoder.locate('1600 Amphitheatre Parkway, Mountain View, CA')
23
+ end
24
+
25
+ def test_bad_key
26
+ return unless prepare_response(:badkey)
27
+ assert_raises(CredentialsError) { @geocoder.locate('x') }
28
+ end
29
+
30
+ def test_locate_missing_address
31
+ return unless prepare_response(:missing_address)
32
+ assert_raises(AddressError) { @geocoder.locate 'x' }
33
+ end
34
+
35
+ def test_locate_server_error
36
+ return unless prepare_response(:server_error)
37
+ assert_raises(Error) { @geocoder.locate 'x' }
38
+ end
39
+
40
+ def test_locate_too_many_queries
41
+ return unless prepare_response(:limit)
42
+ assert_raises(CredentialsError) { @geocoder.locate 'x' }
43
+ end
44
+
45
+ def test_locate_unavailable_address
46
+ return unless prepare_response(:unavailable)
47
+ assert_raises(AddressError) { @geocoder.locate 'x' }
48
+ end
49
+
50
+ def test_locate_unknown_address
51
+ return unless prepare_response(:unknown_address)
52
+ assert_raises(AddressError) { @geocoder.locate 'x' }
53
+ end
54
+
55
+ end
56
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graticule
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Keepers
@@ -74,6 +74,7 @@ files:
74
74
  - lib/graticule/geocoder/map_quest.rb
75
75
  - lib/graticule/geocoder/meta_carta.rb
76
76
  - lib/graticule/geocoder/multi.rb
77
+ - lib/graticule/geocoder/multimap.rb
77
78
  - lib/graticule/geocoder/postcode_anywhere.rb
78
79
  - lib/graticule/geocoder/rest.rb
79
80
  - lib/graticule/geocoder/yahoo.rb
@@ -103,6 +104,9 @@ files:
103
104
  - test/fixtures/responses/meta_carta/bad_address.xml
104
105
  - test/fixtures/responses/meta_carta/multiple.xml
105
106
  - test/fixtures/responses/meta_carta/success.xml
107
+ - test/fixtures/responses/multimap/missing_params.xml
108
+ - test/fixtures/responses/multimap/no_matches.xml
109
+ - test/fixtures/responses/multimap/success.xml
106
110
  - test/fixtures/responses/postcode_anywhere/badkey.xml
107
111
  - test/fixtures/responses/postcode_anywhere/canada.xml
108
112
  - test/fixtures/responses/postcode_anywhere/empty.xml
@@ -114,11 +118,13 @@ files:
114
118
  - test/test_helper.rb
115
119
  - test/unit/graticule/distance_test.rb
116
120
  - test/unit/graticule/geocoder/geocoder_us_test.rb
121
+ - test/unit/graticule/geocoder/geocoders.rb
117
122
  - test/unit/graticule/geocoder/google_test.rb
118
123
  - test/unit/graticule/geocoder/host_ip_test.rb
119
124
  - test/unit/graticule/geocoder/local_search_maps_test.rb
120
125
  - test/unit/graticule/geocoder/meta_carta_test.rb
121
126
  - test/unit/graticule/geocoder/multi_test.rb
127
+ - test/unit/graticule/geocoder/multimap_test.rb
122
128
  - test/unit/graticule/geocoder/postcode_anywhere_test.rb
123
129
  - test/unit/graticule/geocoder/yahoo_test.rb
124
130
  - test/unit/graticule/geocoder_test.rb