routific 1.1.0 → 1.1.1

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/routific/options.rb +49 -0
  3. metadata +10 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ea5df053d952f0517202e18e26493a3d986b739
4
- data.tar.gz: 5b13d657ff00d3d4bc930a9e9f0191ac1b009226
3
+ metadata.gz: 80f461bbd6a8c76891619ef0e6eac1a430eb5aa7
4
+ data.tar.gz: 659b39f98fcd1b8d45d93cbde3b99f59eb8e0a2a
5
5
  SHA512:
6
- metadata.gz: de46d973cc679f1cfe20d1bd3fdd6a9699ba25fb8bb777da63237a8aa4d6d29315af89b8c348c721ce5a4f05ef361d77c6180688b9241ded509d7acb338d1415
7
- data.tar.gz: 0e322fc0e842a8df2335e955ab89a66eb38349e15038aff18f570c09074a6ce7da0b971dd074d34a0880b49beb04d72c7a1d6c0bcad04ee8d45cc9d127f9dd79
6
+ metadata.gz: b10a6414354f038e953e4ca3366b8e6322777c92a16c7656b2f02873f49efa80a8499fffe52bc686154bfb39da91cf1b011326845560553db09910c2c7d9d038
7
+ data.tar.gz: 50130e568b9c6fd4c5a3bab8212968698b938ca699953d7aaaedbeb84578434fb6bf21606f56a93cbf36ea66cc398342a83a01534e693826bc4f7ce1ee863362
@@ -0,0 +1,49 @@
1
+ module RoutificApi
2
+ # This class represents a set of options for the request
3
+ class Options
4
+ VALID_PARAMS = %w{ traffic min_visits_per_vehicle balance min_vehicles shortest_distance }
5
+
6
+ attr_reader *VALID_PARAMS
7
+
8
+ def initialize(params)
9
+ # Validates the provided parameters
10
+ validate(params)
11
+
12
+ @traffic = params["traffic"]
13
+ @min_visits_per_vehicle = params["min_visits_per_vehicle"]
14
+ @balance = params["balance"]
15
+ @min_vehicles = params["min_vehicles"]
16
+ @shortest_distance = params["shortest_distance"]
17
+ end
18
+
19
+ def to_json(options)
20
+ as_json(options).to_json
21
+ end
22
+
23
+ # Returns the JSON representation of this object
24
+ # def to_json(options = nil)
25
+ def as_json(options = nil)
26
+ jsonData = {}
27
+ jsonData["traffic"] = self.traffic if self.traffic
28
+ jsonData["min_visits_per_vehicle"] = self.min_visits_per_vehicle if self.min_visits_per_vehicle
29
+ jsonData["balance"] = self.balance if self.balance
30
+ jsonData["shortest_distance"] = self.shortest_distance if self.shortest_distance
31
+ jsonData["min_vehicles"] = self.min_vehicles if self.min_vehicles
32
+
33
+ jsonData
34
+ end
35
+
36
+ private
37
+ # Validates the parameters being provided
38
+ # Raises an ArgumentError if any of the provided params is not supported
39
+ # Supported params are traffic, min_visits_per_vehicle, and balance
40
+ def validate(params)
41
+ invalid = params.keys.reject { |k| VALID_PARAMS.include?(k) }
42
+
43
+ if invalid.any?
44
+ invalid = invalid.join(",")
45
+ raise ArgumentError, "#{invalid} parameter is not supported"
46
+ end
47
+ end
48
+ end
49
+ 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.1.0
4
+ version: 1.1.1
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: 2016-04-16 00:00:00.000000000 Z
12
+ date: 2016-08-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -85,16 +85,16 @@ description: Gem to use Routific API
85
85
  email: asoesilo@live.com
86
86
  executables: []
87
87
  extensions: []
88
- extra_rdoc_files:
89
- - README.md
88
+ extra_rdoc_files: []
90
89
  files:
91
- - "./lib/routific.rb"
92
- - "./lib/routific/location.rb"
93
- - "./lib/routific/route.rb"
94
- - "./lib/routific/vehicle.rb"
95
- - "./lib/routific/visit.rb"
96
- - "./lib/routific/way_point.rb"
97
90
  - README.md
91
+ - lib/routific.rb
92
+ - lib/routific/location.rb
93
+ - lib/routific/options.rb
94
+ - lib/routific/route.rb
95
+ - lib/routific/vehicle.rb
96
+ - lib/routific/visit.rb
97
+ - lib/routific/way_point.rb
98
98
  homepage: https://routific.com/
99
99
  licenses:
100
100
  - MIT