weighflow_cli 0.2.1 → 0.2.6

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
  SHA256:
3
- metadata.gz: 9c6e577b00577a732143e02785269778ca5d4daf69f710d179df64d6d0adbce8
4
- data.tar.gz: 9629481b85e26f5462b88e150cf2b1a569afba738a53b84345de0b4a0843d121
3
+ metadata.gz: c003dbce7d10d625735cafea74cdf9deee25abc1c98efc66439a437c7070d918
4
+ data.tar.gz: 21778039bbb29a51798a296f04e98c6bbc7d3d437633bc68370a738b6de9ae88
5
5
  SHA512:
6
- metadata.gz: f0682db15a9dd3d5801faef462e465d259a7032bb36018311eb7a52e4e78688fdcb7b833109b3279d6d232b1043f3ac410cf9f6292eed6f0d6d50bb4df6745a4
7
- data.tar.gz: 4f06114d0f3550922b25e62889ecef240b9be6b86b7fb8e262f0a0ead13ee7712730356656348329b936dd6817262e06b0ceb7b60a73d8c02085470f131d4ec4
6
+ metadata.gz: b65df818087d76d495e53c346617f32182444d254bd3794332205eb3e78bf1bbae8469ad486cfae31f74e8b59d2a7384b998b56728f6cae7c6bbdab98dea5257
7
+ data.tar.gz: 721899efee2b692248458c01e75ff21e3f859b46ed8a45e5704e35fcb24809ed100022bc15caf1b95a20aadaeede59d3db51e94343adb91f8b65edee8fb5d355
data/.byebug_history CHANGED
@@ -1,4 +1,23 @@
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
17
+ commodity_inbounds[:orders]
18
+ inventory_inbounds[:orders]
19
+ inventory_outbounds[:orders]
20
+ c
2
21
  response.code
3
22
  response.success?
4
23
  c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- weighflow_cli (0.2.0)
4
+ weighflow_cli (0.2.5)
5
5
  httparty
6
6
  thor (~> 1.1.0)
7
7
 
@@ -17,7 +17,7 @@ GEM
17
17
  multi_xml (>= 0.5.2)
18
18
  mime-types (3.3.1)
19
19
  mime-types-data (~> 3.2015)
20
- mime-types-data (3.2020.1104)
20
+ mime-types-data (3.2021.0225)
21
21
  multi_xml (0.6.0)
22
22
  rake (13.0.3)
23
23
  rspec (3.10.0)
data/README.md CHANGED
@@ -22,13 +22,15 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ From a console prompt simple type:
26
26
 
27
- ## Development
27
+ ```bash
28
28
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
29
+ $ weighflow_cli
30
30
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
31
+ ```
32
+
33
+ Follow menu instructions
32
34
 
33
35
  ## Contributing
34
36
 
data/lib/weighflow_cli.rb CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  require 'thor'
4
4
  require 'httparty'
5
- require 'awesome_print'
6
- require 'byebug'
7
5
 
8
6
  require_relative "weighflow_cli/version"
9
7
  require_relative 'weighflow_cli/rendering'
@@ -17,18 +15,27 @@ module WeighflowCli
17
15
 
18
16
  class Error < StandardError; end
19
17
  #
20
- _ROOT_PATH = File.expand_path('../../',__FILE__).freeze
18
+ _ROOT_PATH = File.expand_path('~/.weighflow_cli').freeze
21
19
  #
22
- # Provide an orderride to relocate data directory
23
- DATA_PATH = ENV['WEIGHFLOW_CLI_PATH'] || File.join(_ROOT_PATH, '.data')
20
+ Dir.mkdir(_ROOT_PATH) unless Dir.exists?(_ROOT_PATH)
24
21
  #
22
+ # Provide an override to relocate data directory
23
+ DATA_PATH = ENV['WEIGHFLOW_CLI_PATH'] || File.join(_ROOT_PATH, 'data')
25
24
  #
26
- # ensure data path
25
+ #
26
+ # Ensure data path
27
27
  Dir.mkdir(DATA_PATH) unless Dir.exists?(DATA_PATH)
28
28
  #
29
29
 
30
30
  Configuration = Struct.new(:secret, :url)
31
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
+ #
32
39
  def self.configuration
33
40
  if block_given?
34
41
  configuration = Configuration.new
@@ -39,24 +46,45 @@ module WeighflowCli
39
46
  end
40
47
 
41
48
 
49
+ ##
50
+ # Creates an instance of the API client lib for direct access to the api
42
51
  def self.client
43
52
  @client ||= Client.new(configuration)
44
53
  end
45
54
 
46
55
 
56
+ ##
57
+ # Pull down the orders and store in the local repository data path
58
+ # * This is used to management order changes
59
+ #
47
60
  def self.pull
48
61
  WeighflowCli::OrderHandler.pull
49
62
  end
50
63
 
51
64
 
65
+ ##
66
+ # Find a specific order based on the +external_id+ given withing the orders
67
+ # + Helps to pull order details when needed.
52
68
  def self.find_order(external_id)
53
69
  WeighflowCli::OrderHandler.find_order(external_id)
54
70
  end
55
71
 
56
72
 
57
- def self.list
58
- 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)
59
84
  end
60
85
 
86
+ def self.void_weight(weight_id, reason)
87
+ client.void_weight(weight_id, reason)
88
+ end
61
89
 
62
90
  end
@@ -1,23 +1,141 @@
1
- module WeighflowCli
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
- WeighflowCli.options_renderer(WeighflowCli.client.status, options)
128
+ options_renderer(WeighflowCli.client.status, options)
15
129
  end
16
130
 
17
131
 
132
+ desc 'data_path', "Current data path"
133
+ def data_path
134
+ puts DATA_PATH
135
+ end
18
136
 
19
137
 
20
- desc "login", "Save Login Credientials"
138
+ desc "login", "Save Login Credentials"
21
139
  def login
22
140
  Credentials.login
23
141
  end
@@ -25,9 +143,7 @@ module WeighflowCli
25
143
 
26
144
 
27
145
 
28
-
29
- desc "pull", "Pull Orders from Weighflow"
30
- method_options yaml: :boolean
146
+ desc "pull", "Pull Orders from Weighflow"
31
147
  def pull
32
148
  options_renderer(WeighflowCli.pull, options)
33
149
  end
@@ -35,18 +151,26 @@ module WeighflowCli
35
151
 
36
152
 
37
153
 
38
- desc 'list', "List currently pulled orders"
39
- method_options yaml: :boolean
154
+ desc 'list', "List currently pulled orders"
40
155
  def list
41
156
  options_renderer(WeighflowCli.list, options)
42
157
  end
43
158
 
159
+ desc 'indexes', "List currently pulled order indexes"
160
+ def indexes
161
+ options_renderer(WeighflowCli.list(indexes_only: true), options)
162
+ end
163
+
44
164
 
45
165
 
46
-
47
166
 
48
- desc 'find_order', 'Find order details'
49
- method_options yaml: :boolean
167
+
168
+
169
+
170
+
171
+
172
+
173
+ desc 'find_order', 'Find order details'
50
174
  def find_order(external_id)
51
175
  if index = WeighflowCli.find_order(external_id)
52
176
  options_renderer(index.data, options)
@@ -15,9 +15,23 @@ module WeighflowCli
15
15
 
16
16
 
17
17
  def status
18
- response = self.class.get('/')
19
- render_error(response) unless response.success?
20
- JSON.parse(response.body, symbolize_names: true)
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?s=OI')
46
- render_error(response) unless response.success?
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
@@ -15,6 +15,7 @@ module WeighflowCli
15
15
  inventory_inbounds = WeighflowCli.client.bulk_inventory_inbound_truck
16
16
  #
17
17
  # combine
18
+
18
19
  orders = commodity_outbounds[:orders] + commodity_inbounds[:orders] + inventory_outbounds[:orders] + inventory_inbounds[:orders]
19
20
  #
20
21
  diff = OrderRepository.new(orders)
@@ -38,11 +39,15 @@ module WeighflowCli
38
39
 
39
40
  #
40
41
  # List all orders currently in stored repository
41
- def self.list
42
+ def self.list(indexes_only: false)
42
43
  result = []
43
44
  finder = Finder.new
44
45
  finder.for_each_index do |index|
45
- result << index.data
46
+ if indexes_only
47
+ result << index.index
48
+ else
49
+ result << index.data
50
+ end
46
51
  end
47
52
  result
48
53
  end
@@ -155,7 +160,8 @@ module WeighflowCli
155
160
 
156
161
  def data
157
162
  return @data if defined?(@data)
158
- return nil unless @file_name
163
+ return {} unless @file_name
164
+ return {} unless File.exists?(@file_name)
159
165
  @data = JSON.parse(File.read(@file_name), symbolize_names: true)
160
166
  end
161
167
 
@@ -166,6 +172,8 @@ module WeighflowCli
166
172
  end
167
173
 
168
174
 
175
+ #
176
+ #
169
177
  class Finder
170
178
  include Handlers
171
179
 
@@ -4,7 +4,7 @@ module WeighflowCli
4
4
  if options[:yaml]
5
5
  puts result.to_yaml
6
6
  else
7
- puts result.to_json
7
+ puts JSON.pretty_generate(result)
8
8
  end
9
9
  end
10
10
  end
@@ -3,7 +3,7 @@
3
3
 
4
4
 
5
5
  module WeighflowCli
6
- VERSION = "0.2.1"
6
+ VERSION = "0.2.6"
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.1
4
+ version: 0.2.6
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-26 00:00:00.000000000 Z
11
+ date: 2021-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor