weighflow_cli 0.2.5 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.byebug_history +19 -0
- data/.gitignore +2 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +16 -2
- data/exe/weighflow_cli +2 -1
- data/lib/weighflow_cli.rb +16 -6
- data/lib/weighflow_cli/cli.rb +8 -126
- data/lib/weighflow_cli/cli_weights.rb +111 -0
- data/lib/weighflow_cli/client.rb +1 -1
- data/lib/weighflow_cli/credentials.rb +1 -1
- data/lib/weighflow_cli/order_handler.rb +2 -2
- data/lib/weighflow_cli/rendering.rb +1 -1
- data/lib/weighflow_cli/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93ff8b4ee53a8072ca02fba4d89306b6fa79e267acf5cef3b1b19e7f3026b513
|
4
|
+
data.tar.gz: 852410b8061d467471b9115a50ce9e9314c4cada5be144f2f7dfce1e207a757c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 553708867bc04f2ffe9287be500c07c5c22e7baf5e2a44a4504637dbff7b62f758abb99c245a47a36c3c447342f1fcbc8f7d01981320f4d77d43ec82eb458e46
|
7
|
+
data.tar.gz: b7fb62070b2028f027e630574f0c1903ab64bb13fc0b3ccef2e2a183ea44c27566f4ad09cf52b049e302ca6bd9b8c26b0c89fb1c0d91109738d63641da71c00f
|
data/.byebug_history
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
q
|
2
|
+
C
|
3
|
+
WeighflowCli::ROOT_PATH
|
4
|
+
c
|
5
|
+
WeighflowCli::_ROOT_PATH
|
6
|
+
WeighflowCli
|
7
|
+
_ROOT_PATH
|
8
|
+
c
|
9
|
+
ap result.first.keys
|
10
|
+
ap keys
|
11
|
+
q
|
12
|
+
c
|
13
|
+
uri
|
14
|
+
uri.port = 80
|
15
|
+
uri.methods
|
16
|
+
ap uri
|
17
|
+
c
|
18
|
+
result.class
|
19
|
+
ap result
|
1
20
|
c
|
2
21
|
weight_params
|
3
22
|
c
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,25 +1,32 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
weighflow_cli (0.2.
|
4
|
+
weighflow_cli (0.2.9)
|
5
5
|
httparty
|
6
6
|
thor (~> 1.1.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
+
addressable (2.7.0)
|
12
|
+
public_suffix (>= 2.0.2, < 5.0)
|
11
13
|
awesome_print (1.8.0)
|
12
14
|
byebug (11.1.3)
|
15
|
+
crack (0.4.5)
|
16
|
+
rexml
|
13
17
|
diff-lcs (1.4.4)
|
14
18
|
gem-release (2.2.1)
|
19
|
+
hashdiff (1.0.1)
|
15
20
|
httparty (0.18.1)
|
16
21
|
mime-types (~> 3.0)
|
17
22
|
multi_xml (>= 0.5.2)
|
18
23
|
mime-types (3.3.1)
|
19
24
|
mime-types-data (~> 3.2015)
|
20
|
-
mime-types-data (3.
|
25
|
+
mime-types-data (3.2021.0225)
|
21
26
|
multi_xml (0.6.0)
|
27
|
+
public_suffix (4.0.6)
|
22
28
|
rake (13.0.3)
|
29
|
+
rexml (3.2.4)
|
23
30
|
rspec (3.10.0)
|
24
31
|
rspec-core (~> 3.10.0)
|
25
32
|
rspec-expectations (~> 3.10.0)
|
@@ -34,6 +41,11 @@ GEM
|
|
34
41
|
rspec-support (~> 3.10.0)
|
35
42
|
rspec-support (3.10.2)
|
36
43
|
thor (1.1.0)
|
44
|
+
vcr (6.0.0)
|
45
|
+
webmock (3.12.0)
|
46
|
+
addressable (>= 2.3.6)
|
47
|
+
crack (>= 0.3.2)
|
48
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
37
49
|
|
38
50
|
PLATFORMS
|
39
51
|
ruby
|
@@ -45,6 +57,8 @@ DEPENDENCIES
|
|
45
57
|
gem-release
|
46
58
|
rake (~> 13.0)
|
47
59
|
rspec (~> 3.0)
|
60
|
+
vcr
|
61
|
+
webmock
|
48
62
|
weighflow_cli!
|
49
63
|
|
50
64
|
BUNDLED WITH
|
data/exe/weighflow_cli
CHANGED
data/lib/weighflow_cli.rb
CHANGED
@@ -6,25 +6,35 @@ require 'httparty'
|
|
6
6
|
require_relative "weighflow_cli/version"
|
7
7
|
require_relative 'weighflow_cli/rendering'
|
8
8
|
require_relative 'weighflow_cli/client'
|
9
|
+
#require_relative 'weighflow_cli/cli_weights'
|
9
10
|
require_relative 'weighflow_cli/cli'
|
10
11
|
require_relative 'weighflow_cli/credentials'
|
11
12
|
require_relative 'weighflow_cli/order_handler'
|
12
13
|
|
14
|
+
|
13
15
|
|
14
16
|
module WeighflowCli
|
15
17
|
|
16
18
|
class Error < StandardError; end
|
17
19
|
#
|
18
|
-
|
20
|
+
ROOT_PATH = File.expand_path('~/.weighflow_cli').freeze
|
19
21
|
#
|
20
|
-
Dir.mkdir(
|
22
|
+
Dir.mkdir(ROOT_PATH) unless Dir.exists?(ROOT_PATH)
|
21
23
|
#
|
24
|
+
|
22
25
|
# Provide an override to relocate data directory
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
def self.data_path
|
27
|
+
return @data_path if defined?(@data_path)
|
28
|
+
@data_path ||= ENV.fetch('WEIGHFLOW_CLI_PATH') { File.join(WeighflowCli::ROOT_PATH, 'data') }
|
29
|
+
ensure_data_path
|
30
|
+
@data_path
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
26
34
|
# Ensure data path
|
27
|
-
|
35
|
+
def self.ensure_data_path
|
36
|
+
Dir.mkdir(data_path) unless Dir.exists?(data_path)
|
37
|
+
end
|
28
38
|
#
|
29
39
|
|
30
40
|
Configuration = Struct.new(:secret, :url)
|
data/lib/weighflow_cli/cli.rb
CHANGED
@@ -1,123 +1,17 @@
|
|
1
|
-
|
1
|
+
require_relative 'cli_weights'
|
2
2
|
|
3
3
|
module WeighflowCli
|
4
4
|
|
5
|
-
|
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
|
-
|
5
|
+
|
114
6
|
class Cli < Thor
|
115
7
|
include Rendering
|
8
|
+
|
9
|
+
|
116
10
|
package_name "WeighflowCli"
|
117
11
|
class_option :yaml, type: :boolean
|
118
12
|
|
119
13
|
desc 'weights', 'weights commands'
|
120
|
-
subcommand 'weights',
|
14
|
+
subcommand 'weights', CliWeights
|
121
15
|
|
122
16
|
def self.exit_on_failure?
|
123
17
|
false
|
@@ -131,7 +25,7 @@
|
|
131
25
|
|
132
26
|
desc 'data_path', "Current data path"
|
133
27
|
def data_path
|
134
|
-
puts
|
28
|
+
puts WeighflowCli.data_path
|
135
29
|
end
|
136
30
|
|
137
31
|
|
@@ -139,17 +33,13 @@
|
|
139
33
|
def login
|
140
34
|
Credentials.login
|
141
35
|
end
|
142
|
-
|
143
|
-
|
144
|
-
|
36
|
+
|
145
37
|
|
146
38
|
desc "pull", "Pull Orders from Weighflow"
|
147
39
|
def pull
|
148
40
|
options_renderer(WeighflowCli.pull, options)
|
149
41
|
end
|
150
|
-
|
151
|
-
|
152
|
-
|
42
|
+
|
153
43
|
|
154
44
|
desc 'list', "List currently pulled orders"
|
155
45
|
def list
|
@@ -160,14 +50,6 @@
|
|
160
50
|
def indexes
|
161
51
|
options_renderer(WeighflowCli.list(indexes_only: true), options)
|
162
52
|
end
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
53
|
|
172
54
|
|
173
55
|
desc 'find_order', 'Find order details'
|
@@ -0,0 +1,111 @@
|
|
1
|
+
|
2
|
+
module WeighflowCli
|
3
|
+
class CliWeights < Thor
|
4
|
+
include Rendering
|
5
|
+
|
6
|
+
desc 'from_index [INDEX ID]', 'create weight from index'
|
7
|
+
#option :index, required: true, banner: 'ie. CommodityOrder-T-I-002-3340455-01'
|
8
|
+
option :gross, aliases: '-g', type: :numeric, required: true
|
9
|
+
option :tare, aliases: '-t', type: :numeric, required: true
|
10
|
+
option :certificate, aliases: '-c', required: true
|
11
|
+
def from_index(index_id)
|
12
|
+
raise 'index_id required' unless index_id
|
13
|
+
index = WeighflowCli.find_order(index_id)
|
14
|
+
raise 'index not found for id' unless index && index.data
|
15
|
+
#
|
16
|
+
# parse external id parts
|
17
|
+
order_type, transport, io, location, order_num, lin = index.data[:external_unique_id].to_s.split('-')
|
18
|
+
#
|
19
|
+
# correct for diff in type between order and weight processor
|
20
|
+
order_type = 'Inventory' if order_type == 'BulkInventory'
|
21
|
+
#
|
22
|
+
weight_params = {
|
23
|
+
io: index.data[:i_o],
|
24
|
+
order_id: index.data[:order_id],
|
25
|
+
order_type: order_type,
|
26
|
+
gross_weight: options[:gross].to_i,
|
27
|
+
tare_weight: options[:tare].to_i,
|
28
|
+
weighed_at: Time.now.round,
|
29
|
+
certificate_number: options[:certificate].to_s
|
30
|
+
}
|
31
|
+
|
32
|
+
options_renderer(WeighflowCli.create_weight(params: weight_params), options)
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
desc 'template [INDEX_ID]', 'create weight template'
|
37
|
+
def template(index_id)
|
38
|
+
aise 'index_id required' unless index_id
|
39
|
+
index = WeighflowCli.find_order(index_id)
|
40
|
+
raise 'index not found for id' unless index && index.data
|
41
|
+
#
|
42
|
+
# parse external id parts
|
43
|
+
order_type, transport, io, location, order_num, lin = index.data[:external_unique_id].to_s.split('-')
|
44
|
+
#
|
45
|
+
# correct for diff in type between order and weight processor
|
46
|
+
order_type = 'Inventory' if order_type == 'BulkInventory'
|
47
|
+
#
|
48
|
+
weight_params = {
|
49
|
+
io: index.data[:i_o],
|
50
|
+
order_id: index.data[:order_id],
|
51
|
+
order_type: order_type,
|
52
|
+
gross_weight: 0,
|
53
|
+
tare_weight: 0,
|
54
|
+
weighed_at: Time.now.round,
|
55
|
+
certificate_number: "{cert number}"
|
56
|
+
}
|
57
|
+
options_renderer(weight_params, options)
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
desc 'list', 'List weights within the last 24 hours'
|
62
|
+
def list
|
63
|
+
options_renderer(WeighflowCli.weights, options)
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
desc 'create', 'Create a weight given an order'
|
69
|
+
long_desc <<~DESC
|
70
|
+
|
71
|
+
weighflow_cli --file weight.json
|
72
|
+
|
73
|
+
This file should contain a minimum of :
|
74
|
+
|
75
|
+
{
|
76
|
+
order_type: "Commodity",
|
77
|
+
io: "O",
|
78
|
+
order_id: "{integer}",
|
79
|
+
gross_weight: "75000",
|
80
|
+
tare_weight: "25444",
|
81
|
+
weighed_at: "2021-02-26 10:15:41 am",
|
82
|
+
release_number: "",
|
83
|
+
truck_license_number: "",
|
84
|
+
trailer1_license_number: "",
|
85
|
+
trailer2_license_number: "",
|
86
|
+
truck_number: "",
|
87
|
+
driver_name: "",
|
88
|
+
driver_number: ""
|
89
|
+
}
|
90
|
+
|
91
|
+
--
|
92
|
+
DESC
|
93
|
+
option :file, aliases: '-f', required: true, banner: '[File name] json format'
|
94
|
+
def create
|
95
|
+
weight_params = JSON.parse(File.read(options[:file]), symbolize_names: true)
|
96
|
+
puts weight_params
|
97
|
+
|
98
|
+
options_renderer(WeighflowCli.create_weight(params: weight_params), options)
|
99
|
+
#options_renderer(options, options)
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
desc 'void', 'Voided a weight within 24 hours'
|
104
|
+
option :weight_id, required: true
|
105
|
+
option :reason, required: true
|
106
|
+
def void
|
107
|
+
options_renderer(WeighflowCli.void_weight(options[:weight_id], options[:reason]), options)
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
data/lib/weighflow_cli/client.rb
CHANGED
@@ -64,7 +64,7 @@ module WeighflowCli
|
|
64
64
|
#
|
65
65
|
# Data index file name
|
66
66
|
def index_file_name
|
67
|
-
@index_file_name ||= File.join(
|
67
|
+
@index_file_name ||= File.join(WeighflowCli.data_path, 'orders_index_cache')
|
68
68
|
end
|
69
69
|
|
70
70
|
|
@@ -85,7 +85,7 @@ module WeighflowCli
|
|
85
85
|
#
|
86
86
|
# Build the file name from the checksum
|
87
87
|
def build_detail_file_name(order)
|
88
|
-
File.join(
|
88
|
+
File.join(WeighflowCli.data_path, 'order_' + create_checksum(order) + '.json')
|
89
89
|
end
|
90
90
|
|
91
91
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weighflow_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruce Martin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02
|
11
|
+
date: 2021-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- exe/weighflow_cli
|
61
61
|
- lib/weighflow_cli.rb
|
62
62
|
- lib/weighflow_cli/cli.rb
|
63
|
+
- lib/weighflow_cli/cli_weights.rb
|
63
64
|
- lib/weighflow_cli/client.rb
|
64
65
|
- lib/weighflow_cli/credentials.rb
|
65
66
|
- lib/weighflow_cli/order_handler.rb
|