weighflow_cli 0.2.6 → 0.2.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c003dbce7d10d625735cafea74cdf9deee25abc1c98efc66439a437c7070d918
4
- data.tar.gz: 21778039bbb29a51798a296f04e98c6bbc7d3d437633bc68370a738b6de9ae88
3
+ metadata.gz: '0880ba4d3668b12210a21ab60ca40dc37cbefe0e2b18a5cca4465bdda5ca28ba'
4
+ data.tar.gz: d0bfc91c553fbe48c1f77d1de71ea6427c925ab3300ade47f2a16ba00a2b09ad
5
5
  SHA512:
6
- metadata.gz: b65df818087d76d495e53c346617f32182444d254bd3794332205eb3e78bf1bbae8469ad486cfae31f74e8b59d2a7384b998b56728f6cae7c6bbdab98dea5257
7
- data.tar.gz: 721899efee2b692248458c01e75ff21e3f859b46ed8a45e5704e35fcb24809ed100022bc15caf1b95a20aadaeede59d3db51e94343adb91f8b65edee8fb5d355
6
+ metadata.gz: 62f8a787fcd636f2c9dde240d282bec123d558ab7c72a24680a2e1c03a2a9e206779553c2676154b6f8034e4b6516855581fb6192d12dc8b056eb87001973306
7
+ data.tar.gz: 7a88511b284eadaf3387642a5ee4fb08ece3b8a870f98fb52a9ed357903ac123266670d596ecbdc5da6197a56e75a771b4ec0b1c22bcc0d38291d0b2dcd97791
data/.byebug_history CHANGED
@@ -1,4 +1,87 @@
1
1
  c
2
+ results.first.value
3
+ results.first.status
4
+ results.first.methods
5
+ ap results.first.methods
6
+ ap results.first.mehtods
7
+ ap results
8
+ c
9
+ ap orders.size
10
+ n
11
+ c
12
+ q
13
+ c
14
+ ap results[:commodity_outbounds][:orders]
15
+ ap results[:commodity_outbounds]
16
+ ap results.keys
17
+ ap results.flatten
18
+ ap results.keys
19
+ ap results
20
+ c
21
+ q
22
+ c
23
+ find_orders(selection: 'OI')
24
+ find_orders(selection: 'OC')
25
+ self
26
+ ap auth_headers
27
+ self
28
+ c
29
+ results
30
+ c
31
+ ap response.body
32
+ c
33
+ ap response.body
34
+ c
35
+ ap selection
36
+ c
37
+ ap selection
38
+ c
39
+ Array[inventory_outbounds[:orders]].compact
40
+ Array[inventory_outbounds[:orders]]
41
+ Array.new(inventory_outbounds[:orders])
42
+ ap inventory_outbounds[:orders]
43
+ c
44
+ e
45
+ n
46
+ c
47
+ Array.new(commodity_outbounds[:orders])
48
+ Array.new(ommodity_outbounds[:orders])
49
+ Array(ommodity_outbounds[:orders])
50
+ commodity_outbounds[:orders]
51
+ ap commodity_outbounds[:orders]
52
+ Array[commodity_outbounds[:orders]]
53
+ ap commodity_outbounds[:orders]
54
+ c
55
+ ap inventory_outbounds
56
+ require 'awesome_print'
57
+ ap inventory_outbounds
58
+ c
59
+ ap inventory_outbounds
60
+ ap commodity_inbounds
61
+ ap commodity_outbounds
62
+ require 'awesome_print'
63
+ ap commodity_outbounds
64
+ commodity_outbounds
65
+ q
66
+ C
67
+ WeighflowCli::ROOT_PATH
68
+ c
69
+ WeighflowCli::_ROOT_PATH
70
+ WeighflowCli
71
+ _ROOT_PATH
72
+ c
73
+ ap result.first.keys
74
+ ap keys
75
+ q
76
+ c
77
+ uri
78
+ uri.port = 80
79
+ uri.methods
80
+ ap uri
81
+ c
82
+ result.class
83
+ ap result
84
+ c
2
85
  weight_params
3
86
  c
4
87
  weight_params
data/.gitignore CHANGED
@@ -7,6 +7,8 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  /.data/*
10
+ /spec/data
11
+
10
12
  # rspec failure tracking
11
13
  .rspec_status
12
14
  .secret.key
data/Gemfile CHANGED
@@ -10,4 +10,6 @@ gem "rake", "~> 13.0"
10
10
  gem "rspec", "~> 3.0"
11
11
  gem 'awesome_print'
12
12
  gem 'byebug'
13
- gem 'gem-release'
13
+ gem 'gem-release'
14
+ gem 'vcr'
15
+ gem 'webmock'
data/Gemfile.lock CHANGED
@@ -1,17 +1,22 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- weighflow_cli (0.2.5)
4
+ weighflow_cli (0.2.10)
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)
@@ -19,7 +24,9 @@ GEM
19
24
  mime-types-data (~> 3.2015)
20
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
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "weighflow_cli"
4
-
4
+
5
+
5
6
  WeighflowCli::Cli.start(ARGV)
data/lib/weighflow_cli.rb CHANGED
@@ -3,6 +3,16 @@
3
3
  require 'thor'
4
4
  require 'httparty'
5
5
 
6
+
7
+ ##
8
+ # Development mode only
9
+ #
10
+ if ENV['RUBY_ENV'] == 'development'
11
+ require 'byebug'
12
+ require 'awesome_print'
13
+ end
14
+ #
15
+ #
6
16
  require_relative "weighflow_cli/version"
7
17
  require_relative 'weighflow_cli/rendering'
8
18
  require_relative 'weighflow_cli/client'
@@ -10,21 +20,30 @@ require_relative 'weighflow_cli/cli'
10
20
  require_relative 'weighflow_cli/credentials'
11
21
  require_relative 'weighflow_cli/order_handler'
12
22
 
23
+
13
24
 
14
25
  module WeighflowCli
15
26
 
16
27
  class Error < StandardError; end
17
28
  #
18
- _ROOT_PATH = File.expand_path('~/.weighflow_cli').freeze
29
+ ROOT_PATH = File.expand_path('~/.weighflow_cli').freeze
19
30
  #
20
- Dir.mkdir(_ROOT_PATH) unless Dir.exists?(_ROOT_PATH)
31
+ Dir.mkdir(ROOT_PATH) unless Dir.exists?(ROOT_PATH)
21
32
  #
33
+
22
34
  # Provide an override to relocate data directory
23
- DATA_PATH = ENV['WEIGHFLOW_CLI_PATH'] || File.join(_ROOT_PATH, 'data')
24
- #
25
- #
35
+ def self.data_path
36
+ return @data_path if defined?(@data_path)
37
+ @data_path ||= ENV.fetch('WEIGHFLOW_CLI_PATH') { File.join(WeighflowCli::ROOT_PATH, 'data') }
38
+ ensure_data_path
39
+ @data_path
40
+ end
41
+
42
+ ##
26
43
  # Ensure data path
27
- Dir.mkdir(DATA_PATH) unless Dir.exists?(DATA_PATH)
44
+ def self.ensure_data_path
45
+ Dir.mkdir(data_path) unless Dir.exists?(data_path)
46
+ end
28
47
  #
29
48
 
30
49
  Configuration = Struct.new(:secret, :url)
@@ -1,123 +1,17 @@
1
- require 'byebug'
1
+ require_relative 'cli_weights'
2
2
 
3
3
  module WeighflowCli
4
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
-
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', 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 DATA_PATH
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
@@ -21,7 +21,7 @@ module WeighflowCli
21
21
 
22
22
  def create_weight(params: {})
23
23
  response = self.class.post('/weights', body: params)
24
- render_json(response)
24
+ render_json(response)
25
25
  end
26
26
 
27
27
  def void_weight(weight_id, reason)
@@ -35,7 +35,7 @@ module WeighflowCli
35
35
  end
36
36
 
37
37
 
38
- def commodity_outbound_truck
38
+ def commodity_outbound_truck
39
39
  find_orders(selection: 'OC')
40
40
  end
41
41
 
@@ -56,7 +56,7 @@ module WeighflowCli
56
56
  private
57
57
 
58
58
  def find_orders(selection: 'OC')
59
- response = self.class.get('/orders', query: { s: selection })
59
+ response = self.class.get('/orders', query: { s: selection })
60
60
  render_json(response)
61
61
  end
62
62
 
@@ -5,7 +5,7 @@ module WeighflowCli
5
5
 
6
6
 
7
7
  def self.key_store_config
8
- File.join(DATA_PATH, '.config.yaml')
8
+ File.join(WeighflowCli.data_path, '.config.yaml')
9
9
  end
10
10
 
11
11
 
@@ -1,30 +1,41 @@
1
1
  require 'digest'
2
+
2
3
 
3
4
 
4
5
  module WeighflowCli
5
6
 
6
7
  module OrderHandler
7
-
8
8
  #
9
9
  # Pull order data from Weighflow and store in local repository
10
10
  def self.pull
11
- commodity_outbounds = WeighflowCli.client.commodity_outbound_truck
12
- commodity_inbounds = WeighflowCli.client.commodity_inbound_truck
11
+ ##
12
+ # api methods to collect orders
13
+ method_names = [:commodity_outbound_truck,
14
+ :commodity_inbound_truck,
15
+ :bulk_inventory_outbound_truck,
16
+ :bulk_inventory_inbound_truck]
13
17
  #
14
- inventory_outbounds = WeighflowCli.client.bulk_inventory_outbound_truck
15
- inventory_inbounds = WeighflowCli.client.bulk_inventory_inbound_truck
18
+ # collect orders using threads
19
+ results = threaded_api_query(method_names)
16
20
  #
17
- # combine
18
-
19
- orders = commodity_outbounds[:orders] + commodity_inbounds[:orders] + inventory_outbounds[:orders] + inventory_inbounds[:orders]
21
+ # flatten order array of hashes
22
+ orders = results.map { |orders| orders[:orders] }.flatten
20
23
  #
24
+ # Store in repository
21
25
  diff = OrderRepository.new(orders)
22
26
  diff.perform
23
-
24
27
  end
25
28
 
26
29
 
30
+ ##
31
+ # Process multiple api calls in threads
32
+ def self.threaded_api_query(method_names)
33
+ method_names.map do |name|
34
+ Thread.new { WeighflowCli.client.send(name) }
35
+ end.map(&:value)
36
+ end
27
37
 
38
+
28
39
  #
29
40
  #
30
41
  # Find a single order with details from the stored repository
@@ -64,7 +75,7 @@ module WeighflowCli
64
75
  #
65
76
  # Data index file name
66
77
  def index_file_name
67
- @index_file_name ||= File.join(DATA_PATH, 'orders_index_cache')
78
+ @index_file_name ||= File.join(WeighflowCli.data_path, 'orders_index_cache')
68
79
  end
69
80
 
70
81
 
@@ -85,7 +96,7 @@ module WeighflowCli
85
96
  #
86
97
  # Build the file name from the checksum
87
98
  def build_detail_file_name(order)
88
- File.join(DATA_PATH, 'order_' + create_checksum(order) + '.json')
99
+ File.join(WeighflowCli.data_path, 'order_' + create_checksum(order) + '.json')
89
100
  end
90
101
 
91
102
 
@@ -3,7 +3,7 @@
3
3
 
4
4
 
5
5
  module WeighflowCli
6
- VERSION = "0.2.6"
6
+ VERSION = "0.2.11"
7
7
 
8
8
 
9
9
  end
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.6
4
+ version: 0.2.11
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-27 00:00:00.000000000 Z
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