graticule 2.5.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 47fedf16b0ffe4698090ec1155d88e251913daf4
4
- data.tar.gz: f142b7298a24e38b1737e803661bf3aa8565de7b
3
+ metadata.gz: 91485c3b1e3be348db8ebfaafa69e7ce5b47f613
4
+ data.tar.gz: 60d765a0b7303994a982035ff0e0370ac36d02c6
5
5
  SHA512:
6
- metadata.gz: 233a07082a35178fd72e240f07fc90f4b072dabbe6b6d070ea2a21cabc8299aadf16c6913c87804c7c7e6becb9575635fdbba1047c5dd10b6ef024509e87a326
7
- data.tar.gz: c0aedc447cfb0150ef65465741123edeb6b630582fa395aed114d8de4c1e38c454bc493d88da9a72c0270a4fde1267db5b773ee25e6425fc23457b78775dbd1e
6
+ metadata.gz: 00eb32e2692ceae1a75b517c91b7ee73c0f7c360c3c95ab217af12cdde92a3c3532f52f1df28d658c7c9d260fdf3e497f1e860797d11abdbbb1fb1ae6435ae8d
7
+ data.tar.gz: f521c98c1472fcfd8331c22c9d593478b8136385047e4a7c3bc4dd4d690d690258ab4b47ad926a7f44eb5691f5d1b7c0c14d143dbac26fa3046442c9cbb397fc
data/.travis.yml CHANGED
@@ -1,17 +1,22 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1.1
3
+ - 2.1
4
+ - 2.2.4
5
+ - 2.3.0
6
+ - ruby-head
6
7
  before_install:
7
8
  - sudo apt-get install libxslt-dev libxml2-dev
9
+ - gem install bundler
8
10
  before_script:
9
11
  - cp test/config.yml.default test/config.yml
10
12
  only:
11
13
  - master
14
+ matrix:
15
+ allow_failures:
16
+ - rvm: ruby-head
12
17
  notifications:
13
18
  email: false
14
19
  webhooks:
15
20
  urls:
16
21
  - http://buildlight.collectiveidea.com/
17
- on_start: true
22
+ on_start: always
data/CHANGELOG.txt CHANGED
@@ -1,3 +1,6 @@
1
+ 2.6.0 (2018-05-31)
2
+ * Update Mapbox to use the current v5 API
3
+
1
4
  2.5.0 (2014-09-04)
2
5
  * Add Mapbox geocoder
3
6
  * Add Open MapQuest
data/Gemfile CHANGED
@@ -5,4 +5,5 @@ gemspec
5
5
  gem 'mocha'
6
6
  gem 'rake'
7
7
  gem 'rdoc'
8
- gem "minitest", "~> 4.0"
8
+ gem "minitest", "~> 4.0"
9
+ gem "test-unit"
data/graticule.gemspec CHANGED
@@ -21,6 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency "activesupport"
22
22
  spec.add_dependency "i18n"
23
23
  spec.add_dependency "nokogiri-happymapper", ">= 0.5.9"
24
- spec.add_dependency "json"
25
24
  end
26
25
 
@@ -3,12 +3,17 @@ module Graticule #:nodoc:
3
3
  module Geocoder #:nodoc:
4
4
  class Geonames < Base
5
5
 
6
- def initialize
7
- @url = URI.parse 'http://ws.geonames.org/timezone'
6
+ def initialize(username)
7
+ @url = URI.parse('http://ws.geonames.org/timezone')
8
+ @username = URI.encode(username)
8
9
  end
9
10
 
10
11
  def time_zone(location)
11
- get :formatted => 'true', :style => 'full', :lat => location.latitude, :lng => location.longitude
12
+ get :formatted => 'true',
13
+ :style => 'full',
14
+ :lat => location.latitude,
15
+ :lng => location.longitude,
16
+ :username => @username
12
17
  end
13
18
 
14
19
  private
@@ -44,8 +44,8 @@ module Graticule #:nodoc:
44
44
  @street_number = component["short_name"]
45
45
  when "route"
46
46
  @route = component["short_name"]
47
- when "locality"
48
- @locality = component["long_name"]
47
+ when "locality", "sublocality"
48
+ @locality = component["long_name"]
49
49
  when "administrative_area_level_1"
50
50
  @region = component["short_name"]
51
51
  when "country"
@@ -1,7 +1,7 @@
1
- module Graticule
2
- module Geocoder
1
+ module Graticule #:nodoc:
2
+ module Geocoder #:nodoc:
3
3
  class Mapbox < Base
4
- BASE_URL = "http://api.tiles.mapbox.com"
4
+ BASE_URL = "http://api.mapbox.com/geocoding/v5/mapbox.places"
5
5
 
6
6
  def initialize(api_key)
7
7
  @api_key = api_key
@@ -13,76 +13,25 @@ module Graticule
13
13
 
14
14
  protected
15
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
16
  class Result
39
- attr_accessor :lat, :lon, :address, :city, :province, :country, :precision, :postal_code
17
+ attr_accessor :lat, :lon, :precision
40
18
 
41
- def initialize(input)
19
+ def initialize(attributes)
42
20
  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
21
+ self.lon = attributes["center"][0]
22
+ self.lat = attributes["center"][1]
74
23
  end
75
24
  end
76
25
 
77
26
  def make_url(params)
78
27
  query = URI.escape(params[:q].to_s)
79
- url = "#{BASE_URL}/v3/#{@api_key}/geocode/#{query}.json"
28
+ url = "#{BASE_URL}/#{query}.json?access_token=#{@api_key}"
80
29
 
81
30
  URI.parse(url)
82
31
  end
83
32
 
84
33
  def check_error(response)
85
- raise AddressError, 'unknown address' if (response["results"].nil? || response["results"].empty?)
34
+ raise AddressError, 'unknown address' if (response["features"].nil? || response["features"].empty?)
86
35
  end
87
36
 
88
37
  def prepare_response(response)
@@ -91,17 +40,11 @@ module Graticule
91
40
 
92
41
  def parse_response(response)
93
42
  # Pull data from the first result since we get a bunch
94
- result = Result.new(response["results"][0])
43
+ result = Result.new(response["features"][0])
95
44
 
96
45
  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
46
+ :latitude => result.lat,
47
+ :longitude => result.lon,
105
48
  )
106
49
  end
107
50
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: UTF-8
2
2
  module Graticule
3
- VERSION = '2.5.0' unless defined?(::Graticule::VERSION)
3
+ VERSION = '2.6.0' unless defined?(::Graticule::VERSION)
4
4
  end
@@ -1 +1,8 @@
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":[]}
1
+ {
2
+ "type": "FeatureCollection",
3
+ "query": [
4
+ "asdfjkl"
5
+ ],
6
+ "features": [],
7
+ "attribution": "NOTICE: © 2017 Mapbox and its suppliers. All rights reserved. Use of this data is subject to the Mapbox Terms of Service (https://www.mapbox.com/about/maps/). This response and the information it contains may not be retained."
8
+ }
@@ -1 +1,8 @@
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>"}}
1
+ {
2
+ "type": "FeatureCollection",
3
+ "query": [
4
+ "asdfjkl"
5
+ ],
6
+ "features": [],
7
+ "attribution": "NOTICE: © 2017 Mapbox and its suppliers. All rights reserved. Use of this data is subject to the Mapbox Terms of Service (https://www.mapbox.com/about/maps/). This response and the information it contains may not be retained."
8
+ }
@@ -1 +1,229 @@
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"}]]}
1
+ {
2
+ "type": "FeatureCollection",
3
+ "query": [
4
+ "1",
5
+ "infinite",
6
+ "loop",
7
+ "cupertino",
8
+ "ca"
9
+ ],
10
+ "features": [
11
+ {
12
+ "id": "address.6395221899832142",
13
+ "type": "Feature",
14
+ "place_type": [
15
+ "address"
16
+ ],
17
+ "relevance": 1,
18
+ "properties": {},
19
+ "text": "Infinite Loop",
20
+ "place_name": "1 Infinite Loop, Cupertino, California 95014, United States",
21
+ "center": [
22
+ -122.03023,
23
+ 37.331524
24
+ ],
25
+ "geometry": {
26
+ "type": "Point",
27
+ "coordinates": [
28
+ -122.03023,
29
+ 37.331524
30
+ ]
31
+ },
32
+ "address": "1",
33
+ "context": [
34
+ {
35
+ "id": "postcode.17583069324210830",
36
+ "text": "95014"
37
+ },
38
+ {
39
+ "id": "place.8489369485676010",
40
+ "wikidata": "Q189471",
41
+ "text": "Cupertino"
42
+ },
43
+ {
44
+ "id": "region.3591",
45
+ "short_code": "US-CA",
46
+ "wikidata": "Q99",
47
+ "text": "California"
48
+ },
49
+ {
50
+ "id": "country.3145",
51
+ "short_code": "us",
52
+ "wikidata": "Q30",
53
+ "text": "United States"
54
+ }
55
+ ]
56
+ },
57
+ {
58
+ "id": "place.8489369485676010",
59
+ "type": "Feature",
60
+ "place_type": [
61
+ "place"
62
+ ],
63
+ "relevance": 0.5,
64
+ "properties": {
65
+ "wikidata": "Q189471"
66
+ },
67
+ "text": "Cupertino",
68
+ "place_name": "Cupertino, California, United States",
69
+ "bbox": [
70
+ -122.143825004601,
71
+ 37.2479929816717,
72
+ -121.995539980292,
73
+ 37.3415970152769
74
+ ],
75
+ "center": [
76
+ -122.0323,
77
+ 37.323
78
+ ],
79
+ "geometry": {
80
+ "type": "Point",
81
+ "coordinates": [
82
+ -122.0323,
83
+ 37.323
84
+ ]
85
+ },
86
+ "context": [
87
+ {
88
+ "id": "region.3591",
89
+ "short_code": "US-CA",
90
+ "wikidata": "Q99",
91
+ "text": "California"
92
+ },
93
+ {
94
+ "id": "country.3145",
95
+ "short_code": "us",
96
+ "wikidata": "Q30",
97
+ "text": "United States"
98
+ }
99
+ ]
100
+ },
101
+ {
102
+ "id": "neighborhood.285073",
103
+ "type": "Feature",
104
+ "place_type": [
105
+ "neighborhood"
106
+ ],
107
+ "relevance": 0.49,
108
+ "properties": {},
109
+ "text": "Calvert",
110
+ "place_name": "Calvert, Cupertino, California 95014, United States",
111
+ "bbox": [
112
+ -122.024501,
113
+ 37.316342,
114
+ -121.986694,
115
+ 37.331914
116
+ ],
117
+ "center": [
118
+ -122.0138,
119
+ 37.3258
120
+ ],
121
+ "geometry": {
122
+ "type": "Point",
123
+ "coordinates": [
124
+ -122.0138,
125
+ 37.3258
126
+ ]
127
+ },
128
+ "context": [
129
+ {
130
+ "id": "postcode.17583069324210830",
131
+ "text": "95014"
132
+ },
133
+ {
134
+ "id": "place.8489369485676010",
135
+ "wikidata": "Q189471",
136
+ "text": "Cupertino"
137
+ },
138
+ {
139
+ "id": "region.3591",
140
+ "short_code": "US-CA",
141
+ "wikidata": "Q99",
142
+ "text": "California"
143
+ },
144
+ {
145
+ "id": "country.3145",
146
+ "short_code": "us",
147
+ "wikidata": "Q30",
148
+ "text": "United States"
149
+ }
150
+ ]
151
+ },
152
+ {
153
+ "id": "country.3179",
154
+ "type": "Feature",
155
+ "place_type": [
156
+ "country"
157
+ ],
158
+ "relevance": 0.3333333333333333,
159
+ "properties": {
160
+ "wikidata": "Q16",
161
+ "short_code": "ca"
162
+ },
163
+ "text": "Canada",
164
+ "place_name": "Canada",
165
+ "bbox": [
166
+ -141.10275,
167
+ 39.943435,
168
+ -47.597809,
169
+ 86.553514
170
+ ],
171
+ "center": [
172
+ -105.750596,
173
+ 55.585901
174
+ ],
175
+ "geometry": {
176
+ "type": "Point",
177
+ "coordinates": [
178
+ -105.750596,
179
+ 55.585901
180
+ ]
181
+ }
182
+ },
183
+ {
184
+ "id": "place.7943223081734240",
185
+ "type": "Feature",
186
+ "place_type": [
187
+ "place"
188
+ ],
189
+ "relevance": 0.3333333333333333,
190
+ "properties": {
191
+ "wikidata": "Q36312"
192
+ },
193
+ "text": "Calgary",
194
+ "place_name": "Calgary, Alberta, Canada",
195
+ "bbox": [
196
+ -114.315773841495,
197
+ 50.842824406804,
198
+ -113.859901837937,
199
+ 51.2124248116277
200
+ ],
201
+ "center": [
202
+ -114.0626,
203
+ 51.0531
204
+ ],
205
+ "geometry": {
206
+ "type": "Point",
207
+ "coordinates": [
208
+ -114.0626,
209
+ 51.0531
210
+ ]
211
+ },
212
+ "context": [
213
+ {
214
+ "id": "region.219693",
215
+ "short_code": "CA-AB",
216
+ "wikidata": "Q1951",
217
+ "text": "Alberta"
218
+ },
219
+ {
220
+ "id": "country.3179",
221
+ "short_code": "ca",
222
+ "wikidata": "Q16",
223
+ "text": "Canada"
224
+ }
225
+ ]
226
+ }
227
+ ],
228
+ "attribution": "NOTICE: © 2017 Mapbox and its suppliers. All rights reserved. Use of this data is subject to the Mapbox Terms of Service (https://www.mapbox.com/about/maps/). This response and the information it contains may not be retained."
229
+ }
@@ -7,14 +7,7 @@ module Graticule
7
7
  def setup
8
8
  URI::HTTP.responses = []
9
9
  URI::HTTP.uris = []
10
- @geocoder = Geonames.new
11
- end
12
-
13
- def test_time_zone
14
- return unless prepare_response(:success)
15
-
16
- chicago = Location.new(:latitude => 41.85, :longitude => -87.65)
17
- assert_equal 'America/Chicago', @geocoder.time_zone(chicago)
10
+ @geocoder = Geonames.new("demo")
18
11
  end
19
12
 
20
13
  def test_time_zone
@@ -5,21 +5,17 @@ module Graticule
5
5
  module Geocoder
6
6
  class MapboxTest < Test::Unit::TestCase
7
7
  def setup
8
+ URI::HTTP.responses = []
9
+ URI::HTTP.uris = []
8
10
  @geocoder = Mapbox.new("api_key")
9
11
  end
10
12
 
11
13
  def test_locate_success
12
- URI::HTTP.responses << response("mapbox", "success", "json")
14
+ prepare_response(:success)
13
15
 
14
16
  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
17
+ :latitude => 37.331524,
18
+ :longitude => -122.03023,
23
19
  )
24
20
 
25
21
  actual = @geocoder.locate("1 Infinite Loop, Cupertino, CA")
@@ -28,16 +24,22 @@ module Graticule
28
24
  end
29
25
 
30
26
  def test_locate_not_found
31
- URI::HTTP.responses << response("mapbox", "empty_results", "json")
27
+ prepare_response(:empty_results)
32
28
 
33
29
  assert_raises(AddressError) { @geocoder.locate 'asdfjkl' }
34
30
  end
35
-
31
+
36
32
  def test_no_results_returned
37
- URI::HTTP.responses << response("mapbox", "no_results", "json")
33
+ prepare_response(:no_results)
38
34
 
39
35
  assert_raises(AddressError) { @geocoder.locate 'asdfjkl' }
40
36
  end
37
+
38
+ protected
39
+
40
+ def prepare_response(id = :success)
41
+ URI::HTTP.responses << response('mapbox', id, 'json')
42
+ end
41
43
  end
42
44
  end
43
45
  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: 2.5.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Keepers
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-09-04 00:00:00.000000000 Z
14
+ date: 2018-05-31 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -55,20 +55,6 @@ dependencies:
55
55
  - - ">="
56
56
  - !ruby/object:Gem::Version
57
57
  version: 0.5.9
58
- - !ruby/object:Gem::Dependency
59
- name: json
60
- requirement: !ruby/object:Gem::Requirement
61
- requirements:
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- version: '0'
65
- type: :runtime
66
- prerelease: false
67
- version_requirements: !ruby/object:Gem::Requirement
68
- requirements:
69
- - - ">="
70
- - !ruby/object:Gem::Version
71
- version: '0'
72
58
  description: Graticule is a geocoding API that provides a common interface to all
73
59
  the popular services, including Google, Yahoo, Geocoder.us, and MetaCarta.
74
60
  email:
@@ -204,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
190
  version: '0'
205
191
  requirements: []
206
192
  rubyforge_project:
207
- rubygems_version: 2.2.2
193
+ rubygems_version: 2.6.3
208
194
  signing_key:
209
195
  specification_version: 4
210
196
  summary: API for using all the popular geocoding services