weighflow_cli 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.byebug_history +15 -0
- data/Gemfile.lock +1 -1
- data/README.md +6 -4
- data/lib/weighflow_cli.rb +33 -4
- data/lib/weighflow_cli/cli.rb +131 -10
- data/lib/weighflow_cli/client.rb +24 -6
- data/lib/weighflow_cli/order_handler.rb +6 -2
- data/lib/weighflow_cli/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f43616755fac94a4e1b1afc3095bdfd03ac5dc50dd2b42ee5ae838cf6023f37
|
4
|
+
data.tar.gz: 4710b9900bca368eb76a530a15e15681357f513efdb2bdf559ce29e36393f7ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8afc73d0d13f07e9f1b893f80040b4dd4d5fa02ad664e7dc55e3567eb9430687cfe9ab956aac8c93bcef93fa80cceb0aa1940010203c2fdc67fbb2fb0f34c7a8
|
7
|
+
data.tar.gz: ce913eb0ba65a20389c685c1a5aa4a4f51cd90f2d036949c9ae40930da53b49eecb9ec7bcc1e1dc2dd3ef64666841ba71a18117888daac1309b6f4a69d94c72b
|
data/.byebug_history
CHANGED
@@ -1,4 +1,19 @@
|
|
1
1
|
c
|
2
|
+
weight_params
|
3
|
+
c
|
4
|
+
weight_params
|
5
|
+
q
|
6
|
+
weight_params
|
7
|
+
c
|
8
|
+
weight_params
|
9
|
+
q
|
10
|
+
weight_params
|
11
|
+
ap weight_params
|
12
|
+
c
|
13
|
+
ap weight_params
|
14
|
+
require 'awesome_print'
|
15
|
+
ap weight_params
|
16
|
+
c
|
2
17
|
commodity_inbounds[:orders]
|
3
18
|
inventory_inbounds[:orders]
|
4
19
|
inventory_outbounds[:orders]
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -22,13 +22,15 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
From a console prompt simple type:
|
26
26
|
|
27
|
-
|
27
|
+
```bash
|
28
28
|
|
29
|
-
|
29
|
+
$ weighflow_cli
|
30
30
|
|
31
|
-
|
31
|
+
```
|
32
|
+
|
33
|
+
Follow menu instructions
|
32
34
|
|
33
35
|
## Contributing
|
34
36
|
|
data/lib/weighflow_cli.rb
CHANGED
@@ -16,18 +16,26 @@ module WeighflowCli
|
|
16
16
|
class Error < StandardError; end
|
17
17
|
#
|
18
18
|
_ROOT_PATH = File.expand_path('~/.weighflow_cli').freeze
|
19
|
+
#
|
19
20
|
Dir.mkdir(_ROOT_PATH) unless Dir.exists?(_ROOT_PATH)
|
20
21
|
#
|
21
|
-
# Provide an
|
22
|
+
# Provide an override to relocate data directory
|
22
23
|
DATA_PATH = ENV['WEIGHFLOW_CLI_PATH'] || File.join(_ROOT_PATH, 'data')
|
23
24
|
#
|
24
25
|
#
|
25
|
-
#
|
26
|
+
# Ensure data path
|
26
27
|
Dir.mkdir(DATA_PATH) unless Dir.exists?(DATA_PATH)
|
27
28
|
#
|
28
29
|
|
29
30
|
Configuration = Struct.new(:secret, :url)
|
30
31
|
|
32
|
+
##
|
33
|
+
# This can be used to set the +secret+ and +url+ for api credentials
|
34
|
+
# this setting can be done at the console, via
|
35
|
+
# weighflow_cli login
|
36
|
+
# or through in code if using the gem within your own code by supplying
|
37
|
+
# a block and passing in the credientials.
|
38
|
+
#
|
31
39
|
def self.configuration
|
32
40
|
if block_given?
|
33
41
|
configuration = Configuration.new
|
@@ -38,24 +46,45 @@ module WeighflowCli
|
|
38
46
|
end
|
39
47
|
|
40
48
|
|
49
|
+
##
|
50
|
+
# Creates an instance of the API client lib for direct access to the api
|
41
51
|
def self.client
|
42
52
|
@client ||= Client.new(configuration)
|
43
53
|
end
|
44
54
|
|
45
55
|
|
56
|
+
##
|
57
|
+
# Pull down the orders and store in the local repository data path
|
58
|
+
# * This is used to management order changes
|
59
|
+
#
|
46
60
|
def self.pull
|
47
61
|
WeighflowCli::OrderHandler.pull
|
48
62
|
end
|
49
63
|
|
50
64
|
|
65
|
+
##
|
66
|
+
# Find a specific order based on the +external_id+ given withing the orders
|
67
|
+
# + Helps to pull order details when needed.
|
51
68
|
def self.find_order(external_id)
|
52
69
|
WeighflowCli::OrderHandler.find_order(external_id)
|
53
70
|
end
|
54
71
|
|
55
72
|
|
56
|
-
def self.list
|
57
|
-
WeighflowCli::OrderHandler.list
|
73
|
+
def self.list(indexes_only: false)
|
74
|
+
WeighflowCli::OrderHandler.list(indexes_only: indexes_only)
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.weights
|
78
|
+
client.weights
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
def self.create_weight(params: {})
|
83
|
+
client.create_weight(params: params)
|
58
84
|
end
|
59
85
|
|
86
|
+
def self.void_weight(weight_id, reason)
|
87
|
+
client.void_weight(weight_id, reason)
|
88
|
+
end
|
60
89
|
|
61
90
|
end
|
data/lib/weighflow_cli/cli.rb
CHANGED
@@ -1,15 +1,129 @@
|
|
1
|
-
|
1
|
+
require 'byebug'
|
2
|
+
|
3
|
+
module WeighflowCli
|
4
|
+
|
5
|
+
class Weights < Thor
|
6
|
+
include Rendering
|
7
|
+
|
8
|
+
desc 'from_index [INDEX ID]', 'create weight from index'
|
9
|
+
#option :index, required: true, banner: 'ie. CommodityOrder-T-I-002-3340455-01'
|
10
|
+
option :gross, aliases: '-g', type: :numeric, required: true
|
11
|
+
option :tare, aliases: '-t', type: :numeric, required: true
|
12
|
+
option :certificate, aliases: '-c', required: true
|
13
|
+
def from_index(index_id)
|
14
|
+
raise 'index_id required' unless index_id
|
15
|
+
index = WeighflowCli.find_order(index_id)
|
16
|
+
raise 'index not found for id' unless index && index.data
|
17
|
+
#
|
18
|
+
# parse external id parts
|
19
|
+
order_type, transport, io, location, order_num, lin = index.data[:external_unique_id].to_s.split('-')
|
20
|
+
#
|
21
|
+
# correct for diff in type between order and weight processor
|
22
|
+
order_type = 'Inventory' if order_type == 'BulkInventory'
|
23
|
+
#
|
24
|
+
weight_params = {
|
25
|
+
io: index.data[:i_o],
|
26
|
+
order_id: index.data[:order_id],
|
27
|
+
order_type: order_type,
|
28
|
+
gross_weight: options[:gross].to_i,
|
29
|
+
tare_weight: options[:tare].to_i,
|
30
|
+
weighed_at: Time.now.round,
|
31
|
+
certificate_number: options[:certificate].to_s
|
32
|
+
}
|
33
|
+
|
34
|
+
options_renderer(WeighflowCli.create_weight(params: weight_params), options)
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
desc 'template [INDEX_ID]', 'create weight template'
|
39
|
+
def template(index_id)
|
40
|
+
aise 'index_id required' unless index_id
|
41
|
+
index = WeighflowCli.find_order(index_id)
|
42
|
+
raise 'index not found for id' unless index && index.data
|
43
|
+
#
|
44
|
+
# parse external id parts
|
45
|
+
order_type, transport, io, location, order_num, lin = index.data[:external_unique_id].to_s.split('-')
|
46
|
+
#
|
47
|
+
# correct for diff in type between order and weight processor
|
48
|
+
order_type = 'Inventory' if order_type == 'BulkInventory'
|
49
|
+
#
|
50
|
+
weight_params = {
|
51
|
+
io: index.data[:i_o],
|
52
|
+
order_id: index.data[:order_id],
|
53
|
+
order_type: order_type,
|
54
|
+
gross_weight: 0,
|
55
|
+
tare_weight: 0,
|
56
|
+
weighed_at: Time.now.round,
|
57
|
+
certificate_number: "{cert number}"
|
58
|
+
}
|
59
|
+
options_renderer(weight_params, options)
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
desc 'list', 'List weights within the last 24 hours'
|
64
|
+
def list
|
65
|
+
options_renderer(WeighflowCli.weights, options)
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
desc 'create', 'Create a weight given an order'
|
71
|
+
long_desc <<~DESC
|
72
|
+
|
73
|
+
weighflow_cli --file weight.json
|
74
|
+
|
75
|
+
This file should contain a minimum of :
|
76
|
+
|
77
|
+
{
|
78
|
+
order_type: "Commodity",
|
79
|
+
io: "O",
|
80
|
+
order_id: "{integer}",
|
81
|
+
gross_weight: "75000",
|
82
|
+
tare_weight: "25444",
|
83
|
+
weighed_at: "2021-02-26 10:15:41 am",
|
84
|
+
release_number: "",
|
85
|
+
truck_license_number: "",
|
86
|
+
trailer1_license_number: "",
|
87
|
+
trailer2_license_number: "",
|
88
|
+
truck_number: "",
|
89
|
+
driver_name: "",
|
90
|
+
driver_number: ""
|
91
|
+
}
|
92
|
+
|
93
|
+
--
|
94
|
+
DESC
|
95
|
+
option :file, aliases: '-f', required: true, banner: '[File name] json format'
|
96
|
+
def create
|
97
|
+
weight_params = JSON.parse(File.read(options[:file]), symbolize_names: true)
|
98
|
+
puts weight_params
|
99
|
+
|
100
|
+
options_renderer(WeighflowCli.create_weight(params: weight_params), options)
|
101
|
+
#options_renderer(options, options)
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
desc 'void', 'Voided a weight within 24 hours'
|
106
|
+
option :weight_id, required: true
|
107
|
+
option :reason, required: true
|
108
|
+
def void
|
109
|
+
options_renderer(WeighflowCli.void_weight(options[:weight_id], options[:reason]), options)
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
2
114
|
class Cli < Thor
|
3
115
|
include Rendering
|
4
116
|
package_name "WeighflowCli"
|
117
|
+
class_option :yaml, type: :boolean
|
5
118
|
|
119
|
+
desc 'weights', 'weights commands'
|
120
|
+
subcommand 'weights', Weights
|
6
121
|
|
7
122
|
def self.exit_on_failure?
|
8
123
|
false
|
9
124
|
end
|
10
125
|
|
11
|
-
desc "status", "Get system status"
|
12
|
-
method_options yaml: :boolean
|
126
|
+
desc "status", "Get system status"
|
13
127
|
def status
|
14
128
|
options_renderer(WeighflowCli.client.status, options)
|
15
129
|
end
|
@@ -29,8 +143,7 @@ module WeighflowCli
|
|
29
143
|
|
30
144
|
|
31
145
|
|
32
|
-
desc "pull", "Pull Orders from Weighflow"
|
33
|
-
method_options yaml: :boolean
|
146
|
+
desc "pull", "Pull Orders from Weighflow"
|
34
147
|
def pull
|
35
148
|
options_renderer(WeighflowCli.pull, options)
|
36
149
|
end
|
@@ -38,18 +151,26 @@ module WeighflowCli
|
|
38
151
|
|
39
152
|
|
40
153
|
|
41
|
-
desc 'list', "List currently pulled orders"
|
42
|
-
method_options yaml: :boolean
|
154
|
+
desc 'list', "List currently pulled orders"
|
43
155
|
def list
|
44
156
|
options_renderer(WeighflowCli.list, options)
|
45
157
|
end
|
46
158
|
|
159
|
+
desc 'indexes', "List currently pulled order indexes"
|
160
|
+
def indexes
|
161
|
+
options_renderer(WeighflowCli.list(indexes_only: true), options)
|
162
|
+
end
|
47
163
|
|
48
164
|
|
49
|
-
|
50
165
|
|
51
|
-
|
52
|
-
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
desc 'find_order', 'Find order details'
|
53
174
|
def find_order(external_id)
|
54
175
|
if index = WeighflowCli.find_order(external_id)
|
55
176
|
options_renderer(index.data, options)
|
data/lib/weighflow_cli/client.rb
CHANGED
@@ -15,9 +15,23 @@ module WeighflowCli
|
|
15
15
|
|
16
16
|
|
17
17
|
def status
|
18
|
-
response = self.class.get('/')
|
19
|
-
|
20
|
-
|
18
|
+
response = self.class.get('/')
|
19
|
+
render_json(response)
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_weight(params: {})
|
23
|
+
response = self.class.post('/weights', body: params)
|
24
|
+
render_json(response)
|
25
|
+
end
|
26
|
+
|
27
|
+
def void_weight(weight_id, reason)
|
28
|
+
response = self.class.delete("/weights/#{weight_id}", body: { reason: reason })
|
29
|
+
render_json(response)
|
30
|
+
end
|
31
|
+
|
32
|
+
def weights
|
33
|
+
response = self.class.get('/weights')
|
34
|
+
render_json(response)
|
21
35
|
end
|
22
36
|
|
23
37
|
|
@@ -42,15 +56,19 @@ module WeighflowCli
|
|
42
56
|
private
|
43
57
|
|
44
58
|
def find_orders(selection: 'OC')
|
45
|
-
response = self.class.get('/orders', query: { s: selection })
|
46
|
-
|
47
|
-
JSON.parse(response.body, symbolize_names: true)
|
59
|
+
response = self.class.get('/orders', query: { s: selection })
|
60
|
+
render_json(response)
|
48
61
|
end
|
49
62
|
|
50
63
|
def render_error(response)
|
51
64
|
raise Error, "Problem accessing Weighflow API #{response.code} : #{response.body}"
|
52
65
|
end
|
53
66
|
|
67
|
+
def render_json(response)
|
68
|
+
render_error(response) unless response.success?
|
69
|
+
JSON.parse(response.body, symbolize_names: true)
|
70
|
+
end
|
71
|
+
|
54
72
|
end
|
55
73
|
|
56
74
|
end
|
@@ -39,11 +39,15 @@ module WeighflowCli
|
|
39
39
|
|
40
40
|
#
|
41
41
|
# List all orders currently in stored repository
|
42
|
-
def self.list
|
42
|
+
def self.list(indexes_only: false)
|
43
43
|
result = []
|
44
44
|
finder = Finder.new
|
45
45
|
finder.for_each_index do |index|
|
46
|
-
|
46
|
+
if indexes_only
|
47
|
+
result << index.index
|
48
|
+
else
|
49
|
+
result << index.data
|
50
|
+
end
|
47
51
|
end
|
48
52
|
result
|
49
53
|
end
|