weighflow_cli 0.2.3 → 0.2.8

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: 9b16083d957ff3cfad0f8b7a0adbdf38837e3f2ec19b47402c24d8f4fba7f064
4
- data.tar.gz: 95078a43257981ce4f2599a349d107620c1c0b35fa14fcabdb189b4c635a587e
3
+ metadata.gz: d2f3ed43fcfecb4a905c2e58e8e38920002f9267dc151917472bdaca2abad173
4
+ data.tar.gz: 0443ce04de39d02bb39dca8fa908d4dc854c014d359b2b9225e2865511bde5f8
5
5
  SHA512:
6
- metadata.gz: 99a11f91ee22093061ab6e8bec309d8aebb3e5450d322a8d3ae688d50ec2caec99d41168fd50d9befbf70a994430eff81303525ead01c03543e1de9230ebffcf
7
- data.tar.gz: a2e6813efc1754aba5b92d70de63ff2e3b785d1bed7bd63c94af8e086d5cd1ab0ec258e0b0d8e6e82c87ecddf30b5770922ed501be507c4edd89dab1169c9a71
6
+ metadata.gz: 0bf5120b6de638145c148e6ac3b695f1fde406246c04a006933a4b3a9d19a7ac1213a9e7cd12517ec9511f39f1043b02d8222fdcb1931663da3323af7958d1e9
7
+ data.tar.gz: 1bf4768ac5f4e8df1845bea9ecb88d9b9dfb82aa15dc35714bc268a0e4213363fea9a4061b9185e5758a76e4e4f85587d8d45a6e5dab26e7e353fff91e9d907d
data/.byebug_history CHANGED
@@ -1,4 +1,31 @@
1
1
  c
2
+ ap result.first.keys
3
+ ap keys
4
+ q
5
+ c
6
+ uri
7
+ uri.port = 80
8
+ uri.methods
9
+ ap uri
10
+ c
11
+ result.class
12
+ ap result
13
+ c
14
+ weight_params
15
+ c
16
+ weight_params
17
+ q
18
+ weight_params
19
+ c
20
+ weight_params
21
+ q
22
+ weight_params
23
+ ap weight_params
24
+ c
25
+ ap weight_params
26
+ require 'awesome_print'
27
+ ap weight_params
28
+ c
2
29
  commodity_inbounds[:orders]
3
30
  inventory_inbounds[:orders]
4
31
  inventory_outbounds[:orders]
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,25 +1,32 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- weighflow_cli (0.2.2)
4
+ weighflow_cli (0.2.7)
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.2020.1104)
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/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,35 @@ 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
- #
24
- # ensure data path
25
- Dir.mkdir(DATA_PATH) unless Dir.exists?(DATA_PATH)
23
+
24
+ # Provide an override to relocate data directory
25
+ def self.data_path
26
+ return @data_path if defined?(@data_path)
27
+ @data_path ||= ENV.fetch('WEIGHFLOW_CLI_PATH') { File.join(_ROOT_PATH, 'data') }
28
+ ensure_data_path
29
+ @data_path
30
+ end
31
+
32
+ ##
33
+ # Ensure data path
34
+ def self.ensure_data_path
35
+ Dir.mkdir(data_path) unless Dir.exists?(data_path)
36
+ end
26
37
  #
27
38
 
28
39
  Configuration = Struct.new(:secret, :url)
29
40
 
41
+ ##
42
+ # This can be used to set the +secret+ and +url+ for api credentials
43
+ # this setting can be done at the console, via
44
+ # weighflow_cli login
45
+ # or through in code if using the gem within your own code by supplying
46
+ # a block and passing in the credientials.
47
+ #
30
48
  def self.configuration
31
49
  if block_given?
32
50
  configuration = Configuration.new
@@ -37,24 +55,45 @@ module WeighflowCli
37
55
  end
38
56
 
39
57
 
58
+ ##
59
+ # Creates an instance of the API client lib for direct access to the api
40
60
  def self.client
41
61
  @client ||= Client.new(configuration)
42
62
  end
43
63
 
44
64
 
65
+ ##
66
+ # Pull down the orders and store in the local repository data path
67
+ # * This is used to management order changes
68
+ #
45
69
  def self.pull
46
70
  WeighflowCli::OrderHandler.pull
47
71
  end
48
72
 
49
73
 
74
+ ##
75
+ # Find a specific order based on the +external_id+ given withing the orders
76
+ # + Helps to pull order details when needed.
50
77
  def self.find_order(external_id)
51
78
  WeighflowCli::OrderHandler.find_order(external_id)
52
79
  end
53
80
 
54
81
 
55
- def self.list
56
- WeighflowCli::OrderHandler.list
82
+ def self.list(indexes_only: false)
83
+ WeighflowCli::OrderHandler.list(indexes_only: indexes_only)
84
+ end
85
+
86
+ def self.weights
87
+ client.weights
88
+ end
89
+
90
+
91
+ def self.create_weight(params: {})
92
+ client.create_weight(params: params)
57
93
  end
58
94
 
95
+ def self.void_weight(weight_id, reason)
96
+ client.void_weight(weight_id, reason)
97
+ end
59
98
 
60
99
  end
@@ -1,23 +1,31 @@
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
+
4
10
  package_name "WeighflowCli"
11
+ class_option :yaml, type: :boolean
5
12
 
13
+ desc 'weights', 'weights commands'
14
+ subcommand 'weights', CliWeights
6
15
 
7
16
  def self.exit_on_failure?
8
17
  false
9
18
  end
10
19
 
11
- desc "status", "Get system status"
12
- method_options yaml: :boolean
20
+ desc "status", "Get system status"
13
21
  def status
14
- WeighflowCli.options_renderer(WeighflowCli.client.status, options)
22
+ options_renderer(WeighflowCli.client.status, options)
15
23
  end
16
24
 
17
25
 
18
26
  desc 'data_path', "Current data path"
19
27
  def data_path
20
- puts DATA_PATH
28
+ puts WeighflowCli.data_path
21
29
  end
22
30
 
23
31
 
@@ -25,31 +33,26 @@ module WeighflowCli
25
33
  def login
26
34
  Credentials.login
27
35
  end
36
+
28
37
 
29
-
30
-
31
-
32
- desc "pull", "Pull Orders from Weighflow"
33
- method_options yaml: :boolean
38
+ desc "pull", "Pull Orders from Weighflow"
34
39
  def pull
35
40
  options_renderer(WeighflowCli.pull, options)
36
41
  end
37
-
38
-
39
-
42
+
40
43
 
41
- desc 'list', "List currently pulled orders"
42
- method_options yaml: :boolean
44
+ desc 'list', "List currently pulled orders"
43
45
  def list
44
46
  options_renderer(WeighflowCli.list, options)
45
47
  end
46
48
 
49
+ desc 'indexes', "List currently pulled order indexes"
50
+ def indexes
51
+ options_renderer(WeighflowCli.list(indexes_only: true), options)
52
+ end
53
+
47
54
 
48
-
49
-
50
-
51
- desc 'find_order', 'Find order details'
52
- method_options yaml: :boolean
55
+ desc 'find_order', 'Find order details'
53
56
  def find_order(external_id)
54
57
  if index = WeighflowCli.find_order(external_id)
55
58
  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', query: { s: selection })
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
@@ -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
- result << index.data
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
@@ -60,7 +64,7 @@ module WeighflowCli
60
64
  #
61
65
  # Data index file name
62
66
  def index_file_name
63
- @index_file_name ||= File.join(DATA_PATH, 'orders_index_cache')
67
+ @index_file_name ||= File.join(WeighflowCli.data_path, 'orders_index_cache')
64
68
  end
65
69
 
66
70
 
@@ -81,7 +85,7 @@ module WeighflowCli
81
85
  #
82
86
  # Build the file name from the checksum
83
87
  def build_detail_file_name(order)
84
- File.join(DATA_PATH, 'order_' + create_checksum(order) + '.json')
88
+ File.join(WeighflowCli.data_path, 'order_' + create_checksum(order) + '.json')
85
89
  end
86
90
 
87
91
 
@@ -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.3"
6
+ VERSION = "0.2.8"
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.3
4
+ version: 0.2.8
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-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