weighflow_cli 0.2.1
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 +7 -0
- data/.byebug_history +113 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +51 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/exe/weighflow_cli +5 -0
- data/lib/weighflow_cli.rb +62 -0
- data/lib/weighflow_cli/cli.rb +59 -0
- data/lib/weighflow_cli/client.rb +56 -0
- data/lib/weighflow_cli/credentials.rb +108 -0
- data/lib/weighflow_cli/order_handler.rb +230 -0
- data/lib/weighflow_cli/rendering.rb +11 -0
- data/lib/weighflow_cli/version.rb +9 -0
- data/weighflow_cli.gemspec +38 -0
- metadata +94 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 9c6e577b00577a732143e02785269778ca5d4daf69f710d179df64d6d0adbce8
|
|
4
|
+
data.tar.gz: 9629481b85e26f5462b88e150cf2b1a569afba738a53b84345de0b4a0843d121
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: f0682db15a9dd3d5801faef462e465d259a7032bb36018311eb7a52e4e78688fdcb7b833109b3279d6d232b1043f3ac410cf9f6292eed6f0d6d50bb4df6745a4
|
|
7
|
+
data.tar.gz: 4f06114d0f3550922b25e62889ecef240b9be6b86b7fb8e262f0a0ead13ee7712730356656348329b936dd6817262e06b0ceb7b60a73d8c02085470f131d4ec4
|
data/.byebug_history
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
c
|
|
2
|
+
response.code
|
|
3
|
+
response.success?
|
|
4
|
+
c
|
|
5
|
+
configuration.to_h
|
|
6
|
+
configuration.attributes
|
|
7
|
+
configuration
|
|
8
|
+
configuration.to_json
|
|
9
|
+
ap configuration.to_json
|
|
10
|
+
ap configuration
|
|
11
|
+
c
|
|
12
|
+
c.secret ='asdf'
|
|
13
|
+
c.secret ='asdf''
|
|
14
|
+
c.lkajsdf ='adf'
|
|
15
|
+
ap c
|
|
16
|
+
c
|
|
17
|
+
c[:url] = 'adsf'
|
|
18
|
+
c[:secret]='adfasdf'
|
|
19
|
+
ap c
|
|
20
|
+
c
|
|
21
|
+
q
|
|
22
|
+
c
|
|
23
|
+
index.checksum == order_checksum
|
|
24
|
+
index.checksum
|
|
25
|
+
ap index
|
|
26
|
+
n
|
|
27
|
+
create_checksum(order)
|
|
28
|
+
order_checksum
|
|
29
|
+
c
|
|
30
|
+
q
|
|
31
|
+
index
|
|
32
|
+
q
|
|
33
|
+
c
|
|
34
|
+
ap order.size
|
|
35
|
+
order[:external_unique_id].to_s
|
|
36
|
+
index
|
|
37
|
+
order_checksum
|
|
38
|
+
c
|
|
39
|
+
ap updates
|
|
40
|
+
ap adds
|
|
41
|
+
ap add
|
|
42
|
+
ap deletes
|
|
43
|
+
ap delets
|
|
44
|
+
c
|
|
45
|
+
ap deletes
|
|
46
|
+
ap updates
|
|
47
|
+
ap adds
|
|
48
|
+
c
|
|
49
|
+
ap index.data
|
|
50
|
+
index.data
|
|
51
|
+
c
|
|
52
|
+
ap index
|
|
53
|
+
index.data
|
|
54
|
+
ap index
|
|
55
|
+
c
|
|
56
|
+
1000.times.map { index_exists?('CommodityOrder-T-I-002-3340452-01') }
|
|
57
|
+
1000.times { index_exists?('CommodityOrder-T-I-002-3340452-01') }
|
|
58
|
+
index_exists?('CommodityOrder-T-I-002-3340452-01')
|
|
59
|
+
c
|
|
60
|
+
index_exists?('CommodityOrder-T-I-002-3340452-01')
|
|
61
|
+
c
|
|
62
|
+
index_exists?('CommodityOrder-T-I-002-3340452-01')
|
|
63
|
+
c
|
|
64
|
+
index_exists?('CommodityOrder-T-I-002-3340452-01')
|
|
65
|
+
c
|
|
66
|
+
index_exists?('adfs')
|
|
67
|
+
c
|
|
68
|
+
AwesomePrint.awesome_print "adf"
|
|
69
|
+
AwesomePrint.methods.grep /prin/
|
|
70
|
+
AwesomePrint.methods
|
|
71
|
+
c
|
|
72
|
+
File.expand_path('../',__FILE__)
|
|
73
|
+
File.expand_path(__FILE__, "../")
|
|
74
|
+
File.expand_path(__FILE__)
|
|
75
|
+
File.expand_pth(__FILE__)
|
|
76
|
+
__FILE__
|
|
77
|
+
__file__
|
|
78
|
+
c
|
|
79
|
+
options[:yaml]
|
|
80
|
+
options[:yaml[
|
|
81
|
+
options
|
|
82
|
+
ap options
|
|
83
|
+
c
|
|
84
|
+
ap client.orders.to_h
|
|
85
|
+
c
|
|
86
|
+
ap client.orders
|
|
87
|
+
ap client.test
|
|
88
|
+
c
|
|
89
|
+
ap client.test
|
|
90
|
+
ap "test"
|
|
91
|
+
ap "test'
|
|
92
|
+
ap.class
|
|
93
|
+
require "awesome_print"
|
|
94
|
+
ap.class
|
|
95
|
+
ap client.test
|
|
96
|
+
client.test
|
|
97
|
+
ap
|
|
98
|
+
ap { a: '3434'}
|
|
99
|
+
ap
|
|
100
|
+
c
|
|
101
|
+
x.message
|
|
102
|
+
x
|
|
103
|
+
ap x
|
|
104
|
+
x=JSON.parse(response.body, object_class: OpenStruct)
|
|
105
|
+
JSON.parse(response.body, object_class: OpenStruct)
|
|
106
|
+
JSON.parse(response.body)
|
|
107
|
+
ap response.body
|
|
108
|
+
ap response.bodu
|
|
109
|
+
ap response.boyd
|
|
110
|
+
ap response
|
|
111
|
+
c
|
|
112
|
+
ap response.parsed_response
|
|
113
|
+
ap response
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.7.2
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
weighflow_cli (0.2.0)
|
|
5
|
+
httparty
|
|
6
|
+
thor (~> 1.1.0)
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
awesome_print (1.8.0)
|
|
12
|
+
byebug (11.1.3)
|
|
13
|
+
diff-lcs (1.4.4)
|
|
14
|
+
gem-release (2.2.1)
|
|
15
|
+
httparty (0.18.1)
|
|
16
|
+
mime-types (~> 3.0)
|
|
17
|
+
multi_xml (>= 0.5.2)
|
|
18
|
+
mime-types (3.3.1)
|
|
19
|
+
mime-types-data (~> 3.2015)
|
|
20
|
+
mime-types-data (3.2020.1104)
|
|
21
|
+
multi_xml (0.6.0)
|
|
22
|
+
rake (13.0.3)
|
|
23
|
+
rspec (3.10.0)
|
|
24
|
+
rspec-core (~> 3.10.0)
|
|
25
|
+
rspec-expectations (~> 3.10.0)
|
|
26
|
+
rspec-mocks (~> 3.10.0)
|
|
27
|
+
rspec-core (3.10.1)
|
|
28
|
+
rspec-support (~> 3.10.0)
|
|
29
|
+
rspec-expectations (3.10.1)
|
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
31
|
+
rspec-support (~> 3.10.0)
|
|
32
|
+
rspec-mocks (3.10.2)
|
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
34
|
+
rspec-support (~> 3.10.0)
|
|
35
|
+
rspec-support (3.10.2)
|
|
36
|
+
thor (1.1.0)
|
|
37
|
+
|
|
38
|
+
PLATFORMS
|
|
39
|
+
ruby
|
|
40
|
+
x86_64-darwin-20
|
|
41
|
+
|
|
42
|
+
DEPENDENCIES
|
|
43
|
+
awesome_print
|
|
44
|
+
byebug
|
|
45
|
+
gem-release
|
|
46
|
+
rake (~> 13.0)
|
|
47
|
+
rspec (~> 3.0)
|
|
48
|
+
weighflow_cli!
|
|
49
|
+
|
|
50
|
+
BUNDLED WITH
|
|
51
|
+
2.2.3
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Bruce Martin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# WeighflowCli
|
|
2
|
+
|
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/weighflow_cli`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
4
|
+
|
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'weighflow_cli'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle install
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install weighflow_cli
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
TODO: Write usage instructions here
|
|
26
|
+
|
|
27
|
+
## Development
|
|
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.
|
|
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).
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/weighflow_cli.
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "bundler/setup"
|
|
5
|
+
require "weighflow_cli"
|
|
6
|
+
|
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
+
|
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
11
|
+
# require "pry"
|
|
12
|
+
# Pry.start
|
|
13
|
+
|
|
14
|
+
require "irb"
|
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/weighflow_cli
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'thor'
|
|
4
|
+
require 'httparty'
|
|
5
|
+
require 'awesome_print'
|
|
6
|
+
require 'byebug'
|
|
7
|
+
|
|
8
|
+
require_relative "weighflow_cli/version"
|
|
9
|
+
require_relative 'weighflow_cli/rendering'
|
|
10
|
+
require_relative 'weighflow_cli/client'
|
|
11
|
+
require_relative 'weighflow_cli/cli'
|
|
12
|
+
require_relative 'weighflow_cli/credentials'
|
|
13
|
+
require_relative 'weighflow_cli/order_handler'
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
module WeighflowCli
|
|
17
|
+
|
|
18
|
+
class Error < StandardError; end
|
|
19
|
+
#
|
|
20
|
+
_ROOT_PATH = File.expand_path('../../',__FILE__).freeze
|
|
21
|
+
#
|
|
22
|
+
# Provide an orderride to relocate data directory
|
|
23
|
+
DATA_PATH = ENV['WEIGHFLOW_CLI_PATH'] || File.join(_ROOT_PATH, '.data')
|
|
24
|
+
#
|
|
25
|
+
#
|
|
26
|
+
# ensure data path
|
|
27
|
+
Dir.mkdir(DATA_PATH) unless Dir.exists?(DATA_PATH)
|
|
28
|
+
#
|
|
29
|
+
|
|
30
|
+
Configuration = Struct.new(:secret, :url)
|
|
31
|
+
|
|
32
|
+
def self.configuration
|
|
33
|
+
if block_given?
|
|
34
|
+
configuration = Configuration.new
|
|
35
|
+
yield(configuration)
|
|
36
|
+
@config = configuration.to_h
|
|
37
|
+
end
|
|
38
|
+
@config ||= Credentials.load_config!
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def self.client
|
|
43
|
+
@client ||= Client.new(configuration)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def self.pull
|
|
48
|
+
WeighflowCli::OrderHandler.pull
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def self.find_order(external_id)
|
|
53
|
+
WeighflowCli::OrderHandler.find_order(external_id)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def self.list
|
|
58
|
+
WeighflowCli::OrderHandler.list
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
module WeighflowCli
|
|
2
|
+
class Cli < Thor
|
|
3
|
+
include Rendering
|
|
4
|
+
package_name "WeighflowCli"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def self.exit_on_failure?
|
|
8
|
+
false
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
desc "status", "Get system status"
|
|
12
|
+
method_options yaml: :boolean
|
|
13
|
+
def status
|
|
14
|
+
WeighflowCli.options_renderer(WeighflowCli.client.status, options)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
desc "login", "Save Login Credientials"
|
|
21
|
+
def login
|
|
22
|
+
Credentials.login
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
desc "pull", "Pull Orders from Weighflow"
|
|
30
|
+
method_options yaml: :boolean
|
|
31
|
+
def pull
|
|
32
|
+
options_renderer(WeighflowCli.pull, options)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
desc 'list', "List currently pulled orders"
|
|
39
|
+
method_options yaml: :boolean
|
|
40
|
+
def list
|
|
41
|
+
options_renderer(WeighflowCli.list, options)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
desc 'find_order', 'Find order details'
|
|
49
|
+
method_options yaml: :boolean
|
|
50
|
+
def find_order(external_id)
|
|
51
|
+
if index = WeighflowCli.find_order(external_id)
|
|
52
|
+
options_renderer(index.data, options)
|
|
53
|
+
else
|
|
54
|
+
options_renderer(nil, options)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
module WeighflowCli
|
|
2
|
+
|
|
3
|
+
class Client
|
|
4
|
+
include HTTParty
|
|
5
|
+
debug_output $stdout if ENV['DEBUG']
|
|
6
|
+
|
|
7
|
+
def initialize(config = {})
|
|
8
|
+
self.class.headers auth_headers(config[:secret].to_s)
|
|
9
|
+
self.class.base_uri config[:url].to_s
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def auth_headers(token)
|
|
13
|
+
{ 'Authorization' => "Token #{token}"}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def status
|
|
18
|
+
response = self.class.get('/')
|
|
19
|
+
render_error(response) unless response.success?
|
|
20
|
+
JSON.parse(response.body, symbolize_names: true)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def commodity_outbound_truck
|
|
25
|
+
find_orders(selection: 'OC')
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def commodity_inbound_truck
|
|
29
|
+
find_orders(selection: 'IC')
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def bulk_inventory_inbound_truck
|
|
33
|
+
find_orders(selection: 'II')
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def bulk_inventory_outbound_truck
|
|
38
|
+
find_orders(selection: 'OI')
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
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)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def render_error(response)
|
|
51
|
+
raise Error, "Problem accessing Weighflow API #{response.code} : #{response.body}"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
require 'readline'
|
|
2
|
+
|
|
3
|
+
module WeighflowCli
|
|
4
|
+
module Credentials
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def self.key_store_config
|
|
8
|
+
File.join(DATA_PATH, '.config.yaml')
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def self.login
|
|
13
|
+
welcome
|
|
14
|
+
url = get_url
|
|
15
|
+
secret = get_secret
|
|
16
|
+
File.write(key_store_config, YAML.dump(secret: secret, url: url))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
#
|
|
21
|
+
#
|
|
22
|
+
def self.welcome
|
|
23
|
+
puts <<~TEXT
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
Welcome to Weighflow Cli
|
|
30
|
+
------------------------
|
|
31
|
+
|
|
32
|
+
Please registry an API Token, and login here.
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
TEXT
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.get_secret
|
|
39
|
+
while secret = Readline.readline("Enter Secret: ", true) do
|
|
40
|
+
if secret.to_s.size > 20
|
|
41
|
+
return secret
|
|
42
|
+
puts <<~TEXT
|
|
43
|
+
|
|
44
|
+
Saved Login Successfully!
|
|
45
|
+
|
|
46
|
+
You are now ready to begin using the CLI!
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
TEXT
|
|
50
|
+
break
|
|
51
|
+
else
|
|
52
|
+
puts "-- invalid credentials --"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
nil
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def self.get_url
|
|
61
|
+
puts <<~TEXT
|
|
62
|
+
|
|
63
|
+
Please enter the URL for Weighflow API
|
|
64
|
+
|
|
65
|
+
TEXT
|
|
66
|
+
while url = Readline.readline("URL: ", true) do
|
|
67
|
+
if url.to_s.size > 10
|
|
68
|
+
return url
|
|
69
|
+
puts <<-TEXT
|
|
70
|
+
|
|
71
|
+
Saved Login Successfully!
|
|
72
|
+
|
|
73
|
+
You are now ready to begin using the CLI!
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
TEXT
|
|
77
|
+
break
|
|
78
|
+
else
|
|
79
|
+
puts "-- invalid credentials --"
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
nil
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def self.load_config!
|
|
89
|
+
secret_fail unless File.exists?(key_store_config)
|
|
90
|
+
config = YAML.load(File.read(key_store_config))
|
|
91
|
+
config
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def self.secret_fail
|
|
95
|
+
puts <<-TEXT
|
|
96
|
+
|
|
97
|
+
Secret is not present, please login first
|
|
98
|
+
|
|
99
|
+
Example:
|
|
100
|
+
|
|
101
|
+
$ weighflow_cli login
|
|
102
|
+
|
|
103
|
+
TEXT
|
|
104
|
+
exit
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
end
|
|
108
|
+
end
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
require 'digest'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
module WeighflowCli
|
|
5
|
+
|
|
6
|
+
module OrderHandler
|
|
7
|
+
|
|
8
|
+
#
|
|
9
|
+
# Pull order data from Weighflow and store in local repository
|
|
10
|
+
def self.pull
|
|
11
|
+
commodity_outbounds = WeighflowCli.client.commodity_outbound_truck
|
|
12
|
+
commodity_inbounds = WeighflowCli.client.commodity_inbound_truck
|
|
13
|
+
#
|
|
14
|
+
inventory_outbounds = WeighflowCli.client.bulk_inventory_outbound_truck
|
|
15
|
+
inventory_inbounds = WeighflowCli.client.bulk_inventory_inbound_truck
|
|
16
|
+
#
|
|
17
|
+
# combine
|
|
18
|
+
orders = commodity_outbounds[:orders] + commodity_inbounds[:orders] + inventory_outbounds[:orders] + inventory_inbounds[:orders]
|
|
19
|
+
#
|
|
20
|
+
diff = OrderRepository.new(orders)
|
|
21
|
+
diff.perform
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
#
|
|
28
|
+
#
|
|
29
|
+
# Find a single order with details from the stored repository
|
|
30
|
+
def self.find_order(external_id)
|
|
31
|
+
finder = Finder.new
|
|
32
|
+
finder.find_order(external_id)
|
|
33
|
+
end
|
|
34
|
+
#
|
|
35
|
+
#
|
|
36
|
+
#
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
#
|
|
40
|
+
# List all orders currently in stored repository
|
|
41
|
+
def self.list
|
|
42
|
+
result = []
|
|
43
|
+
finder = Finder.new
|
|
44
|
+
finder.for_each_index do |index|
|
|
45
|
+
result << index.data
|
|
46
|
+
end
|
|
47
|
+
result
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
#
|
|
53
|
+
#
|
|
54
|
+
#
|
|
55
|
+
# Helpers
|
|
56
|
+
#
|
|
57
|
+
module Handlers
|
|
58
|
+
|
|
59
|
+
#
|
|
60
|
+
# Data index file name
|
|
61
|
+
def index_file_name
|
|
62
|
+
@index_file_name ||= File.join(DATA_PATH, 'orders_index_cache')
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
#
|
|
67
|
+
# MD5 hash of order detail
|
|
68
|
+
def create_checksum(order)
|
|
69
|
+
Digest::MD5.hexdigest(order.to_json)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
#
|
|
73
|
+
# Create the index simple line entry, for speed and
|
|
74
|
+
# change checking by recording an MD5 hash of the contents
|
|
75
|
+
def index_line(order, file_name)
|
|
76
|
+
order[:external_unique_id] + "|#{create_checksum(order)}|#{file_name}"
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
#
|
|
81
|
+
# Build the file name from the checksum
|
|
82
|
+
def build_detail_file_name(order)
|
|
83
|
+
File.join(DATA_PATH, 'order_' + create_checksum(order) + '.json')
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
#
|
|
88
|
+
# Store all orders in data path
|
|
89
|
+
# - Saves the entire contents in separate file
|
|
90
|
+
# - Records the index of the filename with a checksum for detail reference
|
|
91
|
+
def store_in_cache(orders)
|
|
92
|
+
File.open(index_file_name, 'w') do |index_file|
|
|
93
|
+
# process each order
|
|
94
|
+
orders.each do |order|
|
|
95
|
+
detail_file_name = build_detail_file_name(order)
|
|
96
|
+
File.write(detail_file_name, JSON.pretty_generate(order))
|
|
97
|
+
index_file.puts(index_line(order, detail_file_name))
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
#
|
|
103
|
+
# Loop through all indexes. This is memory effecient. Does not load all into memory
|
|
104
|
+
def for_each_index(&block)
|
|
105
|
+
return unless File.exists?(index_file_name)
|
|
106
|
+
File.foreach(index_file_name) do |li|
|
|
107
|
+
compare_index, checksum, stored_json_file_name = li.chomp!.split('|')
|
|
108
|
+
block.call OrderIndexResult.new(index: compare_index, checksum: checksum, file_name: stored_json_file_name)
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
#
|
|
113
|
+
# Find a matching index
|
|
114
|
+
def find_index(index)
|
|
115
|
+
for_each_index do |compare_index|
|
|
116
|
+
return compare_index if compare_index.index == index
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
#
|
|
121
|
+
# Pluck the external unique id from the orders
|
|
122
|
+
def external_ids(orders)
|
|
123
|
+
orders.map { |order| order[:external_unique_id].to_s }
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
#
|
|
128
|
+
# return orders that have been cached, but are no longer needed
|
|
129
|
+
def find_deletes(orders)
|
|
130
|
+
unique_ids = external_ids(orders)
|
|
131
|
+
deletes = []
|
|
132
|
+
for_each_index do |index_result|
|
|
133
|
+
unless unique_ids.include?(index_result.index)
|
|
134
|
+
deletes << index_result.data
|
|
135
|
+
index_result.delete!
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
deletes
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
#
|
|
143
|
+
#
|
|
144
|
+
#
|
|
145
|
+
#
|
|
146
|
+
class OrderIndexResult
|
|
147
|
+
attr_reader :index, :checksum, :file_name
|
|
148
|
+
|
|
149
|
+
def initialize(index:, checksum:, file_name:)
|
|
150
|
+
@index = index
|
|
151
|
+
@checksum = checksum
|
|
152
|
+
@file_name = file_name
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def data
|
|
157
|
+
return @data if defined?(@data)
|
|
158
|
+
return nil unless @file_name
|
|
159
|
+
@data = JSON.parse(File.read(@file_name), symbolize_names: true)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def delete!
|
|
163
|
+
File.delete(@file_name) if File.exists?(@file_name)
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
class Finder
|
|
170
|
+
include Handlers
|
|
171
|
+
|
|
172
|
+
def find_order(external_id)
|
|
173
|
+
find_index(external_id)
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
class OrderRepository
|
|
180
|
+
include Handlers
|
|
181
|
+
|
|
182
|
+
attr_reader :orders
|
|
183
|
+
|
|
184
|
+
def initialize(orders = [])
|
|
185
|
+
@orders = orders
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def perform
|
|
189
|
+
adds = []
|
|
190
|
+
updates = []
|
|
191
|
+
unchanged = 0
|
|
192
|
+
deletes = []
|
|
193
|
+
|
|
194
|
+
# create file if not existing
|
|
195
|
+
File.open(index_file_name, "w") {} unless File.exists?(index_file_name)
|
|
196
|
+
|
|
197
|
+
#
|
|
198
|
+
orders.each do |order|
|
|
199
|
+
order_checksum = create_checksum(order)
|
|
200
|
+
index_result = find_index(order[:external_unique_id].to_s)
|
|
201
|
+
|
|
202
|
+
if index_result
|
|
203
|
+
if index_result.checksum != order_checksum
|
|
204
|
+
index_result.delete! # remove old, schedule update
|
|
205
|
+
updates << order # setup update to be added to cache
|
|
206
|
+
else
|
|
207
|
+
unchanged += 1
|
|
208
|
+
end
|
|
209
|
+
else
|
|
210
|
+
adds << order
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
# Remove and orders that will be deleted on store_in_cache
|
|
215
|
+
deletes = find_deletes(orders)
|
|
216
|
+
#
|
|
217
|
+
# Store all orders in data path with indexed file
|
|
218
|
+
store_in_cache(orders)
|
|
219
|
+
#
|
|
220
|
+
#
|
|
221
|
+
#
|
|
222
|
+
{ statistics: { adds: adds.size, updates: updates.size, deletes: deletes.size, unchanged: unchanged },
|
|
223
|
+
adds: external_ids(adds),
|
|
224
|
+
updates: external_ids(updates),
|
|
225
|
+
deletes: external_ids(deletes)
|
|
226
|
+
}
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/weighflow_cli/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "weighflow_cli"
|
|
7
|
+
spec.version = WeighflowCli::VERSION
|
|
8
|
+
spec.authors = ["Bruce Martin"]
|
|
9
|
+
spec.email = ["bmartin@heiskell.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "Weighflow CLI"
|
|
12
|
+
spec.description = "Weighflow Interface"
|
|
13
|
+
spec.homepage = "https://bitbucket.org/jdhco/weighflow_cli/src/master/"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
|
16
|
+
|
|
17
|
+
#spec.metadata["allowed_push_host"] = "testing"
|
|
18
|
+
|
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
20
|
+
spec.metadata["source_code_uri"] = "https://bitbucket.org/jdhco/weighflow_cli/src/master/"
|
|
21
|
+
# spec.metadata["changelog_uri"] = "http://localhost"
|
|
22
|
+
|
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
|
27
|
+
end
|
|
28
|
+
spec.bindir = "exe"
|
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
30
|
+
spec.require_paths = ["lib"]
|
|
31
|
+
|
|
32
|
+
# Uncomment to register a new dependency of your gem
|
|
33
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
|
34
|
+
spec.add_dependency "thor", "~>1.1.0"
|
|
35
|
+
spec.add_dependency "httparty"
|
|
36
|
+
# For more information and examples about making a new gem, checkout our
|
|
37
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
|
38
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: weighflow_cli
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Bruce Martin
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2021-02-26 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: thor
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 1.1.0
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 1.1.0
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: httparty
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
description: Weighflow Interface
|
|
42
|
+
email:
|
|
43
|
+
- bmartin@heiskell.com
|
|
44
|
+
executables:
|
|
45
|
+
- weighflow_cli
|
|
46
|
+
extensions: []
|
|
47
|
+
extra_rdoc_files: []
|
|
48
|
+
files:
|
|
49
|
+
- ".byebug_history"
|
|
50
|
+
- ".gitignore"
|
|
51
|
+
- ".rspec"
|
|
52
|
+
- ".ruby-version"
|
|
53
|
+
- Gemfile
|
|
54
|
+
- Gemfile.lock
|
|
55
|
+
- LICENSE.txt
|
|
56
|
+
- README.md
|
|
57
|
+
- Rakefile
|
|
58
|
+
- bin/console
|
|
59
|
+
- bin/setup
|
|
60
|
+
- exe/weighflow_cli
|
|
61
|
+
- lib/weighflow_cli.rb
|
|
62
|
+
- lib/weighflow_cli/cli.rb
|
|
63
|
+
- lib/weighflow_cli/client.rb
|
|
64
|
+
- lib/weighflow_cli/credentials.rb
|
|
65
|
+
- lib/weighflow_cli/order_handler.rb
|
|
66
|
+
- lib/weighflow_cli/rendering.rb
|
|
67
|
+
- lib/weighflow_cli/version.rb
|
|
68
|
+
- weighflow_cli.gemspec
|
|
69
|
+
homepage: https://bitbucket.org/jdhco/weighflow_cli/src/master/
|
|
70
|
+
licenses:
|
|
71
|
+
- MIT
|
|
72
|
+
metadata:
|
|
73
|
+
homepage_uri: https://bitbucket.org/jdhco/weighflow_cli/src/master/
|
|
74
|
+
source_code_uri: https://bitbucket.org/jdhco/weighflow_cli/src/master/
|
|
75
|
+
post_install_message:
|
|
76
|
+
rdoc_options: []
|
|
77
|
+
require_paths:
|
|
78
|
+
- lib
|
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - ">="
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: 2.3.0
|
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0'
|
|
89
|
+
requirements: []
|
|
90
|
+
rubygems_version: 3.1.4
|
|
91
|
+
signing_key:
|
|
92
|
+
specification_version: 4
|
|
93
|
+
summary: Weighflow CLI
|
|
94
|
+
test_files: []
|