class Mapbox::Matrix
Public Class Methods
assemble_params(options={})
click to toggle source
# File lib/mapbox/matrix.rb, line 6 def self.assemble_params(options={}) opts = options.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 = ';')
click to toggle source
# 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={})
click to toggle source
# File lib/mapbox/matrix.rb, line 23 def self.matrix(waypoints, profile, options={}) formatted_waypoints = waypoints.map {|p| xy_from_hash(p).join ','}.join ';' params = self.assemble_params(options) return request( :get, "/directions-matrix/v1/mapbox/#{profile}/#{formatted_waypoints}.json#{params}", nil) end