mapbox-sdk 2.1.0 → 2.2.0
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 +4 -4
- data/.travis.yml +9 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +5 -1
- data/README.md +11 -37
- data/docs/directions.md +31 -0
- data/docs/geocoding.md +15 -0
- data/docs/isochrone.md +11 -0
- data/docs/tilequery.md +12 -0
- data/lib/mapbox.rb +1 -0
- data/lib/mapbox/directions.rb +48 -2
- data/lib/mapbox/isochrone.rb +35 -0
- data/mapbox-sdk.gemspec +1 -1
- data/test/all_tests.rb +4 -0
- data/test/directions_test.rb +3 -1
- data/test/isochrone_test.rb +15 -0
- data/test/tilequery_test.rb +1 -1
- metadata +13 -4
- data/.circleci/config.yml +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 206fa6c2df10182a6dec5a95110961dd3688eb42181af8d3ff8d9264410cb69c
|
4
|
+
data.tar.gz: 8e9771a4339e26319e665d665f7f1abdfc3c5a45daca881846e9f4a9f698fe6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9708d334fe1a76f02886d8a8da17d862f192a2c1a6705ee90588145c3a7e9d56a4f068d8a5193bf811fd489fc3a7543e07415e516c9adbb2e024dc7bb3361b0b
|
7
|
+
data.tar.gz: 8789e29b94f27a624d3d8eb89c809cdb710a8262b72abb5017a125662d2299fc2d08fc2df7cc0d30e35ae6343cd2b6a0e877f08f655d16ba63a61a7f4b2c5f41
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,18 @@ 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.1.0] - 2018-12-14
|
8
|
+
### Added
|
9
|
+
- Selection of directions profiles
|
10
|
+
- Isochrone endpoint
|
11
|
+
- New README/docs folder and organization
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
- Update to restclient 2.0
|
15
|
+
- Parameters to requests for directions
|
16
|
+
|
17
|
+
### Removed
|
18
|
+
|
7
19
|
## [2.1.0] - 2018-06-07
|
8
20
|
### Added
|
9
21
|
- Added CHANGELOG.md
|
data/Gemfile
CHANGED
@@ -4,6 +4,10 @@ gemspec
|
|
4
4
|
if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('1.9.3')
|
5
5
|
gem 'i18n', '< 0.7'
|
6
6
|
gem 'rest-client', '~> 2.0.1'
|
7
|
-
gem
|
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
|
+
[](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,45 +12,17 @@ gem install mapbox-sdk
|
|
10
12
|
|
11
13
|
## Services
|
12
14
|
|
13
|
-
* [Geocoding](https://www.mapbox.com/api-documentation/#geocoding)
|
15
|
+
* [Geocoding](https://www.mapbox.com/api-documentation/#geocoding) [[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/api-documentation/#directions)
|
18
|
+
* [Directions](https://www.mapbox.com/api-documentation/#directions): [[docs](https://github.com/mapbox/mapbox-sdk-rb/blob/master/docs/directions.md)]
|
17
19
|
* Profiles for driving, walking, and cycling
|
18
|
-
* [Tilequery](https://www.mapbox.com/api-documentation/#tilequery)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
# Reverse geocoding
|
27
|
-
placenames = Mapbox::Geocoder.geocode_reverse({
|
28
|
-
"latitude" => 38,
|
29
|
-
"longitude" => -100
|
30
|
-
})
|
31
|
-
|
32
|
-
# Forward geocoding with optional proximity parameter
|
33
|
-
places = Mapbox::Geocoder.geocode_forward("Chester, NJ", {:proximity => {:longitude => -74.6968, :latitude => 40.7843}})
|
34
|
-
|
35
|
-
# Driving directions with required profile parameter
|
36
|
-
drivingDirections = Mapbox::Directions.directions([{
|
37
|
-
"longitude" => -100,
|
38
|
-
"latitude" => 38
|
39
|
-
}, {
|
40
|
-
"longitude" => -90,
|
41
|
-
"latitude" => 38
|
42
|
-
}], "driving")
|
43
|
-
|
44
|
-
# 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).
|
45
|
-
|
46
|
-
# Tilequery
|
47
|
-
tilequery = Mapbox::Tilequery.tilequery(mapid, {location}, radius, limit)
|
48
|
-
|
49
|
-
# Example: tilequery = Mapbox::Tilequery.tilequery("mapbox.mapbox-streets-v7", {"longitude" => -100, "latitude" => 38}, 0, 1)
|
50
|
-
# `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.
|
51
|
-
# `Limit` refers to the number of features between 1 - 50 to return. Defaults to 5 if left blank.
|
52
|
-
```
|
20
|
+
* [Tilequery](https://www.mapbox.com/api-documentation/#tilequery): [[docs](https://github.com/mapbox/mapbox-sdk-rb/blob/master/docs/tilequery.md)]
|
21
|
+
* [Isochrone](https://www.mapbox.com/api-documentation/#isochrone): [[docs](https://github.com/mapbox/mapbox-sdk-rb/blob/masterdocs/isochrone.md)]
|
22
|
+
* Profiles for driving, walking, and cycling
|
23
|
+
|
24
|
+
## Testing
|
25
|
+
|
26
|
+
Run `bundle exec ruby -Itest test/all_tests.rb` or individual tests as needed.
|
53
27
|
|
54
28
|
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/#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/#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/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.rb
CHANGED
data/lib/mapbox/directions.rb
CHANGED
@@ -2,11 +2,57 @@ module Mapbox
|
|
2
2
|
class Directions
|
3
3
|
include Mapbox::APIOperations::Request
|
4
4
|
extend Mapbox::HashUtils
|
5
|
-
|
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={})
|
6
50
|
formatted_waypoints = waypoints.map {|p| xy_from_hash(p).join ','}.join ';'
|
51
|
+
params = self.assemble_params(options)
|
52
|
+
|
7
53
|
return request(
|
8
54
|
:get,
|
9
|
-
"/directions/v5/mapbox/#{profile}/#{formatted_waypoints}.json",
|
55
|
+
"/directions/v5/mapbox/#{profile}/#{formatted_waypoints}.json#{params}",
|
10
56
|
nil)
|
11
57
|
end
|
12
58
|
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
|
data/mapbox-sdk.gemspec
CHANGED
data/test/all_tests.rb
ADDED
data/test/directions_test.rb
CHANGED
@@ -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
|
data/test/tilequery_test.rb
CHANGED
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.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom MacWright
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -87,23 +87,30 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
-
- ".circleci/config.yml"
|
91
90
|
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
92
|
- CHANGELOG.md
|
93
93
|
- Gemfile
|
94
94
|
- LICENSE
|
95
95
|
- README.md
|
96
96
|
- Rakefile
|
97
|
+
- docs/directions.md
|
98
|
+
- docs/geocoding.md
|
99
|
+
- docs/isochrone.md
|
100
|
+
- docs/tilequery.md
|
97
101
|
- lib/mapbox-sdk.rb
|
98
102
|
- lib/mapbox.rb
|
99
103
|
- lib/mapbox/api_operations.rb
|
100
104
|
- lib/mapbox/authentication_error.rb
|
101
105
|
- lib/mapbox/directions.rb
|
102
106
|
- lib/mapbox/geocoder.rb
|
107
|
+
- lib/mapbox/isochrone.rb
|
103
108
|
- lib/mapbox/tilequery.rb
|
104
109
|
- mapbox-sdk.gemspec
|
110
|
+
- test/all_tests.rb
|
105
111
|
- test/directions_test.rb
|
106
112
|
- test/geocoding_test.rb
|
113
|
+
- test/isochrone_test.rb
|
107
114
|
- test/mapbox_test.rb
|
108
115
|
- test/tilequery_test.rb
|
109
116
|
homepage: https://mapbox.com/developers
|
@@ -126,12 +133,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
133
|
version: '0'
|
127
134
|
requirements: []
|
128
135
|
rubyforge_project:
|
129
|
-
rubygems_version: 2.7.
|
136
|
+
rubygems_version: 2.7.8
|
130
137
|
signing_key:
|
131
138
|
specification_version: 4
|
132
139
|
summary: Ruby bindings for the Mapbox API
|
133
140
|
test_files:
|
141
|
+
- test/all_tests.rb
|
134
142
|
- test/directions_test.rb
|
135
143
|
- test/geocoding_test.rb
|
144
|
+
- test/isochrone_test.rb
|
136
145
|
- test/mapbox_test.rb
|
137
146
|
- test/tilequery_test.rb
|
data/.circleci/config.yml
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
version: 2
|
2
|
-
jobs:
|
3
|
-
build:
|
4
|
-
working_directory: ~/mapbox/mapbox-sdk-rb
|
5
|
-
parallelism: 1
|
6
|
-
shell: /bin/bash --login
|
7
|
-
environment:
|
8
|
-
CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
|
9
|
-
CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
|
10
|
-
docker:
|
11
|
-
- image: circleci/build-image:ubuntu-14.04-XXL-upstart-1189-5614f37
|
12
|
-
command: /sbin/init
|
13
|
-
steps:
|
14
|
-
- checkout
|
15
|
-
- run: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS
|
16
|
-
- restore_cache:
|
17
|
-
keys:
|
18
|
-
- v1-dep-{{ .Branch }}-
|
19
|
-
- v1-dep-master-
|
20
|
-
- v1-dep-
|
21
|
-
- run: echo -e "export RAILS_ENV=test\nexport RACK_ENV=test" >> $BASH_ENV
|
22
|
-
- run: 'bundle check --path=vendor/bundle || bundle install --path=vendor/bundle
|
23
|
-
--jobs=4 --retry=3 '
|
24
|
-
- save_cache:
|
25
|
-
key: v1-dep-{{ .Branch }}-{{ epoch }}
|
26
|
-
paths:
|
27
|
-
- vendor/bundle
|
28
|
-
- ~/virtualenvs
|
29
|
-
- ~/.bundle
|
30
|
-
- run:
|
31
|
-
command: bundle exec rake test
|
32
|
-
environment:
|
33
|
-
RAILS_ENV: test
|
34
|
-
RACK_ENV: test
|
35
|
-
- store_test_results:
|
36
|
-
path: /tmp/circleci-test-results
|
37
|
-
- store_artifacts:
|
38
|
-
path: /tmp/circleci-artifacts
|
39
|
-
- store_artifacts:
|
40
|
-
path: /tmp/circleci-test-results
|