routific 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5a8db035d39a7c9b994a84f4d3663c4218c32d0
4
- data.tar.gz: 935947c6fdf1628778c239986b2516061ca29a36
3
+ metadata.gz: 1ea5df053d952f0517202e18e26493a3d986b739
4
+ data.tar.gz: 5b13d657ff00d3d4bc930a9e9f0191ac1b009226
5
5
  SHA512:
6
- metadata.gz: 1798aea34b4919f234e532141bd9e593e3b786da101b36e2f2c0f36ad7af614b84ac73a0d4c7a0ca8da1fbc91eb3025e5f3ab43fb59a7ff75a4237e50e0df784
7
- data.tar.gz: ddd45e67797e9b066fee1a6fd4fc86939cc682590529c30cff529f329e881441120ead3a48a5f686d680b9fbd3912848c142487f2f09c75f5c2777fe202f453f
6
+ metadata.gz: de46d973cc679f1cfe20d1bd3fdd6a9699ba25fb8bb777da63237a8aa4d6d29315af89b8c348c721ce5a4f05ef361d77c6180688b9241ded509d7acb338d1415
7
+ data.tar.gz: 0e322fc0e842a8df2335e955ab89a66eb38349e15038aff18f570c09074a6ce7da0b971dd074d34a0880b49beb04d72c7a1d6c0bcad04ee8d45cc9d127f9dd79
data/README.md CHANGED
@@ -63,6 +63,18 @@ Optional arguments in params:
63
63
  - shift_end: this vehicle's end shift time (e.g. '17:00'). Default value is 23:59, if not specified.
64
64
  - capacity: the capacity that this vehicle can load
65
65
 
66
+ `routific.setOptions( params )`
67
+
68
+ Sets optional options onto the route requests.
69
+
70
+ Optional arguments must be one of the following:
71
+
72
+ - traffic
73
+ - min_visits_per_vehicle
74
+ - balance
75
+ - min_vehicles
76
+ - shortest_distance
77
+
66
78
  `routific.getRoute()`
67
79
 
68
80
  Returns the route using the previously provided network, visits and fleet information
data/lib/routific.rb CHANGED
@@ -6,10 +6,11 @@ require_relative './routific/visit'
6
6
  require_relative './routific/vehicle'
7
7
  require_relative './routific/route'
8
8
  require_relative './routific/way_point'
9
+ require_relative './routific/options'
9
10
 
10
11
  # Main class of this gem
11
12
  class Routific
12
- attr_reader :token, :visits, :fleet
13
+ attr_reader :token, :visits, :fleet, :options
13
14
 
14
15
  # Constructor
15
16
  # token: Access token for Routific API
@@ -17,20 +18,27 @@ class Routific
17
18
  @token = token
18
19
  @visits = {}
19
20
  @fleet = {}
21
+ @options = {}
20
22
  end
21
23
 
22
24
  # Sets a visit for the specified location using the specified parameters
23
25
  # id: ID of location to visit
24
26
  # params: parameters for this visit
25
27
  def setVisit(id, params={})
26
- visits[id] = Visit.new(id, params)
28
+ visits[id] = RoutificApi::Visit.new(id, params)
27
29
  end
28
30
 
29
31
  # Sets a vehicle with the specified ID and parameters
30
32
  # id: vehicle ID
31
33
  # params: parameters for this vehicle
32
34
  def setVehicle(id, params)
33
- fleet[id] = Vehicle.new(id, params)
35
+ fleet[id] = RoutificApi::Vehicle.new(id, params)
36
+ end
37
+
38
+ # Sets options with the specified params
39
+ # params: parameters for these options
40
+ def setOptions(params)
41
+ @options = RoutificApi::Options.new(params)
34
42
  end
35
43
 
36
44
  # Returns the route using the previously provided visits and fleet information
@@ -40,6 +48,7 @@ class Routific
40
48
  fleet: fleet
41
49
  }
42
50
 
51
+ data[:options] = options if options
43
52
  Routific.getRoute(data, token)
44
53
  end
45
54
 
@@ -76,8 +85,8 @@ class Routific
76
85
  # Parse the HTTP request response to JSON
77
86
  jsonResponse = JSON.parse(response)
78
87
 
79
- # Parse the JSON representation into a Route object
80
- Route.parse(jsonResponse)
88
+ # Parse the JSON representation into a RoutificApi::Route object
89
+ RoutificApi::Route.parse(jsonResponse)
81
90
  rescue => e
82
91
  puts e
83
92
  errorResponse = JSON.parse e.response.body
@@ -1,52 +1,54 @@
1
- # This class represents a location in the network
2
- class Location
3
- attr_accessor :name, :lat, :lng
1
+ module RoutificApi
2
+ # This class represents a location in the network
3
+ class Location
4
+ attr_accessor :name, :lat, :lng
4
5
 
5
- # Constructor
6
- #
7
- # Required arguments in params:
8
- # lat: Latitude of this location
9
- # lng: Longitude of this location
10
- #
11
- # Optional arguments in params:
12
- # name: Name of this location
13
- def initialize(params)
14
- # Validates the parameters provided
15
- validate(params)
6
+ # Constructor
7
+ #
8
+ # Required arguments in params:
9
+ # lat: Latitude of this location
10
+ # lng: Longitude of this location
11
+ #
12
+ # Optional arguments in params:
13
+ # name: Name of this location
14
+ def initialize(params)
15
+ # Validates the parameters provided
16
+ validate(params)
16
17
 
17
- @lat = params["lat"]
18
- @lng = params["lng"]
19
- @name = params["name"]
20
- end
18
+ @lat = params["lat"]
19
+ @lng = params["lng"]
20
+ @name = params["name"]
21
+ end
21
22
 
22
- def ==(another_location)
23
- self.name == another_location.name &&
24
- self.lat == another_location.lat &&
25
- self.lng == another_location.lng
26
- end
23
+ def ==(another_location)
24
+ self.name == another_location.name &&
25
+ self.lat == another_location.lat &&
26
+ self.lng == another_location.lng
27
+ end
27
28
 
28
- def to_json(options = nil)
29
- as_json(options).to_json
30
- end
29
+ def to_json(options = nil)
30
+ as_json(options).to_json
31
+ end
31
32
 
32
- # Returns the JSON representation of this object
33
- # def to_json(options = nil)
34
- def as_json(options = nil)
35
- jsonData = {}
36
- jsonData["name"] = self.name if self.name
37
- jsonData["lat"] = self.lat
38
- jsonData["lng"] = self.lng
33
+ # Returns the JSON representation of this object
34
+ # def to_json(options = nil)
35
+ def as_json(options = nil)
36
+ jsonData = {}
37
+ jsonData["name"] = self.name if self.name
38
+ jsonData["lat"] = self.lat
39
+ jsonData["lng"] = self.lng
39
40
 
40
- jsonData
41
- end
41
+ jsonData
42
+ end
42
43
 
43
- private
44
- # Validates the parameters being provided
45
- # Raises an ArgumentError if any of the required parameters is not provided.
46
- # Required parameters are: latitude and longitude
47
- def validate(params)
48
- if(params["lat"].nil? || params["lng"].nil?)
49
- raise ArgumentError, "'lat' and 'lng' parameters must be provided"
44
+ private
45
+ # Validates the parameters being provided
46
+ # Raises an ArgumentError if any of the required parameters is not provided.
47
+ # Required parameters are: latitude and longitude
48
+ def validate(params)
49
+ if(params["lat"].nil? || params["lng"].nil?)
50
+ raise ArgumentError, "'lat' and 'lng' parameters must be provided"
51
+ end
50
52
  end
51
53
  end
52
54
  end
@@ -1,48 +1,47 @@
1
- # This class represents the resulting route returned by the Routific API
2
- class Route
3
- attr_reader :status, :fitness, :unserved, :vehicleRoutes
1
+ module RoutificApi
2
+ # This class represents the resulting route returned by the Routific API
3
+ class Route
4
+ attr_reader :status, :fitness, :unserved, :vehicleRoutes
4
5
 
5
- # Constructor
6
- def initialize(status, fitness, unserved)
7
- @status = status
8
- @fitness = fitness
9
- @unserved = unserved
10
- @vehicleRoutes = Hash.new()
11
- end
6
+ # Constructor
7
+ def initialize(status, fitness, unserved)
8
+ @status = status
9
+ @fitness = fitness
10
+ @unserved = unserved
11
+ @vehicleRoutes = Hash.new()
12
+ end
12
13
 
13
- # Adds a new way point for the specified vehicle
14
- def addWayPoint(vehicle_name, way_point)
15
- if @vehicleRoutes[vehicle_name].nil?
16
- # No previous way point was added for the specified vehicle, so create a new array
17
- @vehicleRoutes[vehicle_name] = []
14
+ # Adds a new way point for the specified vehicle
15
+ def addWayPoint(vehicle_name, way_point)
16
+ if @vehicleRoutes[vehicle_name].nil?
17
+ # No previous way point was added for the specified vehicle, so create a new array
18
+ @vehicleRoutes[vehicle_name] = []
19
+ end
20
+ # Adds the provided way point for the specified vehicle
21
+ @vehicleRoutes[vehicle_name] << way_point
18
22
  end
19
- # Adds the provided way point for the specified vehicle
20
- @vehicleRoutes[vehicle_name] << way_point
21
- end
22
23
 
23
- class << self
24
- # Parse the JSON representation of a route, and return it as a Route object
25
- def parse(routeJson)
26
- status = routeJson["status"]
27
- fitness = routeJson["fitness"]
28
- unserved = routeJson["unserved"]
29
- route = Route.new(status, fitness, unserved)
24
+ class << self
25
+ # Parse the JSON representation of a route, and return it as a Route object
26
+ def parse(routeJson)
27
+ status = routeJson["status"]
28
+ fitness = routeJson["fitness"]
29
+ unserved = routeJson["unserved"]
30
+ route = RoutificApi::Route.new(status, fitness, unserved)
30
31
 
31
- # Get way points for each vehicles
32
- routeJson["solution"].each do |vehicle_name, way_points|
33
- # Get all way points for this vehicle
34
- way_points.each do |waypoint_info|
35
- # Get all information for this way point
36
- location_id = waypoint_info["location_id"]
37
- arrival_time = waypoint_info["arrival_time"]
38
- finish_time = waypoint_info["finish_time"]
39
- way_point = WayPoint.new(location_id, arrival_time, finish_time)
40
- route.addWayPoint(vehicle_name, way_point)
32
+ # Get way points for each vehicles
33
+ routeJson["solution"].each do |vehicle_name, way_points|
34
+ # Get all way points for this vehicle
35
+ way_points.each do |waypoint_info|
36
+ # Get all information for this way point
37
+ way_point = RoutificApi::WayPoint.new(waypoint_info)
38
+ route.addWayPoint(vehicle_name, way_point)
39
+ end
41
40
  end
42
- end
43
41
 
44
- # Return the resulting Route object
45
- route
42
+ # Return the resulting Route object
43
+ route
44
+ end
46
45
  end
47
46
  end
48
47
  end
@@ -1,55 +1,57 @@
1
- # This class represents a vehicle in the fleet
2
- class Vehicle
3
- attr_accessor :id, :start_location, :end_location, :shift_start, :shift_end, :capacity
1
+ module RoutificApi
2
+ # This class represents a vehicle in the fleet
3
+ class Vehicle
4
+ attr_accessor :id, :start_location, :end_location, :shift_start, :shift_end, :capacity
4
5
 
5
- # Constructor
6
- #
7
- # Required arguments in params:
8
- # start_location: start location for this vehicle. Instance of Location
9
- #
10
- # Optional arguments in params:
11
- # end_location: end location for this vehicle. Instance of Location
12
- # shift_start: this vehicle's start shift time (e.g. '08:00'). Default value is 00:00, if not specified.
13
- # shift_end: this vehicle's end shift time (e.g. '17:00'). Default value is 23:59, if not specified.
14
- # capacity: the capacity that this vehicle can load
15
- def initialize(id, params)
16
- validate(params)
6
+ # Constructor
7
+ #
8
+ # Required arguments in params:
9
+ # start_location: start location for this vehicle. Instance of Location
10
+ #
11
+ # Optional arguments in params:
12
+ # end_location: end location for this vehicle. Instance of Location
13
+ # shift_start: this vehicle's start shift time (e.g. '08:00'). Default value is 00:00, if not specified.
14
+ # shift_end: this vehicle's end shift time (e.g. '17:00'). Default value is 23:59, if not specified.
15
+ # capacity: the capacity that this vehicle can load
16
+ def initialize(id, params)
17
+ validate(params)
17
18
 
18
- @id = id
19
- @start_location = Location.new(params["start_location"])
20
- if params["end_location"]
21
- @end_location = Location.new(params["end_location"])
19
+ @id = id
20
+ @start_location = RoutificApi::Location.new(params["start_location"])
21
+ if params["end_location"]
22
+ @end_location = RoutificApi::Location.new(params["end_location"])
23
+ end
24
+ @shift_start = params["shift_start"]
25
+ @shift_end = params["shift_end"]
26
+ @capacity = params["capacity"]
22
27
  end
23
- @shift_start = params["shift_start"]
24
- @shift_end = params["shift_end"]
25
- @capacity = params["capacity"]
26
- end
27
28
 
28
- def to_json(options=nil)
29
- as_json(options).to_json
30
- end
29
+ def to_json(options=nil)
30
+ as_json(options).to_json
31
+ end
31
32
 
32
- # Returns the JSON representation of this object
33
- # def to_json(options = nil)
34
- def as_json(options = nil)
35
- jsonData = {}
36
- jsonData["start_location"] = self.start_location.as_json
37
- jsonData["end_location"] = self.end_location.as_json if self.end_location
38
- jsonData["shift_start"] = self.shift_start if self.shift_start
39
- jsonData["shift_end"] = self.shift_end if self.shift_end
40
- jsonData["capacity"] = self.capacity if self.capacity
33
+ # Returns the JSON representation of this object
34
+ # def to_json(options = nil)
35
+ def as_json(options = nil)
36
+ jsonData = {}
37
+ jsonData["start_location"] = self.start_location.as_json
38
+ jsonData["end_location"] = self.end_location.as_json if self.end_location
39
+ jsonData["shift_start"] = self.shift_start if self.shift_start
40
+ jsonData["shift_end"] = self.shift_end if self.shift_end
41
+ jsonData["capacity"] = self.capacity if self.capacity
41
42
 
42
- jsonData
43
- end
43
+ jsonData
44
+ end
44
45
 
45
46
 
46
- private
47
- # Validates the parameters being provided
48
- # Raises an ArgumentError if any of the required parameters is not provided.
49
- # Required parameters are: location
50
- def validate(params)
51
- if params["start_location"].nil?
52
- raise ArgumentError, "'start-location' parameter must be provided"
47
+ private
48
+ # Validates the parameters being provided
49
+ # Raises an ArgumentError if any of the required parameters is not provided.
50
+ # Required parameters are: location
51
+ def validate(params)
52
+ if params["start_location"].nil?
53
+ raise ArgumentError, "'start-location' parameter must be provided"
54
+ end
53
55
  end
54
56
  end
55
57
  end
@@ -1,49 +1,51 @@
1
- # This class represents a location to be visited
2
- class Visit
3
- attr_reader :id, :start, :end, :duration, :demand, :location
1
+ module RoutificApi
2
+ # This class represents a location to be visited
3
+ class Visit
4
+ attr_reader :id, :start, :end, :duration, :demand, :location
4
5
 
5
- # Constructor
6
- #
7
- # Optional arguments in params:
8
- # start: the earliest time for this visit. Default value is 00:00, if not specified.
9
- # end: the latest time for this visit. Default value is 23:59, if not specified.
10
- # duration: the length of this visit in minutes
11
- # demand: the capacity that this visit requires
12
- # location: the location of the visit. Instance of Location
13
- def initialize(id, params = {})
14
- validate(params)
15
- @id = id
16
- @start = params["start"]
17
- @end = params["end"]
18
- @duration = params["duration"]
19
- @demand = params["demand"]
20
- @location = Location.new(params["location"])
21
- end
6
+ # Constructor
7
+ #
8
+ # Optional arguments in params:
9
+ # start: the earliest time for this visit. Default value is 00:00, if not specified.
10
+ # end: the latest time for this visit. Default value is 23:59, if not specified.
11
+ # duration: the length of this visit in minutes
12
+ # demand: the capacity that this visit requires
13
+ # location: the location of the visit. Instance of Location
14
+ def initialize(id, params = {})
15
+ validate(params)
16
+ @id = id
17
+ @start = params["start"]
18
+ @end = params["end"]
19
+ @duration = params["duration"]
20
+ @demand = params["demand"]
21
+ @location = RoutificApi::Location.new(params["location"])
22
+ end
22
23
 
23
- def to_json(options)
24
- as_json(options).to_json
25
- end
24
+ def to_json(options)
25
+ as_json(options).to_json
26
+ end
26
27
 
27
- # Returns the JSON representation of this object
28
- # def to_json(options = nil)
29
- def as_json(options = nil)
30
- jsonData = {}
31
- jsonData["start"] = self.start if self.start
32
- jsonData["end"] = self.end if self.end
33
- jsonData["duration"] = self.duration if self.duration
34
- jsonData["demand"] = self.demand if self.demand
35
- jsonData["location"] = self.location.as_json
28
+ # Returns the JSON representation of this object
29
+ # def to_json(options = nil)
30
+ def as_json(options = nil)
31
+ jsonData = {}
32
+ jsonData["start"] = self.start if self.start
33
+ jsonData["end"] = self.end if self.end
34
+ jsonData["duration"] = self.duration if self.duration
35
+ jsonData["demand"] = self.demand if self.demand
36
+ jsonData["location"] = self.location.as_json
36
37
 
37
- jsonData
38
- end
38
+ jsonData
39
+ end
39
40
 
40
- private
41
- # Validates the parameters being provided
42
- # Raises an ArgumentError if any of the required parameters is not provided.
43
- # Required parameters are: location
44
- def validate(params)
45
- if params["location"].nil?
46
- raise ArgumentError, "'location' parameter must be provided"
41
+ private
42
+ # Validates the parameters being provided
43
+ # Raises an ArgumentError if any of the required parameters is not provided.
44
+ # Required parameters are: location
45
+ def validate(params)
46
+ if params["location"].nil?
47
+ raise ArgumentError, "'location' parameter must be provided"
48
+ end
47
49
  end
48
50
  end
49
51
  end
@@ -1,11 +1,14 @@
1
- # This class represents a location to visit in the route
2
- class WayPoint
3
- attr_reader :location_id, :arrival_time, :finish_time
1
+ module RoutificApi
2
+ # This class represents a location to visit in the route
3
+ class WayPoint
4
+ attr_reader :location_id, :arrival_time, :finish_time, :location_name
4
5
 
5
- # Constructor
6
- def initialize(location_id, arrival_time, finish_time)
7
- @location_id = location_id
8
- @arrival_time = arrival_time
9
- @finish_time = finish_time
6
+ # Constructor
7
+ def initialize(options = {})
8
+ @location_id = options['location_id']
9
+ @arrival_time = options['arrival_time']
10
+ @finish_time = options['finish_time']
11
+ @location_name = options['location_name']
12
+ end
10
13
  end
11
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: routific
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc Kuo
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-10-26 00:00:00.000000000 Z
12
+ date: 2016-04-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -81,34 +81,6 @@ dependencies:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0.11'
84
- - !ruby/object:Gem::Dependency
85
- name: byebug
86
- requirement: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - "~>"
89
- - !ruby/object:Gem::Version
90
- version: '3.5'
91
- type: :development
92
- prerelease: false
93
- version_requirements: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - "~>"
96
- - !ruby/object:Gem::Version
97
- version: '3.5'
98
- - !ruby/object:Gem::Dependency
99
- name: pry-byebug
100
- requirement: !ruby/object:Gem::Requirement
101
- requirements:
102
- - - "~>"
103
- - !ruby/object:Gem::Version
104
- version: '2.0'
105
- type: :development
106
- prerelease: false
107
- version_requirements: !ruby/object:Gem::Requirement
108
- requirements:
109
- - - "~>"
110
- - !ruby/object:Gem::Version
111
- version: '2.0'
112
84
  description: Gem to use Routific API
113
85
  email: asoesilo@live.com
114
86
  executables: []