Class: Mapbox::Optimization
- Inherits:
-
Object
- Object
- Mapbox::Optimization
- Extended by:
- HashUtils
- Includes:
- APIOperations::Request
- Defined in:
- lib/mapbox/optimization.rb
Class Method Summary collapse
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 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mapbox/optimization.rb', line 6 def self.assemble_params(={}) annotations = [:annotations] approaches = [:approaches] distributions = [:distributions] radiuses = [:radiuses] params = '' opts = .select { |key, value| key != :annotations && key != :approaches && key != :distributions && key != :radiuses } if opts.length > 0 params += "#{params.length > 0 ? '&' : '?'}#{URI.encode_www_form(opts)}" end if annotations then params += "#{params.length > 0 ? '&' : '?'}annotations=#{annotations.join(',')}" end if approaches then params += "#{params.length > 0 ? '&' : '?'}approaches=#{approaches.join(';')}" end if distributions then params += "#{params.length > 0 ? '&' : '?'}distributions=#{distributions.join(';')}" end if radiuses then params += "#{params.length > 0 ? '&' : '?'}radiuses=#{radiuses.join(';')}" end return params end |
.optimization(waypoints, profile, options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/mapbox/optimization.rb', line 37 def self.optimization(waypoints, profile, ={}) formatted_waypoints = waypoints.map {|p| xy_from_hash(p).join ','}.join ';' params = self.assemble_params() return request( :get, "/optimized-trips/v1/mapbox/#{profile}/#{formatted_waypoints}.json#{params}", nil) end |