graticule 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 47fedf16b0ffe4698090ec1155d88e251913daf4
4
+ data.tar.gz: f142b7298a24e38b1737e803661bf3aa8565de7b
5
+ SHA512:
6
+ metadata.gz: 233a07082a35178fd72e240f07fc90f4b072dabbe6b6d070ea2a21cabc8299aadf16c6913c87804c7c7e6becb9575635fdbba1047c5dd10b6ef024509e87a326
7
+ data.tar.gz: c0aedc447cfb0150ef65465741123edeb6b630582fa395aed114d8de4c1e38c454bc493d88da9a72c0270a4fde1267db5b773ee25e6425fc23457b78775dbd1e
@@ -2,6 +2,9 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
+ - 2.1.1
6
+ before_install:
7
+ - sudo apt-get install libxslt-dev libxml2-dev
5
8
  before_script:
6
9
  - cp test/config.yml.default test/config.yml
7
10
  only:
@@ -1,3 +1,8 @@
1
+ 2.5.0 (2014-09-04)
2
+ * Add Mapbox geocoder
3
+ * Add Open MapQuest
4
+ * Use Nokogiri
5
+
1
6
  2.4.0 (--)
2
7
  * Update MapQuest handler to use the current API
3
8
 
data/Gemfile CHANGED
@@ -5,3 +5,4 @@ gemspec
5
5
  gem 'mocha'
6
6
  gem 'rake'
7
7
  gem 'rdoc'
8
+ gem "minitest", "~> 4.0"
data/README.md CHANGED
@@ -8,6 +8,7 @@ Graticule
8
8
 
9
9
  Graticule is a geocoding API for looking up address coordinates and performing distance calculations. It supports many popular APIs:
10
10
 
11
+ * Mapbox
11
12
  * Yahoo
12
13
  * Google
13
14
  * MapQuest
@@ -44,7 +45,7 @@ geocoder = Graticule.service(:google).new "api_key"
44
45
  location = geocoder.locate("61 East 9th Street, Holland, MI")
45
46
  ```
46
47
 
47
- For specific service documentation, please visit the [RDOCS -- rdoc.info link].
48
+ For specific service documentation, please visit the [documentation](http://rdoc.info/github/collectiveidea/graticule).
48
49
 
49
50
  #### Distance Calculation
50
51
 
@@ -101,7 +102,7 @@ Here are some ways you can contribute:
101
102
 
102
103
  ### Submitting an Issue
103
104
 
104
- We use the [GitHub issue tracker](https://github.com/collectiveidea/graticule/issues) to track bugs and features. Before submitting a bug report or feature request, check to make sure it hasn't already been submitted. When submitting a bug report, please include a [Gist](https://gist.github.com/) that includes a stack trace and any details that may be necessary to reproduce the bug, including your gem version, Ruby version, and operating system.
105
+ We use the [GitHub issue tracker](https://github.com/collectiveidea/graticule/issues) to track bugs and features. Before submitting a bug report or feature request, check to make sure it hasn't already been submitted. When submitting a bug report, please include a [Gist](https://gist.github.com/) that includes a stack trace and any details that may be necessary to reproduce the bug, including your gem version, Ruby version, and operating system.
105
106
 
106
107
  ### Submitting a Pull Request
107
108
 
@@ -6,8 +6,8 @@ Gem::Specification.new do |spec|
6
6
  spec.name = "graticule"
7
7
  spec.version = Graticule::VERSION
8
8
 
9
- spec.authors = ["Brandon Keepers", "Daniel Morrison", "Collective Idea"]
10
- spec.email = ["brandon@opensoul.org", "daniel@collectiveidea.com", "code@collectiveidea.com"]
9
+ spec.authors = ["Brandon Keepers", "Daniel Morrison", "Jason Roelofs", "Collective Idea"]
10
+ spec.email = ["brandon@opensoul.org", "daniel@collectiveidea.com", "jasongroelofs@gmail.com", "code@collectiveidea.com"]
11
11
  spec.description = "Graticule is a geocoding API that provides a common interface to all the popular services, including Google, Yahoo, Geocoder.us, and MetaCarta."
12
12
  spec.summary = "API for using all the popular geocoding services"
13
13
  spec.homepage = "https://github.com/collectiveidea/graticule"
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency "activesupport"
22
22
  spec.add_dependency "i18n"
23
- spec.add_dependency "happymapper", ">= 0.3.0"
23
+ spec.add_dependency "nokogiri-happymapper", ">= 0.5.9"
24
24
  spec.add_dependency "json"
25
25
  end
26
26
 
@@ -1,8 +1,12 @@
1
1
  # encoding: UTF-8
2
2
  $:.unshift(File.dirname(__FILE__))
3
3
 
4
- require 'active_support'
5
- require 'active_support/core_ext'
4
+ require 'active_support/inflections'
5
+ require 'active_support/core_ext/class/attribute'
6
+ require 'active_support/core_ext/hash/keys'
7
+ require 'active_support/core_ext/object/blank'
8
+ require 'active_support/core_ext/object/with_options'
9
+ require 'active_support/core_ext/string/inflections'
6
10
 
7
11
  require 'graticule/version'
8
12
  require 'graticule/core_ext'
@@ -24,6 +28,7 @@ require 'graticule/geocoder/freethepostcode'
24
28
  require 'graticule/geocoder/multimap'
25
29
  require 'graticule/geocoder/mapquest'
26
30
  require 'graticule/geocoder/simple_geo'
31
+ require 'graticule/geocoder/mapbox'
27
32
  require 'graticule/distance'
28
33
  require 'graticule/distance/haversine'
29
34
  require 'graticule/distance/spherical'
@@ -81,7 +81,6 @@ module Graticule #:nodoc:
81
81
  check_error(response)
82
82
  return parse_response(response)
83
83
  rescue OpenURI::HTTPError => e
84
- raise e.inspect
85
84
  check_error(prepare_response(e.io.read))
86
85
  raise
87
86
  end
@@ -33,9 +33,9 @@ module Graticule #:nodoc:
33
33
  class Point
34
34
  include HappyMapper
35
35
  tag 'Point'
36
- namespace 'http://www.w3.org/2003/01/geo/wgs84_pos#'
36
+ namespace 'geo'
37
37
 
38
- element :description, String, :namespace => 'http://purl.org/dc/elements/1.1/'
38
+ element :description, String, :namespace => 'dc'
39
39
  element :longitude, Float, :tag => 'long'
40
40
  element :latitude, Float, :tag => 'lat'
41
41
  end
@@ -0,0 +1,109 @@
1
+ module Graticule
2
+ module Geocoder
3
+ class Mapbox < Base
4
+ BASE_URL = "http://api.tiles.mapbox.com"
5
+
6
+ def initialize(api_key)
7
+ @api_key = api_key
8
+ end
9
+
10
+ def locate(address)
11
+ get :q => address
12
+ end
13
+
14
+ protected
15
+
16
+ # A result looks like:
17
+ # [
18
+ # {
19
+ # "id"=>"address.110173544177",
20
+ # "lon"=>-122.02912,
21
+ # "lat"=>37.33054,
22
+ # "name"=>"1 Infinite Loop",
23
+ # "type"=>"address"
24
+ # }, {
25
+ # "id"=>"mapbox-places.95014",
26
+ # "name"=>"Cupertino",
27
+ # "type"=>"city"
28
+ # }, {
29
+ # "id"=>"province.1112151813",
30
+ # "name"=>"California",
31
+ # "type"=>"province"
32
+ # }, {
33
+ # "id"=>"country.4150104525",
34
+ # "name"=>"United States",
35
+ # "type"=>"country"
36
+ # }
37
+ # ]
38
+ class Result
39
+ attr_accessor :lat, :lon, :address, :city, :province, :country, :precision, :postal_code
40
+
41
+ def initialize(input)
42
+ self.precision = ::Graticule::Precision::Unknown
43
+ self.lat = input.first["lat"]
44
+ self.lon = input.first["lon"]
45
+
46
+ input.each do |tuple|
47
+ case tuple["type"]
48
+ when "zipcode"
49
+ self.postal_code = tuple["name"]
50
+ set_higher_precision(::Graticule::Precision::PostalCode)
51
+ when "address"
52
+ self.address = tuple["name"]
53
+ set_higher_precision(::Graticule::Precision::Address)
54
+ when "city"
55
+ self.city = tuple["name"]
56
+ set_higher_precision(::Graticule::Precision::Locality)
57
+ self.postal_code = tuple["id"].split(".")[1]
58
+ when "province"
59
+ self.province = tuple["name"]
60
+ set_higher_precision(::Graticule::Precision::Region)
61
+ when "country"
62
+ self.country = tuple["name"]
63
+ set_higher_precision(::Graticule::Precision::Country)
64
+ end
65
+ end
66
+ end
67
+
68
+ private
69
+
70
+ def set_higher_precision(p)
71
+ if self.precision < p
72
+ self.precision = p
73
+ end
74
+ end
75
+ end
76
+
77
+ def make_url(params)
78
+ query = URI.escape(params[:q].to_s)
79
+ url = "#{BASE_URL}/v3/#{@api_key}/geocode/#{query}.json"
80
+
81
+ URI.parse(url)
82
+ end
83
+
84
+ def check_error(response)
85
+ raise AddressError, 'unknown address' if (response["results"].nil? || response["results"].empty?)
86
+ end
87
+
88
+ def prepare_response(response)
89
+ JSON.parse(response)
90
+ end
91
+
92
+ def parse_response(response)
93
+ # Pull data from the first result since we get a bunch
94
+ result = Result.new(response["results"][0])
95
+
96
+ Location.new(
97
+ :latitude => result.lat,
98
+ :longitude => result.lon,
99
+ :street => result.address,
100
+ :locality => result.city,
101
+ :region => result.province,
102
+ :postal_code => result.postal_code,
103
+ :country => result.country,
104
+ :precision => result.precision
105
+ )
106
+ end
107
+ end
108
+ end
109
+ end
@@ -11,9 +11,14 @@ module Graticule #:nodoc:
11
11
  #
12
12
  class Mapquest < Base
13
13
 
14
- def initialize(api_key)
14
+ def initialize(api_key, open = false, restrict_to_country = nil)
15
15
  @api_key = api_key
16
- @url = URI.parse('http://www.mapquestapi.com/geocoding/v1/address')
16
+ @url = if open
17
+ URI.parse('http://open.mapquestapi.com/geocoding/v1/address')
18
+ else
19
+ URI.parse('http://www.mapquestapi.com/geocoding/v1/address')
20
+ end
21
+ @country_filter = restrict_to_country
17
22
  end
18
23
 
19
24
  # Locates +address+ returning a Location
@@ -97,7 +102,11 @@ module Graticule #:nodoc:
97
102
 
98
103
  # Extracts a location from +xml+.
99
104
  def parse_response(response) #:nodoc:
100
- addr = response.result.locations.addresses.first
105
+ if @country_filter
106
+ addr = response.result.locations.addresses.select{|address| address.country == @country_filter}.first
107
+ else
108
+ addr = response.result.locations.addresses.first
109
+ end
101
110
  Location.new(
102
111
  :latitude => addr.latitude,
103
112
  :longitude => addr.longitude,
@@ -36,11 +36,28 @@ module Graticule #:nodoc:
36
36
 
37
37
  private
38
38
 
39
+ class Country
40
+ include HappyMapper
41
+
42
+ register_namespace "xmlns", "urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"
43
+
44
+ tag "Country"
45
+
46
+ element :street, String, :deep => true, :tag => 'ThoroughfareName'
47
+ element :locality, String, :deep => true, :tag => 'LocalityName'
48
+ element :region, String, :deep => true, :tag => 'AdministrativeAreaName'
49
+ element :postal_code, String, :deep => true, :tag => 'PostalCodeNumber'
50
+ element :country, String, :deep => true, :tag => 'CountryNameCode'
51
+ end
52
+
39
53
  class GeocoderMetaData
40
54
  include HappyMapper
41
55
 
42
- tag 'GeocoderMetaData'
43
- namespace 'http://maps.yandex.ru/geocoder/1.x'
56
+ register_namespace "xmlns", "http://maps.yandex.ru/geocoder/1.x"
57
+
58
+ tag "GeocoderMetaData"
59
+
60
+ has_one :address, Country
44
61
 
45
62
  element :kind, String, :tag => 'kind'
46
63
  end
@@ -48,8 +65,9 @@ module Graticule #:nodoc:
48
65
  class FeatureMember
49
66
  include HappyMapper
50
67
 
51
- tag 'featureMember'
52
- namespace 'http://www.opengis.net/gml'
68
+ register_namespace "xmlns", "http://www.opengis.net/gml"
69
+
70
+ tag "featureMember"
53
71
 
54
72
  has_one :geocoder_meta_data, GeocoderMetaData
55
73
 
@@ -57,14 +75,6 @@ module Graticule #:nodoc:
57
75
 
58
76
  element :coordinates, String, :tag => 'pos', :deep => true
59
77
 
60
- with_options :deep => true, :namespace => 'urn:oasis:names:tc:ciq:xsdschema:xAL:2.0' do |map|
61
- map.element :street, String, :tag => 'ThoroughfareName'
62
- map.element :locality, String, :tag => 'LocalityName'
63
- map.element :region, String, :tag => 'AdministrativeAreaName'
64
- map.element :postal_code, String, :tag => 'PostalCodeNumber'
65
- map.element :country, String, :tag => 'CountryNameCode'
66
- end
67
-
68
78
  def coordinates=(coordinates)
69
79
  @longitude, @latitude = coordinates.split(' ').map { |v| v.to_f }
70
80
  end
@@ -78,6 +88,7 @@ module Graticule #:nodoc:
78
88
  include HappyMapper
79
89
 
80
90
  tag 'error'
91
+
81
92
  element :status, Integer, :tag => 'status'
82
93
  element :message, String, :tag => 'message'
83
94
  end
@@ -85,9 +96,19 @@ module Graticule #:nodoc:
85
96
  class Response
86
97
  include HappyMapper
87
98
 
99
+ register_namespace 'xmlns', 'http://maps.yandex.ru/ymaps/1.x'
100
+
88
101
  tag 'GeoObjectCollection'
102
+
89
103
  has_many :feature_members, FeatureMember
90
104
 
105
+ with_nokogiri_config do |config|
106
+ config.nsclean
107
+ config.strict
108
+ config.dtdload
109
+ config.dtdvalid
110
+ end
111
+
91
112
  def status
92
113
  200
93
114
  end
@@ -102,9 +123,9 @@ module Graticule #:nodoc:
102
123
  Location.new(
103
124
  :latitude => result.latitude,
104
125
  :longitude => result.longitude,
105
- :street => result.street,
106
- :locality => result.locality,
107
- :country => result.country,
126
+ :street => result.geocoder_meta_data.address.street,
127
+ :locality => result.geocoder_meta_data.address.locality,
128
+ :country => result.geocoder_meta_data.address.country,
108
129
  :precision => result.precision
109
130
  )
110
131
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: UTF-8
2
2
  module Graticule
3
- VERSION = '2.4.0' unless defined?(::Graticule::VERSION)
3
+ VERSION = '2.5.0' unless defined?(::Graticule::VERSION)
4
4
  end
@@ -0,0 +1 @@
1
+ {"query":["asdfjkl"],"attribution":{"mapbox-places":"<a href='https://www.mapbox.com/about/maps/' target='_blank'>&copy; Mapbox &copy; OpenStreetMap</a> <a class='mapbox-improve-map' href='https://www.mapbox.com/map-feedback/' target='_blank'>Improve this map</a>"},"results":[]}
@@ -0,0 +1 @@
1
+ {"query":["asdfjkl"],"attribution":{"mapbox-places":"<a href='https://www.mapbox.com/about/maps/' target='_blank'>&copy; Mapbox &copy; OpenStreetMap</a> <a class='mapbox-improve-map' href='https://www.mapbox.com/map-feedback/' target='_blank'>Improve this map</a>"}}
@@ -0,0 +1 @@
1
+ {"query":["1","infinite","loop","cupertino","ca"],"attribution":{"mapbox-places":"<a href='https://www.mapbox.com/about/maps/' target='_blank'>&copy; Mapbox &copy; OpenStreetMap</a> <a class='mapbox-improve-map' href='https://www.mapbox.com/map-feedback/' target='_blank'>Improve this map</a>"},"results":[[{"id":"address.110173544177","lon":-122.02912,"lat":37.33054,"name":"1 Infinite Loop","type":"address"},{"id":"mapbox-places.95014","name":"Cupertino","type":"city"},{"id":"province.1112151813","name":"California","type":"province"},{"id":"country.4150104525","name":"United States","type":"country"}]]}
@@ -0,0 +1,171 @@
1
+ <response>
2
+ <info>
3
+ <statusCode>0</statusCode>
4
+ <messages/>
5
+ <copyright>
6
+ <imageUrl>http://api.mqcdn.com/res/mqlogo.gif</imageUrl>
7
+ <imageAltText>© 2014 MapQuest, Inc.</imageAltText>
8
+ <text>© 2014 MapQuest, Inc.</text>
9
+ </copyright>
10
+ </info>
11
+ <results>
12
+ <result>
13
+ <providedLocation>
14
+ <location>12345 US</location>
15
+ </providedLocation>
16
+ <locations>
17
+ <location>
18
+ <street/>
19
+ <adminArea5 type="City">Us</adminArea5>
20
+ <adminArea3 type="State">Ile-de-France</adminArea3>
21
+ <adminArea4 type="County">Pontoise</adminArea4>
22
+ <postalCode/>
23
+ <adminArea1 type="Country">FR</adminArea1>
24
+ <geocodeQuality>CITY</geocodeQuality>
25
+ <geocodeQualityCode>A5XXX</geocodeQualityCode>
26
+ <dragPoint>false</dragPoint>
27
+ <sideOfStreet>N</sideOfStreet>
28
+ <displayLatLng>
29
+ <latLng>
30
+ <lat>49.100945</lat>
31
+ <lng>1.967247</lng>
32
+ </latLng>
33
+ </displayLatLng>
34
+ <linkId>0</linkId>
35
+ <type>s</type>
36
+ <latLng>
37
+ <lat>49.100945</lat>
38
+ <lng>1.967247</lng>
39
+ </latLng>
40
+ <mapUrl>
41
+ <![CDATA[
42
+ http://open.mapquestapi.com/staticmap/v4/getmap?key=Fmjtd|luub2hutnq,8w=o5-9utlur&type=map&size=225,160&pois=purple-1,49.1009451,1.9672466,0,0|&center=49.1009451,1.9672466&zoom=12&rand=-1921049987
43
+ ]]>
44
+ </mapUrl>
45
+ </location>
46
+ <location>
47
+ <street/>
48
+ <adminArea5 type="City">Us</adminArea5>
49
+ <adminArea3 type="State">Bourgogne</adminArea3>
50
+ <adminArea4 type="County">Louhans</adminArea4>
51
+ <postalCode/>
52
+ <adminArea1 type="Country">FR</adminArea1>
53
+ <geocodeQuality>CITY</geocodeQuality>
54
+ <geocodeQualityCode>A5XXX</geocodeQualityCode>
55
+ <dragPoint>false</dragPoint>
56
+ <sideOfStreet>N</sideOfStreet>
57
+ <displayLatLng>
58
+ <latLng>
59
+ <lat>46.818792</lat>
60
+ <lng>5.281419</lng>
61
+ </latLng>
62
+ </displayLatLng>
63
+ <linkId>0</linkId>
64
+ <type>s</type>
65
+ <latLng>
66
+ <lat>46.818792</lat>
67
+ <lng>5.281419</lng>
68
+ </latLng>
69
+ <mapUrl>
70
+ <![CDATA[
71
+ http://open.mapquestapi.com/staticmap/v4/getmap?key=Fmjtd|luub2hutnq,8w=o5-9utlur&type=map&size=225,160&pois=purple-2,46.8187918,5.2814186,0,0|&center=46.8187918,5.2814186&zoom=12&rand=-1921049987
72
+ ]]>
73
+ </mapUrl>
74
+ </location>
75
+ <location>
76
+ <street/>
77
+ <adminArea5 type="City">Us</adminArea5>
78
+ <adminArea3 type="State"/>
79
+ <adminArea4 type="County"/>
80
+ <postalCode/>
81
+ <adminArea1 type="Country">ID</adminArea1>
82
+ <geocodeQuality>CITY</geocodeQuality>
83
+ <geocodeQualityCode>A5XXX</geocodeQualityCode>
84
+ <dragPoint>false</dragPoint>
85
+ <sideOfStreet>N</sideOfStreet>
86
+ <displayLatLng>
87
+ <latLng>
88
+ <lat>-2.771829</lat>
89
+ <lng>132.186285</lng>
90
+ </latLng>
91
+ </displayLatLng>
92
+ <linkId>0</linkId>
93
+ <type>s</type>
94
+ <latLng>
95
+ <lat>-2.771829</lat>
96
+ <lng>132.186285</lng>
97
+ </latLng>
98
+ <mapUrl>
99
+ <![CDATA[
100
+ http://open.mapquestapi.com/staticmap/v4/getmap?key=Fmjtd|luub2hutnq,8w=o5-9utlur&type=map&size=225,160&pois=purple-3,-2.771829,132.1862852,0,0|&center=-2.771829,132.1862852&zoom=12&rand=-1921049987
101
+ ]]>
102
+ </mapUrl>
103
+ </location>
104
+ <location>
105
+ <street/>
106
+ <adminArea5 type="City"/>
107
+ <adminArea3 type="State">LA</adminArea3>
108
+ <adminArea4 type="County">Ascension Parish</adminArea4>
109
+ <postalCode>12345</postalCode>
110
+ <adminArea1 type="Country">US</adminArea1>
111
+ <geocodeQuality>ZIP</geocodeQuality>
112
+ <geocodeQualityCode>Z1XXA</geocodeQualityCode>
113
+ <dragPoint>false</dragPoint>
114
+ <sideOfStreet>N</sideOfStreet>
115
+ <displayLatLng>
116
+ <latLng>
117
+ <lat>30.280046</lat>
118
+ <lng>-90.786583</lng>
119
+ </latLng>
120
+ </displayLatLng>
121
+ <linkId>0</linkId>
122
+ <type>s</type>
123
+ <latLng>
124
+ <lat>30.280046</lat>
125
+ <lng>-90.786583</lng>
126
+ </latLng>
127
+ <mapUrl>
128
+ <![CDATA[
129
+ http://open.mapquestapi.com/staticmap/v4/getmap?key=Fmjtd|luub2hutnq,8w=o5-9utlur&type=map&size=225,160&pois=purple-4,30.2800464733256,-90.7865829472683,0,0|&center=30.2800464733256,-90.7865829472683&zoom=12&rand=-1921049987
130
+ ]]>
131
+ </mapUrl>
132
+ </location>
133
+ <location>
134
+ <street/>
135
+ <adminArea5 type="City">Uz</adminArea5>
136
+ <adminArea3 type="State">Midi-Pyrénées</adminArea3>
137
+ <adminArea4 type="County">Argelès-Gazost</adminArea4>
138
+ <postalCode/>
139
+ <adminArea1 type="Country">FR</adminArea1>
140
+ <geocodeQuality>CITY</geocodeQuality>
141
+ <geocodeQualityCode>A5XXX</geocodeQualityCode>
142
+ <dragPoint>false</dragPoint>
143
+ <sideOfStreet>N</sideOfStreet>
144
+ <displayLatLng>
145
+ <latLng>
146
+ <lat>42.966369</lat>
147
+ <lng>-0.085232</lng>
148
+ </latLng>
149
+ </displayLatLng>
150
+ <linkId>0</linkId>
151
+ <type>s</type>
152
+ <latLng>
153
+ <lat>42.966369</lat>
154
+ <lng>-0.085232</lng>
155
+ </latLng>
156
+ <mapUrl>
157
+ <![CDATA[
158
+ http://open.mapquestapi.com/staticmap/v4/getmap?key=Fmjtd|luub2hutnq,8w=o5-9utlur&type=map&size=225,160&pois=purple-5,42.9663688,-0.0852324,0,0|&center=42.9663688,-0.0852324&zoom=12&rand=-1921049987
159
+ ]]>
160
+ </mapUrl>
161
+ </location>
162
+ </locations>
163
+ </result>
164
+ </results>
165
+ <options>
166
+ <maxResults>-1</maxResults>
167
+ <thumbMaps>true</thumbMaps>
168
+ <ignoreLatLngInput>false</ignoreLatLngInput>
169
+ <boundingBox/>
170
+ </options>
171
+ </response>
@@ -0,0 +1,43 @@
1
+ # encoding: UTF-8
2
+ require 'test_helper'
3
+
4
+ module Graticule
5
+ module Geocoder
6
+ class MapboxTest < Test::Unit::TestCase
7
+ def setup
8
+ @geocoder = Mapbox.new("api_key")
9
+ end
10
+
11
+ def test_locate_success
12
+ URI::HTTP.responses << response("mapbox", "success", "json")
13
+
14
+ expected = Location.new(
15
+ :country => "United States",
16
+ :latitude => 37.33054,
17
+ :longitude => -122.02912,
18
+ :street => "1 Infinite Loop",
19
+ :locality => "Cupertino",
20
+ :region => "California",
21
+ :postal_code => "95014",
22
+ :precision => :address
23
+ )
24
+
25
+ actual = @geocoder.locate("1 Infinite Loop, Cupertino, CA")
26
+
27
+ assert_equal(expected, actual)
28
+ end
29
+
30
+ def test_locate_not_found
31
+ URI::HTTP.responses << response("mapbox", "empty_results", "json")
32
+
33
+ assert_raises(AddressError) { @geocoder.locate 'asdfjkl' }
34
+ end
35
+
36
+ def test_no_results_returned
37
+ URI::HTTP.responses << response("mapbox", "no_results", "json")
38
+
39
+ assert_raises(AddressError) { @geocoder.locate 'asdfjkl' }
40
+ end
41
+ end
42
+ end
43
+ end
@@ -7,10 +7,10 @@ module Graticule
7
7
  def setup
8
8
  URI::HTTP.responses = []
9
9
  URI::HTTP.uris = []
10
- @geocoder = Mapquest.new('api_key')
11
10
  end
12
11
 
13
12
  def test_success
13
+ @geocoder = Mapquest.new('api_key')
14
14
  prepare_response(:success)
15
15
  location = Location.new(
16
16
  :country => "US",
@@ -26,6 +26,7 @@ module Graticule
26
26
  end
27
27
 
28
28
  def test_multi_result
29
+ @geocoder = Mapquest.new('api_key')
29
30
  prepare_response(:multi_result)
30
31
  location = Location.new(
31
32
  :country => "US",
@@ -40,6 +41,22 @@ module Graticule
40
41
  assert_equal(location, @geocoder.locate('217 Union St., NY'))
41
42
  end
42
43
 
44
+ def test_multi_country
45
+ @geocoder = Mapquest.new('api_key', false, 'US')
46
+ prepare_response(:multi_country_success)
47
+ location = Location.new(
48
+ :country => "US",
49
+ :latitude => 30.280046,
50
+ :locality => "",
51
+ :longitude => -90.786583,
52
+ :postal_code => "12345",
53
+ :precision => :postal_code,
54
+ :region => "LA",
55
+ :street => nil
56
+ )
57
+ assert_equal(location, @geocoder.locate('12345 us'))
58
+ end
59
+
43
60
  def test_query_construction
44
61
  request = Mapquest::Request.new("217 Union St., NY", "api_key")
45
62
  query = %Q{key=api_key&outFormat=xml&inFormat=kvp&location=217%20Union%20St.,%20NY}
metadata CHANGED
@@ -1,80 +1,72 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graticule
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
5
- prerelease:
4
+ version: 2.5.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Brandon Keepers
9
8
  - Daniel Morrison
9
+ - Jason Roelofs
10
10
  - Collective Idea
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-10-07 00:00:00.000000000 Z
14
+ date: 2014-09-04 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
18
18
  requirement: !ruby/object:Gem::Requirement
19
- none: false
20
19
  requirements:
21
- - - ! '>='
20
+ - - ">="
22
21
  - !ruby/object:Gem::Version
23
22
  version: '0'
24
23
  type: :runtime
25
24
  prerelease: false
26
25
  version_requirements: !ruby/object:Gem::Requirement
27
- none: false
28
26
  requirements:
29
- - - ! '>='
27
+ - - ">="
30
28
  - !ruby/object:Gem::Version
31
29
  version: '0'
32
30
  - !ruby/object:Gem::Dependency
33
31
  name: i18n
34
32
  requirement: !ruby/object:Gem::Requirement
35
- none: false
36
33
  requirements:
37
- - - ! '>='
34
+ - - ">="
38
35
  - !ruby/object:Gem::Version
39
36
  version: '0'
40
37
  type: :runtime
41
38
  prerelease: false
42
39
  version_requirements: !ruby/object:Gem::Requirement
43
- none: false
44
40
  requirements:
45
- - - ! '>='
41
+ - - ">="
46
42
  - !ruby/object:Gem::Version
47
43
  version: '0'
48
44
  - !ruby/object:Gem::Dependency
49
- name: happymapper
45
+ name: nokogiri-happymapper
50
46
  requirement: !ruby/object:Gem::Requirement
51
- none: false
52
47
  requirements:
53
- - - ! '>='
48
+ - - ">="
54
49
  - !ruby/object:Gem::Version
55
- version: 0.3.0
50
+ version: 0.5.9
56
51
  type: :runtime
57
52
  prerelease: false
58
53
  version_requirements: !ruby/object:Gem::Requirement
59
- none: false
60
54
  requirements:
61
- - - ! '>='
55
+ - - ">="
62
56
  - !ruby/object:Gem::Version
63
- version: 0.3.0
57
+ version: 0.5.9
64
58
  - !ruby/object:Gem::Dependency
65
59
  name: json
66
60
  requirement: !ruby/object:Gem::Requirement
67
- none: false
68
61
  requirements:
69
- - - ! '>='
62
+ - - ">="
70
63
  - !ruby/object:Gem::Version
71
64
  version: '0'
72
65
  type: :runtime
73
66
  prerelease: false
74
67
  version_requirements: !ruby/object:Gem::Requirement
75
- none: false
76
68
  requirements:
77
- - - ! '>='
69
+ - - ">="
78
70
  - !ruby/object:Gem::Version
79
71
  version: '0'
80
72
  description: Graticule is a geocoding API that provides a common interface to all
@@ -82,15 +74,16 @@ description: Graticule is a geocoding API that provides a common interface to al
82
74
  email:
83
75
  - brandon@opensoul.org
84
76
  - daniel@collectiveidea.com
77
+ - jasongroelofs@gmail.com
85
78
  - code@collectiveidea.com
86
79
  executables:
87
80
  - geocode
88
81
  extensions: []
89
82
  extra_rdoc_files: []
90
83
  files:
91
- - .autotest
92
- - .gitignore
93
- - .travis.yml
84
+ - ".autotest"
85
+ - ".gitignore"
86
+ - ".travis.yml"
94
87
  - CHANGELOG.txt
95
88
  - Gemfile
96
89
  - LICENSE.txt
@@ -115,6 +108,7 @@ files:
115
108
  - lib/graticule/geocoder/google.rb
116
109
  - lib/graticule/geocoder/host_ip.rb
117
110
  - lib/graticule/geocoder/local_search_maps.rb
111
+ - lib/graticule/geocoder/mapbox.rb
118
112
  - lib/graticule/geocoder/mapquest.rb
119
113
  - lib/graticule/geocoder/multi.rb
120
114
  - lib/graticule/geocoder/multimap.rb
@@ -153,6 +147,10 @@ files:
153
147
  - test/fixtures/responses/local_search_maps/empty.txt
154
148
  - test/fixtures/responses/local_search_maps/not_found.txt
155
149
  - test/fixtures/responses/local_search_maps/success.txt
150
+ - test/fixtures/responses/mapbox/empty_results.json
151
+ - test/fixtures/responses/mapbox/no_results.json
152
+ - test/fixtures/responses/mapbox/success.json
153
+ - test/fixtures/responses/mapquest/multi_country_success.xml
156
154
  - test/fixtures/responses/mapquest/multi_result.xml
157
155
  - test/fixtures/responses/mapquest/success.xml
158
156
  - test/fixtures/responses/multimap/missing_params.xml
@@ -174,6 +172,7 @@ files:
174
172
  - test/graticule/geocoder/google_test.rb
175
173
  - test/graticule/geocoder/host_ip_test.rb
176
174
  - test/graticule/geocoder/local_search_maps_test.rb
175
+ - test/graticule/geocoder/mapbox_test.rb
177
176
  - test/graticule/geocoder/mapquest_test.rb
178
177
  - test/graticule/geocoder/multi_test.rb
179
178
  - test/graticule/geocoder/multimap_test.rb
@@ -188,27 +187,26 @@ files:
188
187
  homepage: https://github.com/collectiveidea/graticule
189
188
  licenses:
190
189
  - MIT
190
+ metadata: {}
191
191
  post_install_message:
192
192
  rdoc_options: []
193
193
  require_paths:
194
194
  - lib
195
195
  required_ruby_version: !ruby/object:Gem::Requirement
196
- none: false
197
196
  requirements:
198
- - - ! '>='
197
+ - - ">="
199
198
  - !ruby/object:Gem::Version
200
199
  version: '0'
201
200
  required_rubygems_version: !ruby/object:Gem::Requirement
202
- none: false
203
201
  requirements:
204
- - - ! '>='
202
+ - - ">="
205
203
  - !ruby/object:Gem::Version
206
204
  version: '0'
207
205
  requirements: []
208
206
  rubyforge_project:
209
- rubygems_version: 1.8.25
207
+ rubygems_version: 2.2.2
210
208
  signing_key:
211
- specification_version: 3
209
+ specification_version: 4
212
210
  summary: API for using all the popular geocoding services
213
211
  test_files:
214
212
  - test/config.yml.default
@@ -237,6 +235,10 @@ test_files:
237
235
  - test/fixtures/responses/local_search_maps/empty.txt
238
236
  - test/fixtures/responses/local_search_maps/not_found.txt
239
237
  - test/fixtures/responses/local_search_maps/success.txt
238
+ - test/fixtures/responses/mapbox/empty_results.json
239
+ - test/fixtures/responses/mapbox/no_results.json
240
+ - test/fixtures/responses/mapbox/success.json
241
+ - test/fixtures/responses/mapquest/multi_country_success.xml
240
242
  - test/fixtures/responses/mapquest/multi_result.xml
241
243
  - test/fixtures/responses/mapquest/success.xml
242
244
  - test/fixtures/responses/multimap/missing_params.xml
@@ -258,6 +260,7 @@ test_files:
258
260
  - test/graticule/geocoder/google_test.rb
259
261
  - test/graticule/geocoder/host_ip_test.rb
260
262
  - test/graticule/geocoder/local_search_maps_test.rb
263
+ - test/graticule/geocoder/mapbox_test.rb
261
264
  - test/graticule/geocoder/mapquest_test.rb
262
265
  - test/graticule/geocoder/multi_test.rb
263
266
  - test/graticule/geocoder/multimap_test.rb
@@ -269,4 +272,3 @@ test_files:
269
272
  - test/graticule/precision_test.rb
270
273
  - test/mocks/uri.rb
271
274
  - test/test_helper.rb
272
- has_rdoc: