Class: Mapbox::Matrix
- Inherits:
-
Object
- Object
- Mapbox::Matrix
- Extended by:
- HashUtils
- Includes:
- APIOperations::Request
- Defined in:
- lib/mapbox/matrix.rb
Class Method Summary collapse
- .assemble_params(options = {}) ⇒ Object
- .joinArrayParam(opts, name, joinSymbol = ';') ⇒ Object
- .matrix(waypoints, profile, options = {}) ⇒ Object
Methods included from HashUtils
Methods included from APIOperations::Request
Class Method Details
.assemble_params(options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/mapbox/matrix.rb', line 6 def self.assemble_params(={}) opts = .dup self.joinArrayParam(opts, :destinations) self.joinArrayParam(opts, :annotations, ',') self.joinArrayParam(opts, :approaches) self.joinArrayParam(opts, :sources) return "?#{URI.encode_www_form(opts)}" end |
.joinArrayParam(opts, name, joinSymbol = ';') ⇒ Object
17 18 19 20 21 |
# File 'lib/mapbox/matrix.rb', line 17 def self.joinArrayParam(opts, name, joinSymbol = ';') if opts[name].kind_of?(Array) opts[name] = opts[name].join(joinSymbol) end end |
.matrix(waypoints, profile, options = {}) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/mapbox/matrix.rb', line 23 def self.matrix(waypoints, profile, ={}) formatted_waypoints = waypoints.map {|p| xy_from_hash(p).join ','}.join ';' params = self.assemble_params() return request( :get, "/directions-matrix/v1/mapbox/#{profile}/#{formatted_waypoints}.json#{params}", nil) end |