Class: Bing::Route

Inherits:
RestResource show all
Defined in:
lib/bing/route.rb

Defined Under Namespace

Classes: Itinerary

Constant Summary

Constants inherited from RestResource

Bing::RestResource::BASE_PATH

Instance Attribute Summary collapse

Attributes inherited from RestResource

#bounding_box

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RestResource

#bbox, map_find, map_uri

Constructor Details

#initialize(resource) ⇒ Route

Returns a new instance of Route.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/bing/route.rb', line 55

def initialize resource
  raise Bing::RouteResourceMissing if resource.blank?

  @distance_unit  = resource['distanceUnit']
  @duration_unit  = resource['durationUnit']
  @total_distance = resource['travelDistance']
  @total_duration = resource['travelDuration']
  @total_duration_traffic = resource['travelDurationTraffic']

  if resource['bbox'] then
    @bounding_box = bbox resource['bbox']
  end

  # TODO does not support multiple route legs. My testing thus far just
  # breaks Bing if I try to obtain multiple anyways.
  if resource['routeLegs'] && leg = resource['routeLegs'].first then
    @type = leg['type']

    if leg['actualEnd'] && leg['actualEnd']['coordinates'] then
      @ending_coordinates = leg['actualEnd']['coordinates']
    end

    if leg['actualStart'] && leg['actualStart']['coordinates'] then
      @starting_coordinates = leg['actualStart']['coordinates']
    end

    unless leg['itineraryItems'].blank? then
      @itinerary = leg['itineraryItems'].collect do |itinerary|
                     Bing::Route::Itinerary.new itinerary
                   end.compact
    end
  end
end

Instance Attribute Details

#distance_unitObject (readonly)

Returns the value of attribute distance_unit.



45
46
47
# File 'lib/bing/route.rb', line 45

def distance_unit
  @distance_unit
end

#duration_unitObject (readonly)

Returns the value of attribute duration_unit.



46
47
48
# File 'lib/bing/route.rb', line 46

def duration_unit
  @duration_unit
end

#ending_coordinatesObject (readonly)

Returns the value of attribute ending_coordinates.



47
48
49
# File 'lib/bing/route.rb', line 47

def ending_coordinates
  @ending_coordinates
end

#itineraryObject (readonly)

Returns the value of attribute itinerary.



48
49
50
# File 'lib/bing/route.rb', line 48

def itinerary
  @itinerary
end

#starting_coordinatesObject (readonly)

Returns the value of attribute starting_coordinates.



49
50
51
# File 'lib/bing/route.rb', line 49

def starting_coordinates
  @starting_coordinates
end

#total_distanceObject (readonly)

Returns the value of attribute total_distance.



50
51
52
# File 'lib/bing/route.rb', line 50

def total_distance
  @total_distance
end

#total_durationObject (readonly)

Returns the value of attribute total_duration.



51
52
53
# File 'lib/bing/route.rb', line 51

def total_duration
  @total_duration
end

#total_duration_trafficObject (readonly)

Returns the value of attribute total_duration_traffic.



52
53
54
# File 'lib/bing/route.rb', line 52

def total_duration_traffic
  @total_duration_traffic
end

#typeObject (readonly)

Returns the value of attribute type.



53
54
55
# File 'lib/bing/route.rb', line 53

def type
  @type
end

Class Method Details

.find(opts) ⇒ Object

Description

Will return a route based off of opts passed in. See msdn.microsoft.com/en-us/library/ff701717.aspx for reference on allowable opts and what is required. All values in opts are passed through save waypoints. The keys should follow ruby’s convention of snake case which will translate into MSN’s lower camelcase E.g. :date_time will be converted to dateTime for MSN.

opts

waypoints

Array of points. E.g. :waypoints =>

‘start’, ‘next’, ‘end’

will turn into “waypoint.0=

start&waypoint.1=next&waypoint.2=end“. Reference above MSN docs for allowable waypoints. All points must be strings.

Example

Bing::Route.find :avoid => ‘minimizeHighways,tolls’,

:distance_before_first_turn => 500,
:distance_unit              => 'mi'
:heading                    => 90,
:optimize                   => 'time',
:waypoints                  => ['start', 'next', 'end']

Return

msdn.microsoft.com/en-us/library/ff701718.aspx



31
32
33
34
35
36
# File 'lib/bing/route.rb', line 31

def self.find opts
  waypoints = format_waypoints opts.delete :waypoints
  params    = [opts.to_lower_camelized_param, waypoints].join '&'

  map_find params
end

.pathObject

Path to route resource.



41
42
43
# File 'lib/bing/route.rb', line 41

def self.path
  super '/Routes'
end