bill_hicks 0.2.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/bill_hicks.gemspec +1 -1
- data/bin/setup +0 -2
- data/lib/bill_hicks.rb +35 -0
- data/lib/bill_hicks/base.rb +13 -9
- data/lib/bill_hicks/catalog.rb +1 -2
- data/lib/bill_hicks/inventory.rb +1 -2
- data/lib/bill_hicks/order.rb +7 -6
- data/lib/bill_hicks/response_file.rb +51 -0
- data/lib/bill_hicks/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63513599c0b2819f553f3c2a761fe07f931c1697
|
4
|
+
data.tar.gz: 8484b2ac79c96634b3cf4d05aa91ba0e131d203f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47872726da303d436c4d3a65361b5a263f825ebea540f0c4956edec9eff6e20a96f1696eb2a2a3ebad9cd4624b0130559b1b7aac00bc6d227a970ed9965cdc50
|
7
|
+
data.tar.gz: 81cf9a3343ea5a8c9b4a029c587b358745555c885e5f9248ea0fc8f45ea3cb31952ff9bf6e843b628d27049da5fd0d32ff512987b50b045f95ccc65e403a6264
|
data/bill_hicks.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.add_development_dependency "bundler", "~> 1.
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
25
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
26
|
spec.add_development_dependency "rspec", "~> 3.0"
|
27
27
|
end
|
data/bin/setup
CHANGED
data/lib/bill_hicks.rb
CHANGED
@@ -8,9 +8,44 @@ require 'bill_hicks/catalog'
|
|
8
8
|
require 'bill_hicks/category'
|
9
9
|
require 'bill_hicks/inventory'
|
10
10
|
require 'bill_hicks/order'
|
11
|
+
require 'bill_hicks/response_file'
|
11
12
|
require 'bill_hicks/user'
|
12
13
|
|
13
14
|
module BillHicks
|
14
15
|
class InvalidOrder < StandardError; end
|
15
16
|
class NotAuthenticated < StandardError; end
|
17
|
+
|
18
|
+
class << self
|
19
|
+
attr_accessor :config
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.config
|
23
|
+
@config ||= Configuration.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.configure
|
27
|
+
yield(config)
|
28
|
+
end
|
29
|
+
|
30
|
+
class Configuration
|
31
|
+
attr_accessor :ftp_host
|
32
|
+
attr_accessor :response_dir
|
33
|
+
attr_accessor :submission_dir
|
34
|
+
attr_accessor :top_level_dir
|
35
|
+
|
36
|
+
def initialize
|
37
|
+
@ftp_host ||= "billhicksco.hostedftp.com"
|
38
|
+
@top_level_dir ||= "AmmoReady"
|
39
|
+
@submission_dir ||= "toBHC"
|
40
|
+
@response_dir ||= "fromBHC"
|
41
|
+
end
|
42
|
+
|
43
|
+
def full_submission_dir
|
44
|
+
File.join(@top_level_dir, @submission_dir)
|
45
|
+
end
|
46
|
+
|
47
|
+
def full_response_dir
|
48
|
+
File.join(@top_level_dir, @response_dir)
|
49
|
+
end
|
50
|
+
end
|
16
51
|
end
|
data/lib/bill_hicks/base.rb
CHANGED
@@ -1,8 +1,16 @@
|
|
1
1
|
module BillHicks
|
2
2
|
class Base
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
def self.connect(options = {})
|
5
|
+
requires!(options, :username, :password)
|
6
|
+
|
7
|
+
Net::FTP.open(BillHicks.config.ftp_host, options[:username], options[:password]) do |ftp|
|
8
|
+
ftp.passive = true
|
9
|
+
yield ftp
|
10
|
+
end
|
11
|
+
rescue Net::FTPPermError
|
12
|
+
raise BillHicks::NotAuthenticated
|
13
|
+
end
|
6
14
|
|
7
15
|
protected
|
8
16
|
|
@@ -24,15 +32,11 @@ module BillHicks
|
|
24
32
|
end
|
25
33
|
end
|
26
34
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
Net::FTP.open(FTP_HOST, options[:username], options[:password]) do |ftp|
|
31
|
-
ftp.passive = true
|
35
|
+
# Instance methods become class methods through inheritance
|
36
|
+
def connect(options)
|
37
|
+
self.class.connect(options) do |ftp|
|
32
38
|
yield ftp
|
33
39
|
end
|
34
|
-
rescue Net::FTPPermError
|
35
|
-
raise BillHicks::NotAuthenticated
|
36
40
|
end
|
37
41
|
|
38
42
|
end
|
data/lib/bill_hicks/catalog.rb
CHANGED
@@ -20,7 +20,6 @@ module BillHicks
|
|
20
20
|
|
21
21
|
CATALOG_FILENAME = 'billhickscatalog.csv'
|
22
22
|
|
23
|
-
|
24
23
|
def initialize(options = {})
|
25
24
|
requires!(options, :username, :password)
|
26
25
|
@options = options
|
@@ -36,7 +35,7 @@ module BillHicks
|
|
36
35
|
catalog = []
|
37
36
|
|
38
37
|
connect(@options) do |ftp|
|
39
|
-
ftp.chdir(
|
38
|
+
ftp.chdir(BillHicks.config.top_level_dir)
|
40
39
|
|
41
40
|
lines = ftp.gettextfile(CATALOG_FILENAME, nil)
|
42
41
|
|
data/lib/bill_hicks/inventory.rb
CHANGED
@@ -10,7 +10,6 @@ module BillHicks
|
|
10
10
|
|
11
11
|
INVENTORY_FILENAME = 'billhicksinventory.csv'
|
12
12
|
|
13
|
-
|
14
13
|
def initialize(options = {})
|
15
14
|
requires!(options, :username, :password)
|
16
15
|
@options = options
|
@@ -26,7 +25,7 @@ module BillHicks
|
|
26
25
|
inventory = []
|
27
26
|
|
28
27
|
connect(@options) do |ftp|
|
29
|
-
ftp.chdir(
|
28
|
+
ftp.chdir(BillHicks.config.top_level_dir)
|
30
29
|
|
31
30
|
lines = ftp.gettextfile(INVENTORY_FILENAME, nil)
|
32
31
|
|
data/lib/bill_hicks/order.rb
CHANGED
@@ -9,8 +9,6 @@ module BillHicks
|
|
9
9
|
# See each method for a list of required options.
|
10
10
|
class Order < Base
|
11
11
|
|
12
|
-
ORDER_UPLOAD_DIR = [FTP_DIR, 'toBHC'].join('/')
|
13
|
-
|
14
12
|
# @option options [String] :username *required*
|
15
13
|
# @option options [String] :password *required*
|
16
14
|
def initialize(options = {})
|
@@ -45,12 +43,15 @@ module BillHicks
|
|
45
43
|
@items << item
|
46
44
|
end
|
47
45
|
|
46
|
+
def filename
|
47
|
+
"#{@header[:purchase_order]}-order.txt"
|
48
|
+
end
|
49
|
+
|
48
50
|
def submit!
|
49
51
|
raise BillHicks::InvalidOrder.new("Must call #add_header before submitting") if @header.nil?
|
50
52
|
raise BillHicks::InvalidOrder.new("Must add items with #add_item before submitting") if @items.empty?
|
51
53
|
|
52
|
-
@
|
53
|
-
@order_file = Tempfile.new(@order_filename)
|
54
|
+
@order_file = Tempfile.new(filename)
|
54
55
|
begin
|
55
56
|
CSV.open(@order_file.path, 'w+') do |csv|
|
56
57
|
csv << header_names
|
@@ -111,8 +112,8 @@ module BillHicks
|
|
111
112
|
|
112
113
|
def upload!
|
113
114
|
connect(@options) do |ftp|
|
114
|
-
ftp.chdir(
|
115
|
-
ftp.puttextfile(@order_file.path,
|
115
|
+
ftp.chdir(BillHicks.config.full_submission_dir)
|
116
|
+
ftp.puttextfile(@order_file.path, filename)
|
116
117
|
end
|
117
118
|
end
|
118
119
|
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module BillHicks
|
2
|
+
class ResponseFile < Base
|
3
|
+
|
4
|
+
attr_reader :content
|
5
|
+
attr_reader :credentials
|
6
|
+
attr_reader :filename
|
7
|
+
|
8
|
+
FILE_TYPES = {
|
9
|
+
"ACK" => "Purchase Order Acknowledgement",
|
10
|
+
"ASN" => "Advance Shipping Notice"
|
11
|
+
}
|
12
|
+
|
13
|
+
# @option options [String] :username *required*
|
14
|
+
# @option options [String] :password *required*
|
15
|
+
# @option options [String] :filename *required*
|
16
|
+
def initialize(options = {})
|
17
|
+
requires!(options, :username, :password, :filename)
|
18
|
+
|
19
|
+
@credentials = options.select { |k, v| [:username, :password].include?(k) }
|
20
|
+
@filename = options[:filename]
|
21
|
+
end
|
22
|
+
|
23
|
+
# Return list of '855 Purchase Order Acknowledgement' files
|
24
|
+
# @option options [String] :username *required*
|
25
|
+
# @option options [String] :password *required*
|
26
|
+
def self.all(options = {})
|
27
|
+
requires!(options, :username, :password)
|
28
|
+
|
29
|
+
Base.connect(options) do |ftp|
|
30
|
+
ftp.chdir(BillHicks.config.full_response_dir)
|
31
|
+
ftp.nlst("*.txt")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def content
|
36
|
+
return @content if @content
|
37
|
+
connect(@credentials) do |ftp|
|
38
|
+
ftp.chdir(BillHicks.config.full_response_dir)
|
39
|
+
@content = ftp.gettextfile(@filename, nil)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_json
|
44
|
+
CSV.parse(content, headers: true, col_sep: "|").
|
45
|
+
map { |x| x.to_h }.
|
46
|
+
group_by { |x| x["PO Number"] }
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
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: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dale Campbell
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.12'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.12'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- lib/bill_hicks/category.rb
|
78
78
|
- lib/bill_hicks/inventory.rb
|
79
79
|
- lib/bill_hicks/order.rb
|
80
|
+
- lib/bill_hicks/response_file.rb
|
80
81
|
- lib/bill_hicks/user.rb
|
81
82
|
- lib/bill_hicks/version.rb
|
82
83
|
homepage: ''
|
@@ -99,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
100
|
version: '0'
|
100
101
|
requirements: []
|
101
102
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.
|
103
|
+
rubygems_version: 2.6.7
|
103
104
|
signing_key:
|
104
105
|
specification_version: 4
|
105
106
|
summary: Ruby library for Bill Hicks ERP system
|