mapbox-sdk 2.2.0 → 2.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -1
- data/Gemfile +2 -2
- data/README.md +18 -6
- data/docs/directions.md +4 -4
- data/docs/mapmatching.md +43 -0
- data/docs/matrix.md +38 -0
- data/docs/optimization.md +52 -0
- data/lib/mapbox/geocoder.rb +1 -1
- 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.rb +9 -6
- data/mapbox-sdk.gemspec +2 -2
- data/test/geocoding_test.rb +23 -8
- data/test/map_matching_test.rb +46 -0
- data/test/mapbox_test.rb +8 -0
- data/test/matrix_test.rb +40 -0
- data/test/optimization_test.rb +56 -0
- metadata +17 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 485c58289f4baee1dc8d98e0c63642a77abc2b9290bda6f15afb20e8d8157bc3
|
4
|
+
data.tar.gz: 4aab789f653d516d1ae88811f598fd8190c7bfa6e6e3122b558eaa442144e677
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33e2264dda2cdc27b191b1efe999db0596da3d5e861d6de00ab576e400764a2b0d23f9efed98a38cce292aa39ce0b73e4f837fb6c155cf6f54ca7a285078c51e
|
7
|
+
data.tar.gz: ebec6b814a78b45bb9517e3e66ae2c0edea63d91cae279ac328fd2de49b0cf5760c0b6e5f697095b9b563094a554777ad53072689a62bfe97b1377ac3243d3a8
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,29 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
-
## [2.
|
7
|
+
## [2.3.3] - 2021-09-08
|
8
|
+
### Changed
|
9
|
+
- See https://github.com/mapbox/mapbox-sdk-rb/pull/55 / https://github.com/mapbox/mapbox-sdk-rb/issues/54
|
10
|
+
|
11
|
+
## [2.3.2] - 2020-11-23
|
12
|
+
### Changed
|
13
|
+
- Fixed URI.encode obsolete warnings in Ruby 2.7
|
14
|
+
|
15
|
+
## [2.3.1] - 2020-11-07
|
16
|
+
### Changed
|
17
|
+
- Update to restclient 2.1.0
|
18
|
+
|
19
|
+
## [2.3.0] - 2019-01-16
|
20
|
+
### Added
|
21
|
+
- Matrix endpoint, docs, and tests
|
22
|
+
- Map Matching endpoint, docs, and tests
|
23
|
+
- Optimization endpoint, docs, and tests
|
24
|
+
|
25
|
+
### Changed
|
26
|
+
|
27
|
+
### Removed
|
28
|
+
|
29
|
+
## [2.2.0] - 2018-12-14
|
8
30
|
### Added
|
9
31
|
- Selection of directions profiles
|
10
32
|
- Isochrone endpoint
|
data/Gemfile
CHANGED
@@ -3,11 +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', '~> 2.0
|
6
|
+
gem 'rest-client', '~> 2.1.0'
|
7
7
|
gem "activesupport", ">= 4.1.11"
|
8
8
|
gem 'rake', '10.1.0'
|
9
9
|
end
|
10
10
|
|
11
11
|
group :development, :test do
|
12
12
|
gem "coveralls", :require => false
|
13
|
-
end
|
13
|
+
end
|
data/README.md
CHANGED
@@ -12,17 +12,29 @@ gem install mapbox-sdk
|
|
12
12
|
|
13
13
|
## Services
|
14
14
|
|
15
|
-
* [Geocoding](https://
|
15
|
+
* [Geocoding](https://docs.mapbox.com/api/search/) [[docs](https://github.com/mapbox/mapbox-sdk-rb/blob/master/docs/geocoding.md)]
|
16
16
|
* Forward (place names ⇢ longitude, latitude)
|
17
17
|
* Reverse (longitude, latitude ⇢ place names)
|
18
|
-
* [Directions](https://
|
19
|
-
* Profiles for driving, walking, and cycling
|
20
|
-
* [Tilequery](https://
|
21
|
-
* [Isochrone](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)]
|
22
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
|
23
29
|
|
24
30
|
## Testing
|
25
31
|
|
26
|
-
|
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
|
38
|
+
```
|
27
39
|
|
28
40
|
Heavily influenced by Stripe's Ruby client, and includes its MIT license.
|
data/docs/directions.md
CHANGED
@@ -13,7 +13,7 @@ drivingDirections = Mapbox::Directions.directions([{
|
|
13
13
|
"latitude" => 38
|
14
14
|
}], "driving")
|
15
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/#retrieve-directions]).
|
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
17
|
|
18
18
|
# For instance, to use the `geometries` and `voice_instructions` parameter:
|
19
19
|
drivingDirections = Mapbox::Directions.directions([{
|
@@ -26,6 +26,6 @@ drivingDirections = Mapbox::Directions.directions([{
|
|
26
26
|
geometries: "geojson",
|
27
27
|
voice_instructions: true
|
28
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/#directions).
|
31
|
-
```
|
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/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/lib/mapbox/geocoder.rb
CHANGED
@@ -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
|
data/lib/mapbox.rb
CHANGED
@@ -11,7 +11,7 @@ module Mapbox
|
|
11
11
|
LONGITUDE_KEY = 'longitude'.freeze
|
12
12
|
|
13
13
|
class << self
|
14
|
-
attr_accessor :access_token, :api_base, :request_opts
|
14
|
+
attr_accessor :access_token, :api_base, :request_opts, :request_timeout, :request_open_timeout
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.request(method, url, api_key, params={}, headers={}, api_base_url=nil)
|
@@ -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 ? '&' : '?'}#{
|
36
|
+
url += "#{URI.parse(url).query ? '&' : '?'}#{URI.encode_www_form(params)}" if params && params.any?
|
37
37
|
payload = nil
|
38
38
|
end
|
39
39
|
|
@@ -42,10 +42,10 @@ module Mapbox
|
|
42
42
|
|
43
43
|
@request_opts.update(
|
44
44
|
:method => method,
|
45
|
-
:open_timeout => 30,
|
45
|
+
:open_timeout => @request_open_timeout || 30,
|
46
46
|
:payload => payload,
|
47
47
|
:url => url,
|
48
|
-
:timeout => 80)
|
48
|
+
:timeout => @request_timeout || 80)
|
49
49
|
|
50
50
|
begin
|
51
51
|
response = execute_request(@request_opts)
|
@@ -78,7 +78,7 @@ module Mapbox
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def self.url_encode(key)
|
81
|
-
URI.
|
81
|
+
URI.encode_www_form_component(key.to_s)
|
82
82
|
end
|
83
83
|
|
84
84
|
def self.execute_request(opts)
|
@@ -181,4 +181,7 @@ end
|
|
181
181
|
require 'mapbox/geocoder'
|
182
182
|
require 'mapbox/directions'
|
183
183
|
require 'mapbox/tilequery'
|
184
|
-
require 'mapbox/isochrone'
|
184
|
+
require 'mapbox/isochrone'
|
185
|
+
require 'mapbox/matrix'
|
186
|
+
require 'mapbox/map_matching'
|
187
|
+
require 'mapbox/optimization'
|
data/mapbox-sdk.gemspec
CHANGED
@@ -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.
|
5
|
+
s.version = '2.3.3'
|
6
6
|
s.summary = 'Ruby bindings for the Mapbox API'
|
7
7
|
s.description = ''
|
8
8
|
s.authors = ['Tom MacWright']
|
@@ -10,7 +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', '~> 2.0
|
13
|
+
s.add_dependency('rest-client', '~> 2.1.0')
|
14
14
|
|
15
15
|
s.add_development_dependency('mocha', '~> 0.13.2')
|
16
16
|
s.add_development_dependency('shoulda', '~> 3.4.0')
|
data/test/geocoding_test.rb
CHANGED
@@ -5,49 +5,58 @@ require 'shoulda'
|
|
5
5
|
|
6
6
|
module Mapbox
|
7
7
|
class GeocodingTest < Test::Unit::TestCase
|
8
|
-
|
8
|
+
|
9
|
+
def setup
|
9
10
|
Mapbox.access_token = ENV["MapboxAccessToken"]
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
Mapbox.request_open_timeout = nil
|
15
|
+
Mapbox.request_timeout = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
should "#geocode_forward" do
|
10
19
|
result = Mapbox::Geocoder.geocode_forward("Chester, NJ")
|
11
20
|
assert result
|
12
21
|
end
|
13
22
|
|
23
|
+
should "set_default_timeouts" do
|
24
|
+
result = Mapbox::Geocoder.geocode_forward("Chester, NJ")
|
25
|
+
assert Mapbox.request_opts[:timeout] = 80
|
26
|
+
assert Mapbox.request_opts[:open_timeout] = 30
|
27
|
+
end
|
28
|
+
|
14
29
|
should "#geocode_forward (rounded proximity to 3 decimal places)" do
|
15
|
-
Mapbox.access_token = ENV["MapboxAccessToken"]
|
16
30
|
result = Mapbox::Geocoder.geocode_forward("Chester, NJ", {:proximity => {:longitude => 0.1234567, :latitude => -10.987654}})
|
17
31
|
assert result
|
18
32
|
assert Mapbox.request_opts[:url].include? '?proximity=0.123%2C-10.988&'
|
19
33
|
end
|
20
34
|
|
21
35
|
should "#geocode_forward (include bbox param)" do
|
22
|
-
Mapbox.access_token = ENV["MapboxAccessToken"]
|
23
36
|
result = Mapbox::Geocoder.geocode_forward("Washington", {:bbox => [-78.3284,38.6039,-78.0428,38.7841]})
|
24
37
|
assert result
|
25
38
|
assert Mapbox.request_opts[:url].include? '?bbox=-78.3284%2C38.6039%2C-78.0428%2C38.7841';
|
26
39
|
end
|
27
40
|
|
28
41
|
should "#geocode_forward (include extra param)" do
|
29
|
-
Mapbox.access_token = ENV["MapboxAccessToken"]
|
30
42
|
result = Mapbox::Geocoder.geocode_forward("Washington", {:bbox => [-78.3284,38.6039,-78.0428,38.7841], :foo_key => "foo_val", :bar_key => "bar_val"})
|
31
43
|
assert result
|
32
44
|
assert Mapbox.request_opts[:url].include? '?foo_key=foo_val&bar_key=bar_val';
|
33
45
|
end
|
34
46
|
|
35
47
|
should "#geocode_forward (include country param)" do
|
36
|
-
Mapbox.access_token = ENV["MapboxAccessToken"]
|
37
48
|
result = Mapbox::Geocoder.geocode_forward("Washington", {:country => "ca"})
|
38
49
|
assert result
|
39
50
|
assert Mapbox.request_opts[:url].include? '?country=ca';
|
40
51
|
end
|
41
52
|
|
42
53
|
should "#geocode_forward (include types param)" do
|
43
|
-
Mapbox.access_token = ENV["MapboxAccessToken"]
|
44
54
|
result = Mapbox::Geocoder.geocode_forward("Washington", {:types => ['poi.landmark', 'address'], :foo_key => "foo_val", :bar_key => "bar_val"})
|
45
55
|
assert result
|
46
56
|
assert Mapbox.request_opts[:url].include? '?foo_key=foo_val&bar_key=bar_val&types=poi.landmark%2Caddress';
|
47
57
|
end
|
48
58
|
|
49
59
|
should "#geocode_reverse" do
|
50
|
-
Mapbox.access_token = ENV["MapboxAccessToken"]
|
51
60
|
result = Mapbox::Geocoder.geocode_reverse({
|
52
61
|
:latitude => 38,
|
53
62
|
:longitude => -100
|
@@ -56,7 +65,6 @@ module Mapbox
|
|
56
65
|
end
|
57
66
|
|
58
67
|
should "#geocode_reverse (rounded coordinates to 5 decimal places)" do
|
59
|
-
Mapbox.access_token = ENV["MapboxAccessToken"]
|
60
68
|
result = Mapbox::Geocoder.geocode_reverse({
|
61
69
|
:latitude => 1.23456789,
|
62
70
|
:longitude => -99.8765432
|
@@ -66,5 +74,12 @@ module Mapbox
|
|
66
74
|
end
|
67
75
|
end
|
68
76
|
|
77
|
+
should "set_custom_timeouts" do
|
78
|
+
Mapbox.request_timeout = 10
|
79
|
+
Mapbox.request_open_timeout = 5
|
80
|
+
result = Mapbox::Geocoder.geocode_forward("Chester, NJ", {:proximity => {:longitude => 0.1234567, :latitude => -10.987654}})
|
81
|
+
assert Mapbox.request_opts[:timeout] == 10
|
82
|
+
assert Mapbox.request_opts[:open_timeout] == 5
|
83
|
+
end
|
69
84
|
end
|
70
85
|
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
|
data/test/mapbox_test.rb
CHANGED
@@ -14,6 +14,14 @@ module Mapbox
|
|
14
14
|
should "allow access token to be set" do
|
15
15
|
Mapbox.access_token = "foo"
|
16
16
|
end
|
17
|
+
|
18
|
+
should "allow request_timeout to be set" do
|
19
|
+
Mapbox.request_timeout = 5
|
20
|
+
end
|
21
|
+
|
22
|
+
should "allow request_open_timeout to be set" do
|
23
|
+
Mapbox.request_open_timeout = 5
|
24
|
+
end
|
17
25
|
end
|
18
26
|
|
19
27
|
class HashUtilTest < Test::Unit::TestCase
|
data/test/matrix_test.rb
ADDED
@@ -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
|
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.
|
4
|
+
version: 2.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom MacWright
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.0
|
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: 2.0
|
26
|
+
version: 2.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mocha
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -97,6 +97,9 @@ files:
|
|
97
97
|
- docs/directions.md
|
98
98
|
- docs/geocoding.md
|
99
99
|
- docs/isochrone.md
|
100
|
+
- docs/mapmatching.md
|
101
|
+
- docs/matrix.md
|
102
|
+
- docs/optimization.md
|
100
103
|
- docs/tilequery.md
|
101
104
|
- lib/mapbox-sdk.rb
|
102
105
|
- lib/mapbox.rb
|
@@ -105,13 +108,19 @@ files:
|
|
105
108
|
- lib/mapbox/directions.rb
|
106
109
|
- lib/mapbox/geocoder.rb
|
107
110
|
- lib/mapbox/isochrone.rb
|
111
|
+
- lib/mapbox/map_matching.rb
|
112
|
+
- lib/mapbox/matrix.rb
|
113
|
+
- lib/mapbox/optimization.rb
|
108
114
|
- lib/mapbox/tilequery.rb
|
109
115
|
- mapbox-sdk.gemspec
|
110
116
|
- test/all_tests.rb
|
111
117
|
- test/directions_test.rb
|
112
118
|
- test/geocoding_test.rb
|
113
119
|
- test/isochrone_test.rb
|
120
|
+
- test/map_matching_test.rb
|
114
121
|
- test/mapbox_test.rb
|
122
|
+
- test/matrix_test.rb
|
123
|
+
- test/optimization_test.rb
|
115
124
|
- test/tilequery_test.rb
|
116
125
|
homepage: https://mapbox.com/developers
|
117
126
|
licenses:
|
@@ -132,8 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
141
|
- !ruby/object:Gem::Version
|
133
142
|
version: '0'
|
134
143
|
requirements: []
|
135
|
-
|
136
|
-
rubygems_version: 2.7.8
|
144
|
+
rubygems_version: 3.2.25
|
137
145
|
signing_key:
|
138
146
|
specification_version: 4
|
139
147
|
summary: Ruby bindings for the Mapbox API
|
@@ -142,5 +150,8 @@ test_files:
|
|
142
150
|
- test/directions_test.rb
|
143
151
|
- test/geocoding_test.rb
|
144
152
|
- test/isochrone_test.rb
|
153
|
+
- test/map_matching_test.rb
|
145
154
|
- test/mapbox_test.rb
|
155
|
+
- test/matrix_test.rb
|
156
|
+
- test/optimization_test.rb
|
146
157
|
- test/tilequery_test.rb
|