bill_hicks 2.1.4 → 5.0.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 +4 -4
- data/.circleci/config.yml +41 -0
- data/.ruby-version +1 -1
- data/README.md +0 -89
- data/bill_hicks.gemspec +2 -1
- data/lib/bill_hicks/base.rb +27 -4
- data/lib/bill_hicks/brand_converter.rb +1 -0
- data/lib/bill_hicks/catalog.rb +18 -27
- data/lib/bill_hicks/inventory.rb +54 -30
- data/lib/bill_hicks/version.rb +1 -1
- metadata +22 -8
- data/.travis.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e15bab97eb4956e706f0b598e4f42608d0bfe21f
|
4
|
+
data.tar.gz: f7e7007fb2ada66e49902df044e77e3292261fc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c786bf3afd90aeeb879ed1ea2a99908020b8f82a0079e796fad111c884f32f46b0e698baa10c4f5576f9e2c76104efc68d18ba0bf1d12e16bcdee1ae92ce2b6
|
7
|
+
data.tar.gz: 2bcb02cb0addf1b8d9173ebedc575bdbd6ab828ff7dfec09f11b6f57738facd687bd892b5ce4ea351264477b70cb44637377db73d3f2b06e154daf63176d5f4d
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Ruby CircleCI 2.0 configuration file
|
2
|
+
#
|
3
|
+
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
|
4
|
+
#
|
5
|
+
version: 2
|
6
|
+
jobs:
|
7
|
+
build:
|
8
|
+
docker:
|
9
|
+
# specify the version you desire here
|
10
|
+
- image: circleci/ruby:2.4.1-node-browsers
|
11
|
+
|
12
|
+
working_directory: ~/repo
|
13
|
+
|
14
|
+
steps:
|
15
|
+
- checkout
|
16
|
+
|
17
|
+
# Download and cache dependencies
|
18
|
+
- restore_cache:
|
19
|
+
keys:
|
20
|
+
- v1-dependencies-{{ checksum "bill_hicks.gemspec" }}
|
21
|
+
# fallback to using the latest cache if no exact match is found
|
22
|
+
- v1-dependencies-
|
23
|
+
|
24
|
+
- run:
|
25
|
+
name: install dependencies
|
26
|
+
command: |
|
27
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
28
|
+
|
29
|
+
- save_cache:
|
30
|
+
paths:
|
31
|
+
- ./vendor/bundle
|
32
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
33
|
+
|
34
|
+
# run tests!
|
35
|
+
- run:
|
36
|
+
name: run tests
|
37
|
+
command: |
|
38
|
+
mkdir /tmp/test-results
|
39
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
|
40
|
+
|
41
|
+
bundle exec rspec --format documentation $TEST_FILES
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.3.
|
1
|
+
2.3.6
|
data/README.md
CHANGED
@@ -18,95 +18,6 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
$ gem install bill_hicks
|
20
20
|
|
21
|
-
## Usage
|
22
|
-
|
23
|
-
**Note:** Nearly all methods require `:username` and `:password` keys in the options hash.
|
24
|
-
|
25
|
-
```ruby
|
26
|
-
options = {
|
27
|
-
username: 'dealer@example.com',
|
28
|
-
password: 'sekret-passwd'
|
29
|
-
}
|
30
|
-
```
|
31
|
-
|
32
|
-
### BillHicks::Catalog
|
33
|
-
|
34
|
-
To get all items in the catalog:
|
35
|
-
|
36
|
-
```ruby
|
37
|
-
catalog = BillHicks::Catalog.all(options)
|
38
|
-
```
|
39
|
-
|
40
|
-
See `BillHicks::Catalog` for the response structure.
|
41
|
-
|
42
|
-
### BillHicks::Inventory
|
43
|
-
|
44
|
-
To get your inventory details (availability, price, etc.):
|
45
|
-
|
46
|
-
```ruby
|
47
|
-
inventory = BillHicks::Inventory.all(options)
|
48
|
-
```
|
49
|
-
|
50
|
-
See `BillHicks::Inventory` for the response structure.
|
51
|
-
|
52
|
-
### BillHicks::Category
|
53
|
-
|
54
|
-
Returns an array of category codes and descriptions.
|
55
|
-
|
56
|
-
```ruby
|
57
|
-
categories = BillHicks::Category.all(options)
|
58
|
-
|
59
|
-
# [
|
60
|
-
# {:code=>"H648", :description=>"AIRGUNS"},
|
61
|
-
# {:code=>"H610", :description=>"AMMUNITION"},
|
62
|
-
# ...,
|
63
|
-
# ]
|
64
|
-
```
|
65
|
-
|
66
|
-
### BillHicks::Order
|
67
|
-
|
68
|
-
To build and submit an order, the basic steps are: 1) instantiate an Order object, 2) add header
|
69
|
-
information, 3) add item information (multiple items if needed), 4) submit the order.
|
70
|
-
|
71
|
-
```ruby
|
72
|
-
# Instantiate the Order instance, passing in your :username and :password
|
73
|
-
order = BillHicks::Order.new(options)
|
74
|
-
|
75
|
-
# Add header information:
|
76
|
-
header_opts = {
|
77
|
-
customer: '...', # customer number
|
78
|
-
purchase_order: '...', # application specific purchase order
|
79
|
-
ffl: '...', # your FFL number
|
80
|
-
shipping: { # shipping information (all fields except :address_2 are required)
|
81
|
-
name: '...',
|
82
|
-
address_1: '...',
|
83
|
-
address_2: '...',
|
84
|
-
city: '...',
|
85
|
-
state: '...',
|
86
|
-
zip: '...',
|
87
|
-
},
|
88
|
-
|
89
|
-
# Optional fields:
|
90
|
-
shipping_method: '...',
|
91
|
-
notes: '...',
|
92
|
-
}
|
93
|
-
order.add_header(header_opts)
|
94
|
-
|
95
|
-
# Add item information:
|
96
|
-
item_opts = {
|
97
|
-
item_number: '...', # Bill Hicks item number
|
98
|
-
description: '...',
|
99
|
-
quantity: 1,
|
100
|
-
price: '123.45', # Decimal formatted price, without currency sign
|
101
|
-
}
|
102
|
-
order.add_item(item_opts) # Multiple items may be added, just call #add_item for each one.
|
103
|
-
|
104
|
-
# Submit the order (returns true on success, raises an exception on failgure):
|
105
|
-
order.submit!
|
106
|
-
```
|
107
|
-
|
108
|
-
See `BillHicks::Order` for details on required options.
|
109
|
-
|
110
21
|
## Development
|
111
22
|
|
112
23
|
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.
|
data/bill_hicks.gemspec
CHANGED
@@ -23,7 +23,8 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.add_runtime_dependency "smarter_csv", "~> 1.1.4"
|
25
25
|
|
26
|
+
spec.add_development_dependency "activesupport", "~> 5"
|
26
27
|
spec.add_development_dependency "bundler", "~> 1.12"
|
27
|
-
spec.add_development_dependency "rake", "
|
28
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
28
29
|
spec.add_development_dependency "rspec", "~> 3.5"
|
29
30
|
end
|
data/lib/bill_hicks/base.rb
CHANGED
@@ -5,9 +5,13 @@ module BillHicks
|
|
5
5
|
requires!(options, :username, :password)
|
6
6
|
|
7
7
|
Net::FTP.open(BillHicks.config.ftp_host, options[:username], options[:password]) do |ftp|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
begin
|
9
|
+
ftp.debug_mode = BillHicks.config.debug_mode
|
10
|
+
ftp.passive = true
|
11
|
+
yield ftp
|
12
|
+
ensure
|
13
|
+
ftp.close
|
14
|
+
end
|
11
15
|
end
|
12
16
|
rescue Net::FTPPermError
|
13
17
|
raise BillHicks::NotAuthenticated
|
@@ -36,7 +40,26 @@ module BillHicks
|
|
36
40
|
# Instance methods become class methods through inheritance
|
37
41
|
def connect(options)
|
38
42
|
self.class.connect(options) do |ftp|
|
39
|
-
|
43
|
+
begin
|
44
|
+
yield ftp
|
45
|
+
ensure
|
46
|
+
ftp.close
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_file(filename)
|
52
|
+
connect(@options) do |ftp|
|
53
|
+
begin
|
54
|
+
tempfile = Tempfile.new
|
55
|
+
|
56
|
+
ftp.chdir(BillHicks.config.top_level_dir)
|
57
|
+
ftp.getbinaryfile(filename, tempfile.path)
|
58
|
+
|
59
|
+
tempfile
|
60
|
+
ensure
|
61
|
+
ftp.close
|
62
|
+
end
|
40
63
|
end
|
41
64
|
end
|
42
65
|
|
@@ -134,6 +134,7 @@ module BillHicks
|
|
134
134
|
{ prefix: 'FED', company: 'Federal' },
|
135
135
|
{ prefix: 'IND', company: 'Federal' },
|
136
136
|
{ prefix: 'FIO', company: 'Fiocchi' },
|
137
|
+
{ prefix: 'FO', company: 'Freedom Ordnance' },
|
137
138
|
{ prefix: 'WILL', company: 'Williams Gun Sight Company' },
|
138
139
|
{ prefix: 'FC', company: 'Flippin Critters' },
|
139
140
|
{ prefix: 'FLITZ', company: 'Flitz' },
|
data/lib/bill_hicks/catalog.rb
CHANGED
@@ -14,7 +14,8 @@ module BillHicks
|
|
14
14
|
# }
|
15
15
|
class Catalog < Base
|
16
16
|
|
17
|
-
|
17
|
+
CHUNK_SIZE = 500
|
18
|
+
CATALOG_FILENAME = 'billhickscatalog.csv'.freeze
|
18
19
|
PERMITTED_FEATURES = [
|
19
20
|
'weight',
|
20
21
|
'caliber',
|
@@ -46,12 +47,14 @@ module BillHicks
|
|
46
47
|
@options = options
|
47
48
|
end
|
48
49
|
|
49
|
-
def self.all(
|
50
|
+
def self.all(options = {})
|
50
51
|
requires!(options, :username, :password)
|
51
|
-
new(options).all
|
52
|
+
new(options).all
|
52
53
|
end
|
53
54
|
|
54
|
-
def all
|
55
|
+
def all
|
56
|
+
items = []
|
57
|
+
|
55
58
|
connect(@options) do |ftp|
|
56
59
|
tempfile = Tempfile.new
|
57
60
|
|
@@ -59,7 +62,7 @@ module BillHicks
|
|
59
62
|
ftp.getbinaryfile(CATALOG_FILENAME, tempfile.path)
|
60
63
|
|
61
64
|
SmarterCSV.process(tempfile, {
|
62
|
-
chunk_size:
|
65
|
+
chunk_size: CHUNK_SIZE,
|
63
66
|
force_utf8: true,
|
64
67
|
convert_values_to_numeric: false,
|
65
68
|
key_mapping: {
|
@@ -75,39 +78,27 @@ module BillHicks
|
|
75
78
|
item.except!(:category_code)
|
76
79
|
|
77
80
|
item[:item_identifier] = item[:name]
|
78
|
-
item[:brand]
|
79
|
-
item[:mfg_number]
|
81
|
+
item[:brand] = BillHicks::BrandConverter.convert(item[:name])
|
82
|
+
item[:mfg_number] = item[:name].split.last
|
80
83
|
|
81
84
|
if item[:long_description].present?
|
82
|
-
features =
|
83
|
-
|
84
|
-
if features[:action].present?
|
85
|
-
item[:action] = features[:action]
|
86
|
-
|
87
|
-
features.delete(:action)
|
88
|
-
end
|
89
|
-
|
90
|
-
if features[:caliber].present?
|
91
|
-
item[:caliber] = features[:caliber]
|
92
|
-
|
93
|
-
features.delete(:caliber)
|
94
|
-
end
|
85
|
+
features = parse_features(item[:long_description])
|
95
86
|
|
96
|
-
if features[:
|
97
|
-
|
98
|
-
|
99
|
-
features.delete(:weight)
|
100
|
-
end
|
87
|
+
item[:action] = features.delete(:action) if features[:action].present?
|
88
|
+
item[:caliber] = features.delete(:caliber) if features[:caliber].present?
|
89
|
+
item[:weight] = features.delete(:weight) if features[:weight].present?
|
101
90
|
|
102
91
|
item[:features] = features
|
103
92
|
end
|
104
|
-
end
|
105
93
|
|
106
|
-
|
94
|
+
items << item
|
95
|
+
end
|
107
96
|
end
|
108
97
|
|
109
98
|
tempfile.unlink
|
110
99
|
end
|
100
|
+
|
101
|
+
items
|
111
102
|
end
|
112
103
|
|
113
104
|
protected
|
data/lib/bill_hicks/inventory.rb
CHANGED
@@ -8,6 +8,7 @@ module BillHicks
|
|
8
8
|
# }
|
9
9
|
class Inventory < Base
|
10
10
|
|
11
|
+
CHUNK_SIZE = 2000
|
11
12
|
INVENTORY_FILENAME = 'billhicksinventory.csv'
|
12
13
|
|
13
14
|
def initialize(options = {})
|
@@ -15,44 +16,67 @@ module BillHicks
|
|
15
16
|
@options = options
|
16
17
|
end
|
17
18
|
|
18
|
-
def self.
|
19
|
+
def self.get_quantity_file(options = {})
|
19
20
|
requires!(options, :username, :password)
|
20
|
-
new(options).
|
21
|
+
new(options).get_quantity_file
|
21
22
|
end
|
22
23
|
|
23
|
-
def self.
|
24
|
+
def self.quantity(options = {})
|
24
25
|
requires!(options, :username, :password)
|
25
|
-
new(options).all
|
26
|
+
new(options).all
|
26
27
|
end
|
27
28
|
|
28
|
-
def all(
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
29
|
+
def self.all(options = {})
|
30
|
+
requires!(options, :username, :password)
|
31
|
+
new(options).all
|
32
|
+
end
|
33
|
+
|
34
|
+
def all
|
35
|
+
items = []
|
36
|
+
quantity_tempfile = get_file(INVENTORY_FILENAME)
|
37
|
+
|
38
|
+
SmarterCSV.process(quantity_tempfile, {
|
39
|
+
chunk_size: CHUNK_SIZE,
|
40
|
+
force_utf8: true,
|
41
|
+
convert_values_to_numeric: false,
|
42
|
+
key_mapping: {
|
43
|
+
product: :item_identifier,
|
44
|
+
qty_avail: :quantity,
|
45
|
+
}
|
46
|
+
}) do |chunk|
|
47
|
+
chunk.each do |item|
|
48
|
+
items << item
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
quantity_tempfile.close
|
53
|
+
quantity_tempfile.unlink
|
54
|
+
|
55
|
+
items
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_quantity_file
|
59
|
+
quantity_tempfile = get_file(INVENTORY_FILENAME)
|
60
|
+
tempfile = Tempfile.new
|
61
|
+
|
62
|
+
SmarterCSV.process(quantity_tempfile, {
|
63
|
+
chunk_size: CHUNK_SIZE,
|
64
|
+
force_utf8: true,
|
65
|
+
convert_values_to_numeric: false,
|
66
|
+
key_mapping: {
|
67
|
+
product: :item_identifier,
|
68
|
+
qty_avail: :quantity,
|
69
|
+
}
|
70
|
+
}) do |chunk|
|
71
|
+
chunk.each do |item|
|
72
|
+
tempfile.puts("#{item[:item_identifier]},#{item[:quantity]}")
|
54
73
|
end
|
55
74
|
end
|
75
|
+
|
76
|
+
quantity_tempfile.close
|
77
|
+
quantity_tempfile.unlink
|
78
|
+
tempfile.close
|
79
|
+
tempfile.path
|
56
80
|
end
|
57
81
|
|
58
82
|
alias quantity all
|
data/lib/bill_hicks/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bill_hicks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dale Campbell
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: smarter_csv
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.1.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -42,16 +56,16 @@ dependencies:
|
|
42
56
|
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - "
|
59
|
+
- - ">="
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
61
|
+
version: 12.3.3
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- - "
|
66
|
+
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
68
|
+
version: 12.3.3
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rspec
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,11 +87,11 @@ executables: []
|
|
73
87
|
extensions: []
|
74
88
|
extra_rdoc_files: []
|
75
89
|
files:
|
90
|
+
- ".circleci/config.yml"
|
76
91
|
- ".gitignore"
|
77
92
|
- ".rspec"
|
78
93
|
- ".ruby-gemset"
|
79
94
|
- ".ruby-version"
|
80
|
-
- ".travis.yml"
|
81
95
|
- Gemfile
|
82
96
|
- LICENSE.txt
|
83
97
|
- README.md
|
@@ -116,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
130
|
version: '0'
|
117
131
|
requirements: []
|
118
132
|
rubyforge_project:
|
119
|
-
rubygems_version: 2.
|
133
|
+
rubygems_version: 2.6.14.1
|
120
134
|
signing_key:
|
121
135
|
specification_version: 4
|
122
136
|
summary: Ruby library for Bill Hicks ERP system
|