routific 0.0.4 → 1.0.0a

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: 340ed36c4db7569fd0679c3e58431486ecfaeaf9
4
- data.tar.gz: f4b9bc9f9b6b9dd71a7a4224e6d375838e1df543
3
+ metadata.gz: c43eb62c5c532be88022366d509eb35ed7d9bf06
4
+ data.tar.gz: 2d6d5a8452eeab57ff608196bcf48fc19de7eda6
5
5
  SHA512:
6
- metadata.gz: 3e7e5acc2e1c239251fc6cf0dae6898a1b47a2b3870500f1df6d068ed61a73bc1e252a92f5ed896b35862e115def1638750d15baaf89e162c7ce74741f09f4e6
7
- data.tar.gz: ddde157979fa350588935653e8ae63e2197fe685e5352f65c4c6e76cedfbf0b3fb4b79d7de5519daa1bfe28377b30b474382e47236fc800161c90256e83f9ef6
6
+ metadata.gz: df8cea59d6224904a54e20ac9c13e222b66c074e85e2abbcb5a4029244e150ddf4126fbed2ad2e3b36913af2ec0eeb0efa63b0961ed9306e6426dfd0bb230746
7
+ data.tar.gz: 93f6fcf341e85634b8f055b848013679a0c41c629ab2996a1440595966279763c147c9e549de8b5101ed1620878dbc2d0cf4c16a2f55d70c81d7e99d711bfc5a
data/README.md CHANGED
@@ -23,22 +23,16 @@ routific = Routific.new(--API_KEY--)
23
23
 
24
24
  ### Instance methods
25
25
 
26
- `routific.setLocation( id, params )`
26
+ `routific.setVisit( id, [params] )`
27
27
 
28
- Sets a location with the specified ID and parameters
28
+ Sets a visit for the specified location using the specified parameters
29
29
 
30
30
  Required arguments in params:
31
31
 
32
- - lat: Latitude of this location
33
- - lng: Longitude of this location
34
-
35
- Optional arguments in params:
36
-
37
- - name: Name of this location
38
-
39
- `routific.setVisit( id, [params] )`
40
-
41
- Sets a visit for the specified location using the specified parameters
32
+ - location: Object representing the location of the visit.
33
+ + lat: Latitude of this location
34
+ + lng: Longitude of this location
35
+ + name: (optional) Name of the location
42
36
 
43
37
  Optional arguments in params:
44
38
 
@@ -53,11 +47,18 @@ Sets a vehicle with the specified ID and parameters
53
47
 
54
48
  Required arguments in params:
55
49
 
56
- - start_location: ID of start location for this vehicle
50
+ - start_location: Object representing the start location for this vehicle.
51
+ + lat: Latitude of this location
52
+ + lng: Longitude of this location
53
+ + name: (optional) Name of the location
57
54
 
58
55
  Optional arguments in params:
59
56
 
60
- - end_location: ID of end location for this vehicle
57
+ - end_location: Object representing the end location for this vehicle.
58
+ + lat: Latitude of this location
59
+ + lng: Longitude of this location
60
+ + name: (optional) Name of the location
61
+
61
62
  - shift_start: this vehicle's start shift time (e.g. '08:00'). Default value is 00:00, if not specified.
62
63
  - shift_end: this vehicle's end shift time (e.g. '17:00'). Default value is 23:59, if not specified.
63
64
  - capacity: the capacity that this vehicle can load
@@ -94,27 +95,28 @@ require 'routific'
94
95
 
95
96
  routific = Routific.new(--API_KEY--)
96
97
 
97
- routific.setLocation("order_1", {
98
- "name" => "6800 Cambie",
99
- "lat" => 49.227107,
100
- "lng" => -123.1163085,
101
- })
102
-
103
- routific.setLocation("depot", {
104
- "name" => "800 Kingsway",
105
- "lat" => 49.2553636,
106
- "lng" => -123.0873365,
107
- })
108
-
109
98
  routific.setVisit("order_1", {
110
99
  "start" => "9:00",
111
100
  "end" => "12:00",
112
101
  "duration" => 10,
102
+ "location" => {
103
+ "name" => "6800 Cambie",
104
+ "lat" => 49.227107,
105
+ "lng" => -123.1163085,
106
+ }
113
107
  })
114
108
 
115
109
  routific.setVehicle("vehicle_1", {
116
- "start_location" => "depot",
117
- "end_location" => "depot",
110
+ "start_location" => {
111
+ "name" => "800 Kingsway",
112
+ "lat" => 49.2553636,
113
+ "lng" => -123.0873365,
114
+ },
115
+ "end_location" => {
116
+ "name" => "800 Kingsway",
117
+ "lat" => 49.2553636,
118
+ "lng" => -123.0873365,
119
+ },
118
120
  "shift_start" => "8:00",
119
121
  "shift_end" => "12:00",
120
122
  })
@@ -129,38 +131,37 @@ require 'routific'
129
131
 
130
132
  Routific.setToken(--API_KEY--)
131
133
 
132
- network = {
133
- "order_1" => {
134
- "name" => "6800 Cambie",
135
- "lat" => 49.227107,
136
- "lng" => -123.1163085
137
- },
138
- "depot" => {
139
- "name" => "800 Kingsway",
140
- "lat" => 49.2553636,
141
- "lng" => -123.0873365
142
- }
143
- }
144
-
145
134
  visits = {
146
135
  "order_1" => {
147
136
  "start" => "9:00",
148
137
  "end" => "12:00",
149
- "duration" => 10
138
+ "duration" => 10,
139
+ "location" => {
140
+ "name" => "6800 Cambie",
141
+ "lat" => 49.227107,
142
+ "lng" => -123.1163085
143
+ }
150
144
  }
151
145
  }
152
146
 
153
147
  fleet = {
154
148
  "vehicle_1" => {
155
- "start-location" => "depot",
156
- "end-location" => "depot",
157
- "shift-start" => "8:00",
158
- "shift-end" => "12:00"
149
+ "start_location" => {
150
+ "name" => "800 Kingsway",
151
+ "lat" => 49.2553636,
152
+ "lng" => -123.0873365
153
+ },
154
+ "end_location" => {
155
+ "name" => "800 Kingsway",
156
+ "lat" => 49.2553636,
157
+ "lng" => -123.0873365
158
+ },
159
+ "shift_start" => "8:00",
160
+ "shift_end" => "12:00"
159
161
  }
160
162
  }
161
163
 
162
164
  data = {
163
- network: network,
164
165
  visits: visits,
165
166
  fleet: fleet
166
167
  }
@@ -9,42 +9,33 @@ require_relative './routific/way_point'
9
9
 
10
10
  # Main class of this gem
11
11
  class Routific
12
- attr_reader :token, :network, :visits, :fleet
12
+ attr_reader :token, :visits, :fleet
13
13
 
14
14
  # Constructor
15
15
  # token: Access token for Routific API
16
16
  def initialize(token)
17
17
  @token = token
18
- @network = {}
19
18
  @visits = {}
20
19
  @fleet = {}
21
20
  end
22
21
 
23
- # Sets a location with the specified ID and parameters
24
- # id: location ID
25
- # params: parameters for this location
26
- def setLocation(id, params)
27
- network[id] = Location.new(params)
28
- end
29
-
30
22
  # Sets a visit for the specified location using the specified parameters
31
23
  # id: ID of location to visit
32
24
  # params: parameters for this visit
33
25
  def setVisit(id, params={})
34
- visits[id] = Visit.new(params)
26
+ visits[id] = Visit.new(id, params)
35
27
  end
36
28
 
37
29
  # Sets a vehicle with the specified ID and parameters
38
30
  # id: vehicle ID
39
31
  # params: parameters for this vehicle
40
32
  def setVehicle(id, params)
41
- fleet[id] = Vehicle.new(params)
33
+ fleet[id] = Vehicle.new(id, params)
42
34
  end
43
35
 
44
- # Returns the route using the previously provided network, visits and fleet information
36
+ # Returns the route using the previously provided visits and fleet information
45
37
  def getRoute
46
38
  data = {
47
- network: network,
48
39
  visits: visits,
49
40
  fleet: fleet
50
41
  }
@@ -62,7 +53,7 @@ class Routific
62
53
  @@token
63
54
  end
64
55
 
65
- # Returns the route using the specified access token, network, visits and fleet information
56
+ # Returns the route using the specified access token, visits and fleet information
66
57
  # If no access token is provided, the default access token previously set is used
67
58
  # If the default access token either is nil or has not been set, an ArgumentError is raised
68
59
  def getRoute(data, token = @@token)
@@ -75,7 +66,7 @@ class Routific
75
66
 
76
67
  begin
77
68
  # Sends HTTP request to Routific API server
78
- response = RestClient.post('https://routific.com/api/vrp',
69
+ response = RestClient.post('https://api.routific.com/v1/vrp',
79
70
  data.to_json,
80
71
  'Authorization' => prefixed_token,
81
72
  content_type: :json,
@@ -88,6 +79,7 @@ class Routific
88
79
  # Parse the JSON representation into a Route object
89
80
  Route.parse(jsonResponse)
90
81
  rescue => e
82
+ puts e
91
83
  errorResponse = JSON.parse e.response.body
92
84
  puts "Received HTTP #{e.message}: #{errorResponse["error"]}"
93
85
  nil
@@ -19,6 +19,12 @@ class Location
19
19
  @name = params["name"]
20
20
  end
21
21
 
22
+ def ==(another_location)
23
+ self.name == another_location.name &&
24
+ self.lat == another_location.lat &&
25
+ self.lng == another_location.lng
26
+ end
27
+
22
28
  def to_json(options = nil)
23
29
  as_json(options).to_json
24
30
  end
@@ -43,4 +49,4 @@ class Location
43
49
  raise ArgumentError, "'lat' and 'lng' parameters must be provided"
44
50
  end
45
51
  end
46
- end
52
+ end
@@ -34,10 +34,9 @@ class Route
34
34
  way_points.each do |waypoint_info|
35
35
  # Get all information for this way point
36
36
  location_id = waypoint_info["location_id"]
37
- location_name = waypoint_info["location_name"]
38
37
  arrival_time = waypoint_info["arrival_time"]
39
38
  finish_time = waypoint_info["finish_time"]
40
- way_point = WayPoint.new(location_id, location_name, arrival_time, finish_time)
39
+ way_point = WayPoint.new(location_id, arrival_time, finish_time)
41
40
  route.addWayPoint(vehicle_name, way_point)
42
41
  end
43
42
  end
@@ -46,4 +45,4 @@ class Route
46
45
  route
47
46
  end
48
47
  end
49
- end
48
+ end
@@ -1,23 +1,25 @@
1
1
  # This class represents a vehicle in the fleet
2
2
  class Vehicle
3
- attr_accessor :start_location, :end_location, :shift_start, :shift_end, :capacity
3
+ attr_accessor :id, :start_location, :end_location, :shift_start, :shift_end, :capacity
4
4
 
5
5
  # Constructor
6
6
  #
7
7
  # Required arguments in params:
8
- # start_location: ID of start location for this vehicle
8
+ # start_location: start location for this vehicle. Instance of Location
9
9
  #
10
10
  # Optional arguments in params:
11
- # end_location: ID of end location for this vehicle
11
+ # end_location: end location for this vehicle. Instance of Location
12
12
  # shift_start: this vehicle's start shift time (e.g. '08:00'). Default value is 00:00, if not specified.
13
13
  # shift_end: this vehicle's end shift time (e.g. '17:00'). Default value is 23:59, if not specified.
14
14
  # capacity: the capacity that this vehicle can load
15
- def initialize(params)
16
- # Validates the provided parameters
15
+ def initialize(id, params)
17
16
  validate(params)
18
17
 
19
- @start_location = params["start_location"]
20
- @end_location = params["end_location"]
18
+ @id = id
19
+ @start_location = Location.new(params["start_location"])
20
+ if params["end_location"]
21
+ @end_location = Location.new(params["end_location"])
22
+ end
21
23
  @shift_start = params["shift_start"]
22
24
  @shift_end = params["shift_end"]
23
25
  @capacity = params["capacity"]
@@ -31,22 +33,23 @@ class Vehicle
31
33
  # def to_json(options = nil)
32
34
  def as_json(options = nil)
33
35
  jsonData = {}
34
- jsonData["start-location"] = self.start_location
35
- jsonData["end-location"] = self.end_location if self.end_location
36
- jsonData["shift-start"] = self.shift_start if self.shift_start
37
- jsonData["shift-end"] = self.shift_end if self.shift_end
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
38
40
  jsonData["capacity"] = self.capacity if self.capacity
39
41
 
40
42
  jsonData
41
43
  end
42
44
 
45
+
43
46
  private
44
47
  # Validates the parameters being provided
45
48
  # Raises an ArgumentError if any of the required parameters is not provided.
46
- # Required parameter is: start_location
49
+ # Required parameters are: location
47
50
  def validate(params)
48
- if(params["start_location"].nil?)
49
- raise ArgumentError, "'start_location' parameter must be provided"
51
+ if params["start_location"].nil?
52
+ raise ArgumentError, "'start-location' parameter must be provided"
50
53
  end
51
54
  end
52
- end
55
+ end
@@ -1,6 +1,6 @@
1
1
  # This class represents a location to be visited
2
2
  class Visit
3
- attr_reader :start, :end, :duration, :demand
3
+ attr_reader :id, :start, :end, :duration, :demand, :location
4
4
 
5
5
  # Constructor
6
6
  #
@@ -9,11 +9,15 @@ class Visit
9
9
  # end: the latest time for this visit. Default value is 23:59, if not specified.
10
10
  # duration: the length of this visit in minutes
11
11
  # demand: the capacity that this visit requires
12
- def initialize(params = {})
12
+ # location: the location of the visit. Instance of Location
13
+ def initialize(id, params = {})
14
+ validate(params)
15
+ @id = id
13
16
  @start = params["start"]
14
17
  @end = params["end"]
15
18
  @duration = params["duration"]
16
19
  @demand = params["demand"]
20
+ @location = Location.new(params["location"])
17
21
  end
18
22
 
19
23
  def to_json(options)
@@ -28,7 +32,18 @@ class Visit
28
32
  jsonData["end"] = self.end if self.end
29
33
  jsonData["duration"] = self.duration if self.duration
30
34
  jsonData["demand"] = self.demand if self.demand
35
+ jsonData["location"] = self.location.as_json
31
36
 
32
37
  jsonData
33
38
  end
34
- end
39
+
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"
47
+ end
48
+ end
49
+ end
@@ -1,12 +1,11 @@
1
1
  # This class represents a location to visit in the route
2
2
  class WayPoint
3
- attr_reader :location_id, :location_name, :arrival_time, :finish_time
3
+ attr_reader :location_id, :arrival_time, :finish_time
4
4
 
5
5
  # Constructor
6
- def initialize(location_id, location_name, arrival_time, finish_time)
6
+ def initialize(location_id, arrival_time, finish_time)
7
7
  @location_id = location_id
8
- @location_name = location_name
9
8
  @arrival_time = arrival_time
10
9
  @finish_time = finish_time
11
10
  end
12
- end
11
+ 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: 0.0.4
4
+ version: 1.0.0a
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-01-31 00:00:00.000000000 Z
12
+ date: 2015-06-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -139,12 +139,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
139
139
  version: '0'
140
140
  required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  requirements:
142
- - - ">="
142
+ - - ">"
143
143
  - !ruby/object:Gem::Version
144
- version: '0'
144
+ version: 1.3.1
145
145
  requirements: []
146
146
  rubyforge_project:
147
- rubygems_version: 2.4.5
147
+ rubygems_version: 2.2.2
148
148
  signing_key:
149
149
  specification_version: 4
150
150
  summary: routific API