Class: Mapbox::Directions
- Inherits:
-
Object
- Object
- Mapbox::Directions
- Extended by:
- HashUtils
- Includes:
- APIOperations::Request
- Defined in:
- lib/mapbox/directions.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 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/mapbox/directions.rb', line 6 def self.assemble_params(={}) alternatives = [:alternatives] annotations = [:annotations] approaches = [:approaches] = [:banner_instructions] bearings = [:bearings] continue_straight = [:continue_straight] exclude = [:exclude] geometries = [:geometries] language = [:language] overview = [:overview] radiuses = [:radiuses] roundabout_exits = [:roundabout_exits] steps = [:steps] voice_instructions = [:voice_instructions] voice_units = [:voice_units] waypoint_names = [:waypoint_names] params = '' opts = .select { |key, value| key != :approaches && key != :bearings && key != :radiuses && key != :waypoint_names } if opts.length > 0 params += "#{params.length > 0 ? '&' : '?'}#{URI.encode_www_form(opts)}" end if approaches then params += "#{params.length > 0 ? '&' : '?'}approaches=#{approaches.join(';')}" end if bearings then params += "#{params.length > 0 ? '&' : '?'}bearings=#{bearings.map {|p| bearings.join ','}.join ';'}" end if radiuses then params += "#{params.length > 0 ? '&' : '?'}radiuses=#{radiuses.join ';'}" end if waypoint_names then params += "#{params.length > 0 ? '&' : '?'}waypoint_names=#{waypoint_names.join ';'}" end return params end |
.directions(waypoints, profile, options = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/mapbox/directions.rb', line 49 def self.directions(waypoints, profile, ={}) formatted_waypoints = waypoints.map {|p| xy_from_hash(p).join ','}.join ';' params = self.assemble_params() return request( :get, "/directions/v5/mapbox/#{profile}/#{formatted_waypoints}.json#{params}", nil) end |