mapbox-sdk 1.0.0 → 2.3.1
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.
- checksums.yaml +5 -5
- data/.gitignore +9 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.md +45 -0
- data/Gemfile +6 -2
- data/README.md +27 -25
- data/docs/directions.md +31 -0
- data/docs/geocoding.md +15 -0
- data/docs/isochrone.md +11 -0
- data/docs/mapmatching.md +43 -0
- data/docs/matrix.md +38 -0
- data/docs/optimization.md +52 -0
- data/docs/tilequery.md +12 -0
- data/lib/mapbox-sdk.rb +1 -0
- data/lib/mapbox.rb +24 -8
- data/lib/mapbox/directions.rb +53 -11
- data/lib/mapbox/geocoder.rb +41 -4
- data/lib/mapbox/isochrone.rb +35 -0
- data/lib/mapbox/map_matching.rb +57 -0
- data/lib/mapbox/matrix.rb +32 -0
- data/lib/mapbox/optimization.rb +47 -0
- data/lib/mapbox/tilequery.rb +15 -0
- data/mapbox-sdk.gemspec +2 -3
- data/test/all_tests.rb +4 -0
- data/test/directions_test.rb +7 -5
- data/test/geocoding_test.rb +50 -3
- data/test/isochrone_test.rb +15 -0
- data/test/map_matching_test.rb +46 -0
- data/test/mapbox_test.rb +23 -0
- data/test/matrix_test.rb +40 -0
- data/test/optimization_test.rb +56 -0
- data/test/tilequery_test.rb +15 -0
- metadata +45 -33
- data/Gemfile.lock +0 -64
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2de67f3d74dc108741f0f24be98c0d0c9ef1e0f339f1f93a0ded434a346327e7
|
4
|
+
data.tar.gz: a1c6335da15b1741f67f59d56860f7185aed3e21ee64ffb356b4dc03b3e71925
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 652a2d627953d128b3dd777885356646e40cb023584113e80ac88b53ccc14001d70837f7c04902fe6a8484fd1d064845a42e842762d321dd0e21ce64534a9b82
|
7
|
+
data.tar.gz: 80deb42871d24df8de2f632a86b5d815a9ec0ec69824096e23d86bc32213dd82603a05be7cbe292bd0180f61c467549201b4784ce4eef6a522d1583d2540dcf1
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -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.1] - 2020-11-07
|
8
|
+
### Added
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
- Update to restclient 2.1.0
|
12
|
+
|
13
|
+
### Removed
|
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.
|
7
|
-
gem
|
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,38 +1,40 @@
|
|
1
|
+
[](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/).
|
4
6
|
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
```
|
10
|
+
gem install mapbox-sdk
|
11
|
+
```
|
12
|
+
|
5
13
|
## Services
|
6
14
|
|
7
|
-
* [Geocoding](https://
|
15
|
+
* [Geocoding](https://docs.mapbox.com/api/search/) [[docs](https://github.com/mapbox/mapbox-sdk-rb/blob/master/docs/geocoding.md)]
|
8
16
|
* Forward (place names ⇢ longitude, latitude)
|
9
17
|
* Reverse (longitude, latitude ⇢ place names)
|
10
|
-
* [Directions](https://
|
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)]
|
11
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
|
12
29
|
|
13
|
-
##
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
"latitude" => 38,
|
22
|
-
"longitude" => -100
|
23
|
-
})
|
24
|
-
|
25
|
-
# Forward geocoding
|
26
|
-
places = Mapbox::Geocoder.geocode_forward("Chester, NJ")
|
27
|
-
|
28
|
-
# Directions
|
29
|
-
drivingDirections = Mapbox::Directions.directions([{
|
30
|
-
"longitude" => -100,
|
31
|
-
"latitude" => 38
|
32
|
-
}, {
|
33
|
-
"longitude" => -90,
|
34
|
-
"latitude" => 38
|
35
|
-
}])
|
30
|
+
## Testing
|
31
|
+
|
32
|
+
You'll need to [create an access token](https://account.mapbox.com/access-tokens/create) in order to run tests.
|
33
|
+
|
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
|
36
38
|
```
|
37
39
|
|
38
40
|
Heavily influenced by Stripe's Ruby client, and includes its MIT license.
|
data/docs/directions.md
ADDED
@@ -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
|
+
```
|
data/docs/geocoding.md
ADDED
@@ -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
|
+
```
|
data/docs/isochrone.md
ADDED
@@ -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
|
+
```
|
data/docs/mapmatching.md
ADDED
@@ -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
|
+
```
|
data/docs/matrix.md
ADDED
@@ -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
|
+
```
|
data/docs/tilequery.md
ADDED
@@ -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
|
+
```
|
data/lib/mapbox-sdk.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'mapbox'
|
data/lib/mapbox.rb
CHANGED
@@ -3,15 +3,15 @@ require 'json'
|
|
3
3
|
require 'mapbox/api_operations'
|
4
4
|
require 'mapbox/authentication_error'
|
5
5
|
|
6
|
-
# services
|
7
|
-
require 'mapbox/geocoder'
|
8
|
-
require 'mapbox/directions'
|
9
|
-
|
10
6
|
module Mapbox
|
11
7
|
@api_base = 'https://api.mapbox.com'
|
8
|
+
@request_opts = {}
|
9
|
+
|
10
|
+
LATITUDE_KEY = 'latitude'.freeze
|
11
|
+
LONGITUDE_KEY = 'longitude'.freeze
|
12
12
|
|
13
13
|
class << self
|
14
|
-
attr_accessor :access_token, :api_base
|
14
|
+
attr_accessor :access_token, :api_base, :request_opts
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.request(method, url, api_key, params={}, headers={}, api_base_url=nil)
|
@@ -37,10 +37,10 @@ module Mapbox
|
|
37
37
|
payload = nil
|
38
38
|
end
|
39
39
|
|
40
|
-
request_opts = {:verify_ssl => OpenSSL::SSL::VERIFY_PEER,
|
40
|
+
@request_opts = {:verify_ssl => OpenSSL::SSL::VERIFY_PEER,
|
41
41
|
:ssl_ca_file => @ssl_bundle_path}
|
42
42
|
|
43
|
-
request_opts.update(
|
43
|
+
@request_opts.update(
|
44
44
|
:method => method,
|
45
45
|
:open_timeout => 30,
|
46
46
|
:payload => payload,
|
@@ -48,7 +48,7 @@ module Mapbox
|
|
48
48
|
:timeout => 80)
|
49
49
|
|
50
50
|
begin
|
51
|
-
response = execute_request(request_opts)
|
51
|
+
response = execute_request(@request_opts)
|
52
52
|
rescue SocketError => e
|
53
53
|
handle_restclient_error(e, api_base_url)
|
54
54
|
rescue NoMethodError => e
|
@@ -168,4 +168,20 @@ module Mapbox
|
|
168
168
|
|
169
169
|
raise StandardError.new(message + "\n\n(Network error: #{e.message})")
|
170
170
|
end
|
171
|
+
|
172
|
+
module HashUtils
|
173
|
+
def xy_from_hash h = {}
|
174
|
+
[ h.fetch(:longitude){ h[LONGITUDE_KEY] },
|
175
|
+
h.fetch(:latitude){ h[LATITUDE_KEY] } ]
|
176
|
+
end
|
177
|
+
end
|
171
178
|
end
|
179
|
+
|
180
|
+
# services
|
181
|
+
require 'mapbox/geocoder'
|
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'
|
data/lib/mapbox/directions.rb
CHANGED
@@ -1,17 +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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
extend Mapbox::HashUtils
|
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={})
|
50
|
+
formatted_waypoints = waypoints.map {|p| xy_from_hash(p).join ','}.join ';'
|
51
|
+
params = self.assemble_params(options)
|
52
|
+
|
11
53
|
return request(
|
12
|
-
|
13
|
-
|
14
|
-
|
54
|
+
:get,
|
55
|
+
"/directions/v5/mapbox/#{profile}/#{formatted_waypoints}.json#{params}",
|
56
|
+
nil)
|
15
57
|
end
|
16
58
|
end
|
17
|
-
end
|
59
|
+
end
|