weighflow_cli 0.2.2 → 0.2.7

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: 2ecb1b35aff4662fffcab033608f0ea6827ad91214d4033a061cc2c908990338
4
- data.tar.gz: f6f91ca72cc5b2df043334b784410f313506668912018bb80da9472e9e506780
3
+ metadata.gz: 963cc22724b95f0392a78886af4db5615247fac9c6f2df3d3fe7012b9ff4f5a3
4
+ data.tar.gz: 6408e424292209cbaada4f62718a380d4e7052ccb9aadcdf3548e63ed0a7932f
5
5
  SHA512:
6
- metadata.gz: 77b6708b15972eddb504a8626a5ab779676a0215e4315f59574e804dd8a5e75bd921b80daaec5419775ff2a27bb29afbf25562103d41828727decfb8234790f2
7
- data.tar.gz: 31443865b8c51a3286350709f8029afb9041c30daae852d3ea4c1433a1cfe1d6fdf423e48735d4f586075c7a1a637b3d951f93ac6a043fa6c83663be5dedcc36
6
+ metadata.gz: 0db4c48496094db993dd0ea24bd9452e5e61ab2894f406fd2e935030ba5707665ff9a8b86a06425f720dc241b623d0115e80569e34a803703ab3f52b105bce16
7
+ data.tar.gz: 6ef4ce49145d58247a5230b3229ef45da023a8abebbd65424e6dfcc01e6e30afb5c6932770bda3971c760e08c6af5c7acadf0ece59a9ce6e97ce990f78affcda
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.6)
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/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
@@ -6,6 +6,7 @@ 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'
@@ -15,18 +16,27 @@ module WeighflowCli
15
16
 
16
17
  class Error < StandardError; end
17
18
  #
18
- _ROOT_PATH = File.expand_path('../../',__FILE__).freeze
19
+ _ROOT_PATH = File.expand_path('~/.weighflow_cli').freeze
19
20
  #
20
- # Provide an orderride to relocate data directory
21
- DATA_PATH = ENV['WEIGHFLOW_CLI_PATH'] || File.join(_ROOT_PATH, '.data')
21
+ Dir.mkdir(_ROOT_PATH) unless Dir.exists?(_ROOT_PATH)
22
22
  #
23
+ # Provide an override to relocate data directory
24
+ DATA_PATH = ENV['WEIGHFLOW_CLI_PATH'] || File.join(_ROOT_PATH, 'data')
23
25
  #
24
- # ensure data path
26
+ #
27
+ # Ensure data path
25
28
  Dir.mkdir(DATA_PATH) unless Dir.exists?(DATA_PATH)
26
29
  #
27
30
 
28
31
  Configuration = Struct.new(:secret, :url)
29
32
 
33
+ ##
34
+ # This can be used to set the +secret+ and +url+ for api credentials
35
+ # this setting can be done at the console, via
36
+ # weighflow_cli login
37
+ # or through in code if using the gem within your own code by supplying
38
+ # a block and passing in the credientials.
39
+ #
30
40
  def self.configuration
31
41
  if block_given?
32
42
  configuration = Configuration.new
@@ -37,24 +47,45 @@ module WeighflowCli
37
47
  end
38
48
 
39
49
 
50
+ ##
51
+ # Creates an instance of the API client lib for direct access to the api
40
52
  def self.client
41
53
  @client ||= Client.new(configuration)
42
54
  end
43
55
 
44
56
 
57
+ ##
58
+ # Pull down the orders and store in the local repository data path
59
+ # * This is used to management order changes
60
+ #
45
61
  def self.pull
46
62
  WeighflowCli::OrderHandler.pull
47
63
  end
48
64
 
49
65
 
66
+ ##
67
+ # Find a specific order based on the +external_id+ given withing the orders
68
+ # + Helps to pull order details when needed.
50
69
  def self.find_order(external_id)
51
70
  WeighflowCli::OrderHandler.find_order(external_id)
52
71
  end
53
72
 
54
73
 
55
- def self.list
56
- WeighflowCli::OrderHandler.list
74
+ def self.list(indexes_only: false)
75
+ WeighflowCli::OrderHandler.list(indexes_only: indexes_only)
76
+ end
77
+
78
+ def self.weights
79
+ client.weights
80
+ end
81
+
82
+
83
+ def self.create_weight(params: {})
84
+ client.create_weight(params: params)
57
85
  end
58
86
 
87
+ def self.void_weight(weight_id, reason)
88
+ client.void_weight(weight_id, reason)
89
+ end
59
90
 
60
91
  end
@@ -1,52 +1,59 @@
1
- module WeighflowCli
1
+ require_relative 'cli_weights'
2
+
3
+ module WeighflowCli
4
+
5
+
2
6
  class Cli < Thor
3
7
  include Rendering
8
+
9
+
10
+
4
11
  package_name "WeighflowCli"
12
+ class_option :yaml, type: :boolean
5
13
 
14
+ desc 'weights', 'weights commands'
15
+ subcommand 'weights', CliWeights
6
16
 
7
17
  def self.exit_on_failure?
8
18
  false
9
19
  end
10
20
 
11
- desc "status", "Get system status"
12
- method_options yaml: :boolean
21
+ desc "status", "Get system status"
13
22
  def status
14
- WeighflowCli.options_renderer(WeighflowCli.client.status, options)
23
+ options_renderer(WeighflowCli.client.status, options)
15
24
  end
16
25
 
17
26
 
27
+ desc 'data_path', "Current data path"
28
+ def data_path
29
+ puts DATA_PATH
30
+ end
18
31
 
19
32
 
20
- desc "login", "Save Login Credientials"
33
+ desc "login", "Save Login Credentials"
21
34
  def login
22
35
  Credentials.login
23
36
  end
37
+
24
38
 
25
-
26
-
27
-
28
-
29
- desc "pull", "Pull Orders from Weighflow"
30
- method_options yaml: :boolean
39
+ desc "pull", "Pull Orders from Weighflow"
31
40
  def pull
32
41
  options_renderer(WeighflowCli.pull, options)
33
42
  end
34
-
35
-
36
-
43
+
37
44
 
38
- desc 'list', "List currently pulled orders"
39
- method_options yaml: :boolean
45
+ desc 'list', "List currently pulled orders"
40
46
  def list
41
47
  options_renderer(WeighflowCli.list, options)
42
48
  end
43
49
 
50
+ desc 'indexes', "List currently pulled order indexes"
51
+ def indexes
52
+ options_renderer(WeighflowCli.list(indexes_only: true), options)
53
+ end
54
+
44
55
 
45
-
46
-
47
-
48
- desc 'find_order', 'Find order details'
49
- method_options yaml: :boolean
56
+ desc 'find_order', 'Find order details'
50
57
  def find_order(external_id)
51
58
  if index = WeighflowCli.find_order(external_id)
52
59
  options_renderer(index.data, options)
@@ -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
@@ -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.2"
6
+ VERSION = "0.2.7"
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.2
4
+ version: 0.2.7
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
@@ -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