mapbox-sdk 2.0.0 → 2.3.2

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
- SHA1:
3
- metadata.gz: c0484d85c89aade2922c0a0d43b3d3d61c74db5f
4
- data.tar.gz: 0a9304ae7755bbb5121bc237f61b915cdd35596c
2
+ SHA256:
3
+ metadata.gz: 672927337ebb6e2225839694318310798e63a8f4cc64100d96a67d67a2cde23e
4
+ data.tar.gz: 4fea4ca533cf9e8b6b9ff7118e2abffe36ff8d9b72758adabc21391e279dead0
5
5
  SHA512:
6
- metadata.gz: 2664c0e47fc458b1933b3476d7902edbb965613b5326f308b77e07be56f16e5ba2c3193b0abd4ec365e6538e7c7e2db3e7860320a8110f7c23bcfe5c9dad93a4
7
- data.tar.gz: 68f8963b09a9f1b00c76778a79751467ff1d1c636c5454ef6aa934a3124f0daed07e54c6b540f8a151edbcbe0600324936f7a74088e3a9fd3a2d74590aa29995
6
+ metadata.gz: 8a271a83fcb6f562421aceb5c45c0d66bef03fe6d59ef171f3d325936dd9cd01a935e29fd51404a40e39b59d5a9b43d40c9f1fd1d48054d7befff0588e66a43e
7
+ data.tar.gz: a016890aca123c692ec7a72b03cb3bf7395551c958775affde6feed96ad7d25428aa108118cc99615463d94049a1fec7d2b97f814054a6b2bdab9025b81dca75
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.5.1
4
+ install:
5
+ - bundle install
6
+ script:
7
+ - bundle exec ruby -Itest test/all_tests.rb
8
+ after_success:
9
+ - coveralls
@@ -0,0 +1,45 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [2.3.2] - 2020-11-23
8
+ ### Changed
9
+ - Fixed URI.encode obsolete warnings in Ruby 2.7
10
+
11
+ ## [2.3.1] - 2020-11-07
12
+ ### Changed
13
+ - Update to restclient 2.1.0
14
+
15
+ ## [2.3.0] - 2019-01-16
16
+ ### Added
17
+ - Matrix endpoint, docs, and tests
18
+ - Map Matching endpoint, docs, and tests
19
+ - Optimization endpoint, docs, and tests
20
+
21
+ ### Changed
22
+
23
+ ### Removed
24
+
25
+ ## [2.2.0] - 2018-12-14
26
+ ### Added
27
+ - Selection of directions profiles
28
+ - Isochrone endpoint
29
+ - New README/docs folder and organization
30
+
31
+ ### Changed
32
+ - Update to restclient 2.0
33
+ - Parameters to requests for directions
34
+
35
+ ### Removed
36
+
37
+ ## [2.1.0] - 2018-06-07
38
+ ### Added
39
+ - Added CHANGELOG.md
40
+ - Added Tilequery endpoint
41
+
42
+ ### Changed
43
+ - Updated documentation links in README
44
+
45
+ ### Removed
data/Gemfile CHANGED
@@ -3,7 +3,11 @@ gemspec
3
3
 
4
4
  if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('1.9.3')
5
5
  gem 'i18n', '< 0.7'
6
- gem 'rest-client', '~> 1.6.8'
7
- gem 'activesupport', '~> 3.2'
6
+ gem 'rest-client', '~> 2.1.0'
7
+ gem "activesupport", ">= 4.1.11"
8
8
  gem 'rake', '10.1.0'
9
9
  end
10
+
11
+ group :development, :test do
12
+ gem "coveralls", :require => false
13
+ end
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Coverage Status](https://coveralls.io/repos/github/mapbox/mapbox-sdk-rb/badge.svg?branch=master)](https://coveralls.io/github/mapbox/mapbox-sdk-rb?branch=master)
2
+
1
3
  # mapbox-sdk-ruby
2
4
 
3
5
  The `mapbox-sdk` gem. A ruby interface to [Mapbox APIs](https://www.mapbox.com/developers/api/).
@@ -10,35 +12,29 @@ gem install mapbox-sdk
10
12
 
11
13
  ## Services
12
14
 
13
- * [Geocoding](https://www.mapbox.com/developers/api/geocoding/)
15
+ * [Geocoding](https://docs.mapbox.com/api/search/) [[docs](https://github.com/mapbox/mapbox-sdk-rb/blob/master/docs/geocoding.md)]
14
16
  * Forward (place names ⇢ longitude, latitude)
15
17
  * Reverse (longitude, latitude ⇢ place names)
16
- * [Directions](https://www.mapbox.com/developers/api/directions/)
18
+ * [Directions](https://docs.mapbox.com/api/navigation/#directions): [[docs](https://github.com/mapbox/mapbox-sdk-rb/blob/master/docs/directions.md)]
19
+ * Profiles for driving, driving-traffic, walking, and cycling
20
+ * [Tilequery](https://docs.mapbox.com/api/maps/#tilequery): [[docs](https://github.com/mapbox/mapbox-sdk-rb/blob/master/docs/tilequery.md)]
21
+ * [Isochrone](https://docs.mapbox.com/api/navigation/#isochrone): [[docs](https://github.com/mapbox/mapbox-sdk-rb/blob/master/docs/isochrone.md)]
17
22
  * Profiles for driving, walking, and cycling
23
+ * [Matrix](https://docs.mapbox.com/api/navigation/#matrix): [[docs](https://github.com/mapbox/mapbox-sdk-rb/blob/master/docs/matrix.md)]
24
+ * Profiles for driving, driving-traffic, walking, and cycling
25
+ * [Map Matching](https://docs.mapbox.com/api/navigation/#map-matching): [[docs](https://github.com/mapbox/mapbox-sdk-rb/blob/master/docs/mapmatching.md)]
26
+ * Profiles for driving, driving-traffic, walking, and cycling
27
+ * [Optimization](https://docs.mapbox.com/api/navigation/#optimization): [[docs](https://github.com/mapbox/mapbox-sdk-rb/blob/master/docs/optimization.md)]
28
+ * Profiles for driving, driving-traffic, walking, and cycling
29
+
30
+ ## Testing
31
+
32
+ You'll need to [create an access token](https://account.mapbox.com/access-tokens/create) in order to run tests.
18
33
 
19
- ## Example
20
-
21
- ```rb
22
- require "mapbox-sdk"
23
- Mapbox.access_token = "YOUR_ACCESS_TOKEN"
24
-
25
- # Reverse geocoding
26
- placenames = Mapbox::Geocoder.geocode_reverse({
27
- "latitude" => 38,
28
- "longitude" => -100
29
- })
30
-
31
- # Forward geocoding with optional proximity parameter
32
- places = Mapbox::Geocoder.geocode_forward("Chester, NJ", {:proximity => {:longitude => -74.6968, :latitude => 40.7843}})
33
-
34
- # Directions
35
- drivingDirections = Mapbox::Directions.directions([{
36
- "longitude" => -100,
37
- "latitude" => 38
38
- }, {
39
- "longitude" => -90,
40
- "latitude" => 38
41
- }])
34
+ Then you can run the entire test suite with the following command:
35
+
36
+ ```
37
+ MapboxAccessToken=<YOUR_ACCESS_TOKEN> bundle exec ruby -Itest test/all_tests.rb
42
38
  ```
43
39
 
44
40
  Heavily influenced by Stripe's Ruby client, and includes its MIT license.
@@ -0,0 +1,31 @@
1
+ # Directions
2
+
3
+ ```rb
4
+ require "mapbox-sdk"
5
+ Mapbox.access_token = "YOUR_ACCESS_TOKEN"
6
+
7
+ # Driving directions with required profile parameter.
8
+ drivingDirections = Mapbox::Directions.directions([{
9
+ "longitude" => -100,
10
+ "latitude" => 38
11
+ }, {
12
+ "longitude" => -90,
13
+ "latitude" => 38
14
+ }], "driving")
15
+
16
+ # To provide query parameters to the Directions API, such as `geometries`, `language` or `steps`, add those in a Hash as third parameter (find the full list of parameters (here)[https://www.mapbox.com/api-documentation/navigation/#retrieve-directions]).
17
+
18
+ # For instance, to use the `geometries` and `voice_instructions` parameter:
19
+ drivingDirections = Mapbox::Directions.directions([{
20
+ "longitude" => -100,
21
+ "latitude" => 38
22
+ }, {
23
+ "longitude" => -90,
24
+ "latitude" => 38
25
+ }], "driving", {
26
+ geometries: "geojson",
27
+ voice_instructions: true
28
+ })
29
+
30
+ # In the above example, you can substitute `driving` for `driving-traffic`, `cycling` or `walking`. For more, [check out the documentation](https://www.mapbox.com/api-documentation/navigation/#directions).
31
+ ```
@@ -0,0 +1,15 @@
1
+ # Geocoding
2
+
3
+ ```rb
4
+ require "mapbox-sdk"
5
+ Mapbox.access_token = "YOUR_ACCESS_TOKEN"
6
+
7
+ # Reverse geocoding
8
+ placenames = Mapbox::Geocoder.geocode_reverse({
9
+ "latitude": 38,
10
+ "longitude": -100
11
+ })
12
+
13
+ # Forward geocoding with optional proximity parameter
14
+ places = Mapbox::Geocoder.geocode_forward("Chester, NJ", {:proximity => {:longitude => -74.6968, :latitude => 40.7843}})
15
+ ```
@@ -0,0 +1,11 @@
1
+ # Isochrone
2
+
3
+ ```rb
4
+ require "mapbox-sdk"
5
+ Mapbox.access_token = "YOUR_ACCESS_TOKEN"
6
+
7
+ isochrone = Mapbox::Isochrone.isochrone("walking", "-118.22258,33.99038", {contours_minutes: [5,10,15]})
8
+
9
+ # You must include the contours_minutes parameter, as well as a profile (walking, driving, cycling) and the center point coordinate.
10
+ # Optional parameters are contours_colors, polygons, denoise, and generalize. See more on the API documentation page.
11
+ ```
@@ -0,0 +1,43 @@
1
+ # Map Matching
2
+
3
+ ```rb
4
+ require "mapbox-sdk"
5
+ Mapbox.access_token = "YOUR_ACCESS_TOKEN"
6
+
7
+ # Snap fuzzy, inaccurate GPS or phone traces to the road and path network with required profile parameter.
8
+ matching = Mapbox::MapMatching.map_matching([{
9
+ "longitude" => -117.17282,
10
+ "latitude" => 32.71204
11
+ }, {
12
+ "longitude" => -117.17288,
13
+ "latitude" => 32.71225
14
+ }, {
15
+ "longitude" => -117.17293,
16
+ "latitude" => 32.71244
17
+ },{
18
+ "longitude" => -117.17292,
19
+ "latitude" => 32.71256
20
+ }], "driving")
21
+
22
+ # To provide query parameters to the Matrix API, such as `annotations`, `approaches` or `sources`, add those in a Hash as third parameter (find the full list of parameters (here)[https://www.mapbox.com/api-documentation/navigation/#matrix]).
23
+
24
+ # For instance, to use the `geometries` and `voice_instructions` parameter:
25
+ matching = Mapbox::MapMatching.map_matching([{
26
+ "longitude" => -117.17282,
27
+ "latitude" => 32.71204
28
+ }, {
29
+ "longitude" => -117.17288,
30
+ "latitude" => 32.71225
31
+ }, {
32
+ "longitude" => -117.17293,
33
+ "latitude" => 32.71244
34
+ },{
35
+ "longitude" => -117.17292,
36
+ "latitude" => 32.71256
37
+ }], "driving", {
38
+ annotations: ["duration", "distance", "speed"],
39
+ approaches: ["curb","curb","curb","curb"]
40
+ })
41
+
42
+ # In the above example, you can substitute `driving` for `driving-traffic`, `cycling` or `walking`. For more, [check out the documentation](https://docs.mapbox.com/api/navigation/#map-matching).
43
+ ```
@@ -0,0 +1,38 @@
1
+ # Matrix
2
+
3
+ ```rb
4
+ require "mapbox-sdk"
5
+ Mapbox.access_token = "YOUR_ACCESS_TOKEN"
6
+
7
+ # Return travel times between many points, passing in the required profile parameter.
8
+ matrix = Mapbox::Matrix.matrix([{
9
+ "longitude" => -122.42,
10
+ "latitude" => 37.78
11
+ }, {
12
+ "longitude" => -122.45,
13
+ "latitude" => 37.91
14
+ }, {
15
+ "longitude" => -122.48,
16
+ "latitude" => 37.73
17
+ }], "walking")
18
+
19
+ # To provide query parameters to the Matrix API, such as `annotations`, `approaches` or `sources`, add those in a Hash as third parameter (find the full list of parameters (here)[https://www.mapbox.com/api-documentation/navigation/#matrix]).
20
+
21
+ # For instance, to use the `annotations`, `approaches`, and `destinations` parameters:
22
+ matrix = Mapbox::Matrix.matrix([{
23
+ "longitude" => -122.42,
24
+ "latitude" => 37.78
25
+ }, {
26
+ "longitude" => -122.45,
27
+ "latitude" => 37.91
28
+ }, {
29
+ "longitude" => -122.48,
30
+ "latitude" => 37.73
31
+ }], "cycling", {
32
+ annotations: ["duration", "distance"],
33
+ approaches: ["curb","","curb"],
34
+ destinations: [0,1]
35
+ })
36
+
37
+ # In the above example, you can substitute `driving` for `driving-traffic`, `cycling` or `walking`. For more, [check out the documentation](https://www.mapbox.com/api-documentation/navigation/#matrix).
38
+ ```
@@ -0,0 +1,52 @@
1
+ # Optimization
2
+
3
+ ```rb
4
+ require "mapbox-sdk"
5
+ Mapbox.access_token = "YOUR_ACCESS_TOKEN"
6
+
7
+ # Returns a duration-optimized route between coordinates with required profile parameter.
8
+ optimization = Mapbox::Optimization.optimization([{
9
+ "longitude" => -122.42,
10
+ "latitude" => 37.78
11
+ }, {
12
+ "longitude" => -122.45,
13
+ "latitude" => 37.91
14
+ }, {
15
+ "longitude" => -122.48,
16
+ "latitude" => 37.73
17
+ }], "walking")
18
+
19
+ # To provide query parameters to the Matrix API, such as `annotations`, `approaches` or `sources`, add those in a Hash as third parameter (find the full list of parameters (here)[https://www.mapbox.com/api-documentation/navigation/#matrix]).
20
+
21
+ # For instance, to use the `annotations`, `approaches`, and `overview` parameters:
22
+ optimization = Mapbox::Optimization.optimization([{
23
+ "longitude" => -122.42,
24
+ "latitude" => 37.78
25
+ }, {
26
+ "longitude" => -122.45,
27
+ "latitude" => 37.91
28
+ }, {
29
+ "longitude" => -122.48,
30
+ "latitude" => 37.73
31
+ }], "cycling", {
32
+ annotations: ["duration", "distance"],
33
+ approaches: ["curb","curb","curb"],
34
+ overview: "false"
35
+ })
36
+
37
+ # The bearings param works a bit differently. Here's an example, leaving the second bearing blank with an additional `;` character (you must include the same number of bearings as waypoints, per the docs):
38
+ optimization = Mapbox::Optimization.optimization([{
39
+ "longitude" => -122.42,
40
+ "latitude" => 37.78
41
+ }, {
42
+ "longitude" => -122.45,
43
+ "latitude" => 37.91
44
+ }, {
45
+ "longitude" => -122.48,
46
+ "latitude" => 37.73
47
+ }], "driving", {
48
+ bearings: "45,90;;90,1"
49
+ })
50
+
51
+ # In the above example, you can substitute `driving` for `driving-traffic`, `cycling` or `walking`. For more, [check out the documentation](https://docs.mapbox.com/api/navigation/#optimization).
52
+ ```
@@ -0,0 +1,12 @@
1
+ # Tilequery
2
+
3
+ ```rb
4
+ require "mapbox-sdk"
5
+ Mapbox.access_token = "YOUR_ACCESS_TOKEN"
6
+
7
+ tilequery = Mapbox::Tilequery.tilequery(mapid, {location}, radius, limit)
8
+
9
+ # Example: tilequery = Mapbox::Tilequery.tilequery("mapbox.mapbox-streets-v7", {"longitude" => -100, "latitude" => 38}, 0, 1)
10
+ # `Radius` refers to the approximate distance in meters to query for features. Defaults to 0 if left blank. Has no upper bound. Required for queries against point and line data.
11
+ # `Limit` refers to the number of features between 1 - 50 to return. Defaults to 5 if left blank.
12
+ ```
@@ -33,7 +33,7 @@ module Mapbox
33
33
  case method.to_s.downcase.to_sym
34
34
  when :get, :head, :delete
35
35
  # Make params into GET parameters
36
- url += "#{URI.parse(url).query ? '&' : '?'}#{uri_encode(params)}" if params && params.any?
36
+ url += "#{URI.parse(url).query ? '&' : '?'}#{URI.encode_www_form(params)}" if params && params.any?
37
37
  payload = nil
38
38
  end
39
39
 
@@ -78,7 +78,7 @@ module Mapbox
78
78
  end
79
79
 
80
80
  def self.url_encode(key)
81
- URI.escape(key.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
81
+ URI.encode_www_form_component(key.to_s)
82
82
  end
83
83
 
84
84
  def self.execute_request(opts)
@@ -180,3 +180,8 @@ end
180
180
  # services
181
181
  require 'mapbox/geocoder'
182
182
  require 'mapbox/directions'
183
+ require 'mapbox/tilequery'
184
+ require 'mapbox/isochrone'
185
+ require 'mapbox/matrix'
186
+ require 'mapbox/map_matching'
187
+ require 'mapbox/optimization'
@@ -1,16 +1,59 @@
1
- require 'rest-client'
2
- require 'json'
3
-
4
1
  module Mapbox
5
2
  class Directions
6
3
  include Mapbox::APIOperations::Request
7
4
  extend Mapbox::HashUtils
8
- def self.directions(waypoints, profile='mapbox.driving')
5
+
6
+ def self.assemble_params(options={})
7
+ alternatives = options[:alternatives]
8
+ annotations = options[:annotations]
9
+ approaches = options[:approaches]
10
+ banner_instructions = options[:banner_instructions]
11
+ bearings = options[:bearings]
12
+ continue_straight = options[:continue_straight]
13
+ exclude = options[:exclude]
14
+ geometries = options[:geometries]
15
+ language = options[:language]
16
+ overview = options[:overview]
17
+ radiuses = options[:radiuses]
18
+ roundabout_exits = options[:roundabout_exits]
19
+ steps = options[:steps]
20
+ voice_instructions = options[:voice_instructions]
21
+ voice_units = options[:voice_units]
22
+ waypoint_names = options[:waypoint_names]
23
+
24
+ params = ''
25
+ opts = options.select { |key, value| key != :approaches && key != :bearings && key != :radiuses && key != :waypoint_names }
26
+ if opts.length > 0
27
+ params += "#{params.length > 0 ? '&' : '?'}#{URI.encode_www_form(opts)}"
28
+ end
29
+
30
+ if approaches then
31
+ params += "#{params.length > 0 ? '&' : '?'}approaches=#{approaches.join(';')}"
32
+ end
33
+
34
+ if bearings then
35
+ params += "#{params.length > 0 ? '&' : '?'}bearings=#{bearings.map {|p| bearings.join ','}.join ';'}"
36
+ end
37
+
38
+ if radiuses then
39
+ params += "#{params.length > 0 ? '&' : '?'}radiuses=#{radiuses.join ';'}"
40
+ end
41
+
42
+ if waypoint_names then
43
+ params += "#{params.length > 0 ? '&' : '?'}waypoint_names=#{waypoint_names.join ';'}"
44
+ end
45
+
46
+ return params
47
+ end
48
+
49
+ def self.directions(waypoints, profile, options={})
9
50
  formatted_waypoints = waypoints.map {|p| xy_from_hash(p).join ','}.join ';'
51
+ params = self.assemble_params(options)
52
+
10
53
  return request(
11
- :get,
12
- "/v4/directions/#{profile}/#{formatted_waypoints}.json",
13
- nil)
54
+ :get,
55
+ "/directions/v5/mapbox/#{profile}/#{formatted_waypoints}.json#{params}",
56
+ nil)
14
57
  end
15
58
  end
16
- end
59
+ end
@@ -7,11 +7,12 @@ module Mapbox
7
7
  include Mapbox::APIOperations::Request
8
8
  extend Mapbox::HashUtils
9
9
 
10
- def self.geocode_forward(query, options={}, dataset='mapbox.places')
10
+ def self.assemble_params(options={})
11
11
  proximity = options[:proximity]
12
12
  bbox = options[:bbox]
13
+ types = options[:types]
13
14
  params = ''
14
- opts = options.select { |key, value| key != :proximity && key != :bbox}
15
+ opts = options.select { |key, value| key != :proximity && key != :bbox && key != :types}
15
16
  if opts.length > 0
16
17
  params += "#{params.length > 0 ? '&' : '?'}#{URI.encode_www_form(opts)}"
17
18
  end
@@ -25,19 +26,32 @@ module Mapbox
25
26
  if bbox then
26
27
  params += "#{params.length > 0 ? '&' : '?'}bbox=#{bbox.join('%2C')}"
27
28
  end
29
+
30
+ if types then
31
+ params += "#{params.length > 0 ? '&' : '?'}types=#{types.join('%2C')}"
32
+ end
33
+
34
+ return params
35
+ end
36
+
37
+ def self.geocode_forward(query, options={}, dataset='mapbox.places')
38
+ params = self.assemble_params(options)
39
+
28
40
  return request(
29
41
  :get,
30
- "/geocoding/v5/#{dataset}/#{URI.escape(query)}.json#{params}",
42
+ "/geocoding/v5/#{dataset}/#{URI.encode_www_form_component(query)}.json#{params}",
31
43
  nil)
32
44
  end
33
45
 
34
- def self.geocode_reverse(location, dataset='mapbox.places')
46
+ def self.geocode_reverse(location, options={}, dataset='mapbox.places')
35
47
  location[:longitude] = location[:longitude].round(5)
36
48
  location[:latitude] = location[:latitude].round(5)
37
49
 
50
+ params = self.assemble_params(options)
51
+
38
52
  return request(
39
53
  :get,
40
- "/geocoding/v5/#{dataset}/#{xy_from_hash(location).join(',')}.json",
54
+ "/geocoding/v5/#{dataset}/#{xy_from_hash(location).join(',')}.json#{params}",
41
55
  nil)
42
56
  end
43
57
  end
@@ -0,0 +1,35 @@
1
+ module Mapbox
2
+ class Isochrone
3
+ include Mapbox::APIOperations::Request
4
+
5
+ def self.assemble_params(options={})
6
+ contours_minutes = options[:contours_minutes]
7
+ contours_colors = options[:contours_colors]
8
+
9
+ params = ''
10
+ opts = options.select { |key, value| key != :contours_minutes && key != :contours_colors }
11
+ if opts.length > 0
12
+ params += "#{params.length > 0 ? '&' : '?'}#{URI.encode_www_form(opts)}"
13
+ end
14
+
15
+ if contours_minutes then
16
+ params += "#{params.length > 0 ? '&' : '?'}contours_minutes=#{contours_minutes.join(',')}"
17
+ end
18
+
19
+ if contours_colors then
20
+ params += "#{params.length > 0 ? '&' : '?'}contours_colors=#{contours_colors.join(',')}"
21
+ end
22
+
23
+ return params
24
+ end
25
+
26
+ def self.isochrone(profile, coordinates, options={})
27
+ params = self.assemble_params(options)
28
+
29
+ return request(
30
+ :get,
31
+ "/isochrone/v1/mapbox/#{profile}/#{coordinates}#{params}",
32
+ nil)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,57 @@
1
+ module Mapbox
2
+ class MapMatching
3
+ include Mapbox::APIOperations::Request
4
+ extend Mapbox::HashUtils
5
+
6
+ def self.assemble_params(options={})
7
+ annotations = options[:annotations]
8
+ approaches = options[:approaches]
9
+ radiuses = options[:radiuses]
10
+ timestamps = options[:timestamps]
11
+ waypoint_names = options[:waypoint_names]
12
+ waypoints = options[:waypoints]
13
+
14
+ params = ''
15
+ opts = options.select { |key, value| key != :annotations && key != :approaches && key != :radiuses && key != :timestamps && key != :waypoint_names && key != :waypoints }
16
+ if opts.length > 0
17
+ params += "#{params.length > 0 ? '&' : '?'}#{URI.encode_www_form(opts)}"
18
+ end
19
+
20
+ if annotations then
21
+ params += "#{params.length > 0 ? '&' : '?'}annotations=#{annotations.join(',')}"
22
+ end
23
+
24
+ if approaches then
25
+ params += "#{params.length > 0 ? '&' : '?'}approaches=#{approaches.join(';')}"
26
+ end
27
+
28
+ if radiuses then
29
+ params += "#{params.length > 0 ? '&' : '?'}radiuses=#{radiuses.join ';'}"
30
+ end
31
+
32
+ if timestamps then
33
+ params += "#{params.length > 0 ? '&' : '?'}timestamps=#{timestamps.join ';'}"
34
+ end
35
+
36
+ if waypoint_names then
37
+ params += "#{params.length > 0 ? '&' : '?'}waypoint_names=#{waypoint_names.join ';'}"
38
+ end
39
+
40
+ if waypoints then
41
+ params += "#{params.length > 0 ? '&' : '?'}waypoints=#{waypoints.join ';'}"
42
+ end
43
+
44
+ return params
45
+ end
46
+
47
+ def self.map_matching(waypoints, profile, options={})
48
+ formatted_waypoints = waypoints.map {|p| xy_from_hash(p).join ','}.join ';'
49
+ params = self.assemble_params(options)
50
+
51
+ return request(
52
+ :get,
53
+ "/matching/v5/mapbox/#{profile}/#{formatted_waypoints}.json#{params}",
54
+ nil)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,32 @@
1
+ module Mapbox
2
+ class Matrix
3
+ include Mapbox::APIOperations::Request
4
+ extend Mapbox::HashUtils
5
+
6
+ def self.assemble_params(options={})
7
+ opts = options.dup
8
+
9
+ self.joinArrayParam(opts, :destinations)
10
+ self.joinArrayParam(opts, :annotations, ',')
11
+ self.joinArrayParam(opts, :approaches)
12
+ self.joinArrayParam(opts, :sources)
13
+
14
+ return "?#{URI.encode_www_form(opts)}"
15
+ end
16
+
17
+ def self.joinArrayParam(opts, name, joinSymbol = ';')
18
+ if opts[name].kind_of?(Array)
19
+ opts[name] = opts[name].join(joinSymbol)
20
+ end
21
+ end
22
+
23
+ def self.matrix(waypoints, profile, options={})
24
+ formatted_waypoints = waypoints.map {|p| xy_from_hash(p).join ','}.join ';'
25
+ params = self.assemble_params(options)
26
+ return request(
27
+ :get,
28
+ "/directions-matrix/v1/mapbox/#{profile}/#{formatted_waypoints}.json#{params}",
29
+ nil)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,47 @@
1
+ module Mapbox
2
+ class Optimization
3
+ include Mapbox::APIOperations::Request
4
+ extend Mapbox::HashUtils
5
+
6
+ def self.assemble_params(options={})
7
+ annotations = options[:annotations]
8
+ approaches = options[:approaches]
9
+ distributions = options[:distributions]
10
+ radiuses = options[:radiuses]
11
+
12
+ params = ''
13
+ opts = options.select { |key, value| key != :annotations && key != :approaches && key != :distributions && key != :radiuses }
14
+ if opts.length > 0
15
+ params += "#{params.length > 0 ? '&' : '?'}#{URI.encode_www_form(opts)}"
16
+ end
17
+
18
+ if annotations then
19
+ params += "#{params.length > 0 ? '&' : '?'}annotations=#{annotations.join(',')}"
20
+ end
21
+
22
+ if approaches then
23
+ params += "#{params.length > 0 ? '&' : '?'}approaches=#{approaches.join(';')}"
24
+ end
25
+
26
+ if distributions then
27
+ params += "#{params.length > 0 ? '&' : '?'}distributions=#{distributions.join(';')}"
28
+ end
29
+
30
+ if radiuses then
31
+ params += "#{params.length > 0 ? '&' : '?'}radiuses=#{radiuses.join(';')}"
32
+ end
33
+
34
+ return params
35
+ end
36
+
37
+ def self.optimization(waypoints, profile, options={})
38
+ formatted_waypoints = waypoints.map {|p| xy_from_hash(p).join ','}.join ';'
39
+ params = self.assemble_params(options)
40
+
41
+ return request(
42
+ :get,
43
+ "/optimized-trips/v1/mapbox/#{profile}/#{formatted_waypoints}.json#{params}",
44
+ nil)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,15 @@
1
+ module Mapbox
2
+ class Tilequery
3
+ include Mapbox::APIOperations::Request
4
+ extend Mapbox::HashUtils
5
+
6
+ def self.tilequery(mapid, location, radius, limit)
7
+ lon = location['longitude'].round(5)
8
+ lat = location['latitude'].round(5)
9
+ return request(
10
+ :get,
11
+ "/v4/#{mapid}/tilequery/#{lon},#{lat}.json?radius=#{radius}&limit=#{limit}",
12
+ nil)
13
+ end
14
+ end
15
+ end
@@ -2,7 +2,7 @@ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
2
 
3
3
  spec = Gem::Specification.new do |s|
4
4
  s.name = 'mapbox-sdk'
5
- s.version = '2.0.0'
5
+ s.version = '2.3.2'
6
6
  s.summary = 'Ruby bindings for the Mapbox API'
7
7
  s.description = ''
8
8
  s.authors = ['Tom MacWright']
@@ -10,8 +10,7 @@ spec = Gem::Specification.new do |s|
10
10
  s.homepage = 'https://mapbox.com/developers'
11
11
  s.license = 'MIT'
12
12
 
13
- s.add_dependency('rest-client', '~> 1.4')
14
- s.add_dependency('json', '~> 1.8.1')
13
+ s.add_dependency('rest-client', '~> 2.1.0')
15
14
 
16
15
  s.add_development_dependency('mocha', '~> 0.13.2')
17
16
  s.add_development_dependency('shoulda', '~> 3.4.0')
@@ -0,0 +1,4 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ Dir[File.dirname(File.absolute_path(__FILE__)) + '/**/*_test.rb'].each {|file| require file }
@@ -16,7 +16,9 @@ module Mapbox
16
16
  :longitude => -90,
17
17
  :latitude => 38
18
18
  }
19
- ])
19
+ ], "cycling", {
20
+ geometries: "geojson"
21
+ })
20
22
  assert result
21
23
  end
22
24
  end
@@ -39,6 +39,13 @@ module Mapbox
39
39
  assert Mapbox.request_opts[:url].include? '?country=ca';
40
40
  end
41
41
 
42
+ should "#geocode_forward (include types param)" do
43
+ Mapbox.access_token = ENV["MapboxAccessToken"]
44
+ result = Mapbox::Geocoder.geocode_forward("Washington", {:types => ['poi.landmark', 'address'], :foo_key => "foo_val", :bar_key => "bar_val"})
45
+ assert result
46
+ assert Mapbox.request_opts[:url].include? '?foo_key=foo_val&bar_key=bar_val&types=poi.landmark%2Caddress';
47
+ end
48
+
42
49
  should "#geocode_reverse" do
43
50
  Mapbox.access_token = ENV["MapboxAccessToken"]
44
51
  result = Mapbox::Geocoder.geocode_reverse({
@@ -0,0 +1,15 @@
1
+ require 'mapbox'
2
+ require 'test/unit'
3
+ require 'mocha/setup'
4
+ require 'shoulda'
5
+
6
+ module Mapbox
7
+ class IsochroneTest < Test::Unit::TestCase
8
+ should "#isochrone" do
9
+ Mapbox.access_token = ENV["MapboxAccessToken"]
10
+ result = Mapbox::Isochrone.isochrone(
11
+ "walking", "-118.22258,33.99038", {contours_minutes: [5,10,15]})
12
+ assert result
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,46 @@
1
+ require 'mapbox'
2
+ require 'test/unit'
3
+ require 'mocha/setup'
4
+ require 'shoulda'
5
+
6
+ module Mapbox
7
+ class MapMatchingTest < Test::Unit::TestCase
8
+ should "#map match with just coordinates and profile" do
9
+ Mapbox.access_token = ENV["MapboxAccessToken"]
10
+ result = Mapbox::MapMatching.map_matching([{
11
+ "longitude" => -117.17282,
12
+ "latitude" => 32.71204
13
+ }, {
14
+ "longitude" => -117.17288,
15
+ "latitude" => 32.71225
16
+ }, {
17
+ "longitude" => -117.17293,
18
+ "latitude" => 32.71244
19
+ },{
20
+ "longitude" => -117.17292,
21
+ "latitude" => 32.71256
22
+ }], "driving")
23
+ assert result
24
+ end
25
+ should "#map match with optional params" do
26
+ Mapbox.access_token = ENV["MapboxAccessToken"]
27
+ result = Mapbox::MapMatching.map_matching([{
28
+ "longitude" => -117.17282,
29
+ "latitude" => 32.71204
30
+ }, {
31
+ "longitude" => -117.17288,
32
+ "latitude" => 32.71225
33
+ }, {
34
+ "longitude" => -117.17293,
35
+ "latitude" => 32.71244
36
+ }, {
37
+ "longitude" => -117.17292,
38
+ "latitude" => 32.71256
39
+ }], "driving", {
40
+ annotations: ["duration", "distance", "speed"],
41
+ approaches: ["curb","curb","curb","curb"]
42
+ })
43
+ assert result
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,40 @@
1
+ require 'mapbox'
2
+ require 'test/unit'
3
+ require 'mocha/setup'
4
+ require 'shoulda'
5
+
6
+ module Mapbox
7
+ class MatrixTest < Test::Unit::TestCase
8
+ should "#matrix with just coordinates and profile" do
9
+ Mapbox.access_token = ENV["MapboxAccessToken"]
10
+ result = Mapbox::Matrix.matrix([{
11
+ "longitude" => -122.42,
12
+ "latitude" => 37.78
13
+ }, {
14
+ "longitude" => -122.45,
15
+ "latitude" => 37.91
16
+ }, {
17
+ "longitude" => -122.48,
18
+ "latitude" => 37.73
19
+ }], "driving")
20
+ assert result
21
+ end
22
+ should "#matrix with optional params" do
23
+ Mapbox.access_token = ENV["MapboxAccessToken"]
24
+ result = Mapbox::Matrix.matrix([{
25
+ "longitude" => -122.42,
26
+ "latitude" => 37.78
27
+ }, {
28
+ "longitude" => -122.45,
29
+ "latitude" => 37.91
30
+ }, {
31
+ "longitude" => -122.48,
32
+ "latitude" => 37.73
33
+ }], "cycling", {
34
+ annotations: ["duration", "distance"],
35
+ approaches: ["curb","curb","curb"]
36
+ })
37
+ assert result
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,56 @@
1
+ require 'mapbox'
2
+ require 'test/unit'
3
+ require 'mocha/setup'
4
+ require 'shoulda'
5
+
6
+ module Mapbox
7
+ class MatrixTest < Test::Unit::TestCase
8
+ should "#optimization with just coordinates and profile" do
9
+ Mapbox.access_token = ENV["MapboxAccessToken"]
10
+ result = Mapbox::Optimization.optimization([{
11
+ "longitude" => -122.42,
12
+ "latitude" => 37.78
13
+ }, {
14
+ "longitude" => -122.45,
15
+ "latitude" => 37.91
16
+ }, {
17
+ "longitude" => -122.48,
18
+ "latitude" => 37.73
19
+ }], "walking")
20
+ assert result
21
+ end
22
+ should "#optimization with optional params" do
23
+ Mapbox.access_token = ENV["MapboxAccessToken"]
24
+ result = Mapbox::Optimization.optimization([{
25
+ "longitude" => -122.42,
26
+ "latitude" => 37.78
27
+ }, {
28
+ "longitude" => -122.45,
29
+ "latitude" => 37.91
30
+ }, {
31
+ "longitude" => -122.48,
32
+ "latitude" => 37.73
33
+ }], "cycling", {
34
+ annotations: ["duration", "distance"],
35
+ approaches: ["curb","curb","curb"]
36
+ })
37
+ assert result
38
+ end
39
+ should "#optimization with an empty bearing" do
40
+ Mapbox.access_token = ENV["MapboxAccessToken"]
41
+ result = Mapbox::Optimization.optimization([{
42
+ "longitude" => -122.42,
43
+ "latitude" => 37.78
44
+ }, {
45
+ "longitude" => -122.45,
46
+ "latitude" => 37.91
47
+ }, {
48
+ "longitude" => -122.48,
49
+ "latitude" => 37.73
50
+ }], "driving", {
51
+ bearings: "45,90;;90,1"
52
+ })
53
+ assert result
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,15 @@
1
+ require 'mapbox'
2
+ require 'test/unit'
3
+ require 'mocha/setup'
4
+ require 'shoulda'
5
+
6
+ module Mapbox
7
+ class TilequeryTest < Test::Unit::TestCase
8
+ should "#tilequery" do
9
+ Mapbox.access_token = ENV["MapboxAccessToken"]
10
+ result = Mapbox::Tilequery.tilequery(
11
+ "mapbox.mapbox-streets-v7", {"longitude" => -122.42901, "latitude" => 37.80633}, 5, 10)
12
+ assert result
13
+ end
14
+ end
15
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mapbox-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom MacWright
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-13 00:00:00.000000000 Z
11
+ date: 2020-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -16,28 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.4'
19
+ version: 2.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.4'
27
- - !ruby/object:Gem::Dependency
28
- name: json
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: 1.8.1
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 1.8.1
26
+ version: 2.1.0
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: mocha
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -101,21 +87,41 @@ executables: []
101
87
  extensions: []
102
88
  extra_rdoc_files: []
103
89
  files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - CHANGELOG.md
104
93
  - Gemfile
105
- - Gemfile.lock
106
94
  - LICENSE
107
95
  - README.md
108
96
  - Rakefile
97
+ - docs/directions.md
98
+ - docs/geocoding.md
99
+ - docs/isochrone.md
100
+ - docs/mapmatching.md
101
+ - docs/matrix.md
102
+ - docs/optimization.md
103
+ - docs/tilequery.md
109
104
  - lib/mapbox-sdk.rb
110
105
  - lib/mapbox.rb
111
106
  - lib/mapbox/api_operations.rb
112
107
  - lib/mapbox/authentication_error.rb
113
108
  - lib/mapbox/directions.rb
114
109
  - lib/mapbox/geocoder.rb
110
+ - lib/mapbox/isochrone.rb
111
+ - lib/mapbox/map_matching.rb
112
+ - lib/mapbox/matrix.rb
113
+ - lib/mapbox/optimization.rb
114
+ - lib/mapbox/tilequery.rb
115
115
  - mapbox-sdk.gemspec
116
+ - test/all_tests.rb
116
117
  - test/directions_test.rb
117
118
  - test/geocoding_test.rb
119
+ - test/isochrone_test.rb
120
+ - test/map_matching_test.rb
118
121
  - test/mapbox_test.rb
122
+ - test/matrix_test.rb
123
+ - test/optimization_test.rb
124
+ - test/tilequery_test.rb
119
125
  homepage: https://mapbox.com/developers
120
126
  licenses:
121
127
  - MIT
@@ -135,12 +141,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
141
  - !ruby/object:Gem::Version
136
142
  version: '0'
137
143
  requirements: []
138
- rubyforge_project:
139
- rubygems_version: 2.5.1
144
+ rubygems_version: 3.1.4
140
145
  signing_key:
141
146
  specification_version: 4
142
147
  summary: Ruby bindings for the Mapbox API
143
148
  test_files:
149
+ - test/all_tests.rb
144
150
  - test/directions_test.rb
145
151
  - test/geocoding_test.rb
152
+ - test/isochrone_test.rb
153
+ - test/map_matching_test.rb
146
154
  - test/mapbox_test.rb
155
+ - test/matrix_test.rb
156
+ - test/optimization_test.rb
157
+ - test/tilequery_test.rb
@@ -1,64 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- mapbox (1.0.0)
5
- json (~> 1.8.1)
6
- rest-client (~> 1.4)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- activesupport (4.2.3)
12
- i18n (~> 0.7)
13
- json (~> 1.7, >= 1.7.7)
14
- minitest (~> 5.1)
15
- thread_safe (~> 0.3, >= 0.3.4)
16
- tzinfo (~> 1.1)
17
- bourne (1.5.0)
18
- mocha (>= 0.13.2, < 0.15)
19
- domain_name (0.5.24)
20
- unf (>= 0.0.5, < 1.0.0)
21
- http-cookie (1.0.2)
22
- domain_name (~> 0.5)
23
- i18n (0.7.0)
24
- json (1.8.3)
25
- metaclass (0.0.4)
26
- mime-types (2.6.1)
27
- minitest (5.7.0)
28
- mocha (0.13.3)
29
- metaclass (~> 0.0.1)
30
- netrc (0.10.3)
31
- power_assert (0.2.4)
32
- rake (10.4.2)
33
- rest-client (1.8.0)
34
- http-cookie (>= 1.0.2, < 2.0)
35
- mime-types (>= 1.16, < 3.0)
36
- netrc (~> 0.7)
37
- shoulda (3.4.0)
38
- shoulda-context (~> 1.0, >= 1.0.1)
39
- shoulda-matchers (~> 1.0, >= 1.4.1)
40
- shoulda-context (1.2.1)
41
- shoulda-matchers (1.5.6)
42
- activesupport (>= 3.0.0)
43
- bourne (~> 1.3)
44
- test-unit (3.1.2)
45
- power_assert
46
- thread_safe (0.3.5)
47
- tzinfo (1.2.2)
48
- thread_safe (~> 0.1)
49
- unf (0.1.4)
50
- unf_ext
51
- unf_ext (0.0.7.1)
52
-
53
- PLATFORMS
54
- ruby
55
-
56
- DEPENDENCIES
57
- mapbox!
58
- mocha (~> 0.13.2)
59
- rake
60
- shoulda (~> 3.4.0)
61
- test-unit
62
-
63
- BUNDLED WITH
64
- 1.10.6