gun_accessory_supply 0.0.1 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gun_accessory_supply/base.rb +10 -5
- data/lib/gun_accessory_supply/catalog.rb +4 -4
- data/lib/gun_accessory_supply/inventory.rb +6 -6
- data/lib/gun_accessory_supply/order.rb +16 -14
- data/lib/gun_accessory_supply/version.rb +1 -1
- data/lib/gun_accessory_supply.rb +11 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cb360468009585d6c544174df5a98e085a8ff8504acd2af87d97d3f91d5e111
|
4
|
+
data.tar.gz: 8ffea43be565f45d76e1dd08b13ddc17fdf7555b01d84abc9bd4e32bd70ddb03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 714b1a759af4f27ed31aeb28caaee92abbac0e7f75cfe11b1563fe3df7ff9f68878516e8bec584940d8661e9abbec0869891ff7ec474bd9e320b7e97efeb6385
|
7
|
+
data.tar.gz: de7c514d94c2f18b1611db4a45af9da44b6169bdd662aeebedd42ab21783f6a084366333c4afbbf937f4a019accde79efb9a3e6135e269365fb9b0042bcad114
|
@@ -3,8 +3,13 @@ module GunAccessorySupply
|
|
3
3
|
|
4
4
|
def self.connect(options = {})
|
5
5
|
requires!(options, :username, :password)
|
6
|
-
|
7
|
-
Net::SFTP.start(
|
6
|
+
|
7
|
+
Net::SFTP.start(
|
8
|
+
GunAccessorySupply.config.proxy_host || GunAccessorySupply.config.sftp_host,
|
9
|
+
options[:username],
|
10
|
+
password: options[:password],
|
11
|
+
port: GunAccessorySupply.config.proxy_port || GunAccessorySupply.config.sftp_port
|
12
|
+
) do |sftp|
|
8
13
|
yield(sftp)
|
9
14
|
end
|
10
15
|
end
|
@@ -47,12 +52,12 @@ module GunAccessorySupply
|
|
47
52
|
node.content.try(:strip)
|
48
53
|
end
|
49
54
|
end
|
50
|
-
|
55
|
+
|
51
56
|
def get_file(filename, file_directory=nil)
|
52
57
|
connect(@options) do |sftp|
|
53
58
|
begin
|
54
59
|
tempfile = Tempfile.new
|
55
|
-
|
60
|
+
|
56
61
|
sftp.download!(File.join(file_directory, filename), tempfile.path)
|
57
62
|
|
58
63
|
return tempfile
|
@@ -67,7 +72,7 @@ module GunAccessorySupply
|
|
67
72
|
sftp.dir.foreach(file_directory) { |entry| filenames << entry.name }
|
68
73
|
filename = filenames.select{ |n| n.include?(file_prefix) }.sort.last
|
69
74
|
|
70
|
-
tempfile = self.get_file(filename, file_directory)
|
75
|
+
tempfile = self.get_file(filename, file_directory)
|
71
76
|
return tempfile
|
72
77
|
end
|
73
78
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module GunAccessorySupply
|
2
2
|
class Catalog < Base
|
3
|
-
|
3
|
+
|
4
4
|
def initialize(options = {})
|
5
5
|
requires!(options, :username, :password)
|
6
6
|
@options = options
|
@@ -12,12 +12,12 @@ module GunAccessorySupply
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def all
|
15
|
-
tempfile = get_most_recent_file(GunAccessorySupply.config.
|
15
|
+
tempfile = get_most_recent_file(GunAccessorySupply.config.inventory_filename_prefix, 'out')
|
16
16
|
items = []
|
17
17
|
|
18
18
|
File.open(tempfile).each_with_index do |row, i|
|
19
19
|
row = parse_row(row)
|
20
|
-
|
20
|
+
|
21
21
|
if i==0
|
22
22
|
@headers = row
|
23
23
|
next
|
@@ -30,7 +30,7 @@ module GunAccessorySupply
|
|
30
30
|
upc: row[@headers.index('UPC')].try(:strip),
|
31
31
|
name: row[@headers.index('Item Description')].try(:strip),
|
32
32
|
quantity: row[@headers.index("Available Qty")].to_i,
|
33
|
-
price: row[@headers.index('
|
33
|
+
price: row[@headers.index('Dealer Cost')].try(:strip),
|
34
34
|
msrp: row[@headers.index('MSRP')].try(:strip),
|
35
35
|
map_price: row[@headers.index('MAP Price')].try(:strip),
|
36
36
|
brand: row[@headers.index('Manufacturer')].try(:strip),
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module GunAccessorySupply
|
2
2
|
class Inventory < Base
|
3
|
-
|
3
|
+
|
4
4
|
def initialize(options = {})
|
5
5
|
requires!(options, :username, :password)
|
6
6
|
@options = options
|
@@ -17,12 +17,12 @@ module GunAccessorySupply
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def all
|
20
|
-
tempfile = get_most_recent_file(GunAccessorySupply.config.
|
20
|
+
tempfile = get_most_recent_file(GunAccessorySupply.config.inventory_filename_prefix, 'out')
|
21
21
|
items = []
|
22
22
|
|
23
23
|
File.open(tempfile).each_with_index do |row, i|
|
24
24
|
row = parse_row(row)
|
25
|
-
|
25
|
+
|
26
26
|
if i==0
|
27
27
|
@headers = row
|
28
28
|
next
|
@@ -31,7 +31,7 @@ module GunAccessorySupply
|
|
31
31
|
item = {
|
32
32
|
item_identifier: row[@headers.index('Item ID')].try(:strip),
|
33
33
|
quantity: row[@headers.index('Available Qty')].to_i,
|
34
|
-
price: row[@headers.index('
|
34
|
+
price: row[@headers.index('Dealer Cost')].try(:strip),
|
35
35
|
}
|
36
36
|
|
37
37
|
items << item
|
@@ -44,12 +44,12 @@ module GunAccessorySupply
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def quantity
|
47
|
-
tempfile = get_most_recent_file(GunAccessorySupply.config.
|
47
|
+
tempfile = get_most_recent_file(GunAccessorySupply.config.inventory_filename_prefix, 'out')
|
48
48
|
items = []
|
49
49
|
|
50
50
|
File.open(tempfile).each_with_index do |row, i|
|
51
51
|
row = parse_row(row)
|
52
|
-
|
52
|
+
|
53
53
|
if i==0
|
54
54
|
@headers = row
|
55
55
|
next
|
@@ -32,7 +32,7 @@ module GunAccessorySupply
|
|
32
32
|
# * :special_instructions [String] optional
|
33
33
|
def add_recipient(hash = {})
|
34
34
|
requires!(hash, :dealer_name, :shipping)
|
35
|
-
requires!(hash[:shipping], :name, :address, :city, :state, :zip, :email
|
35
|
+
requires!(hash[:shipping], :name, :address, :city, :state, :zip, :email)
|
36
36
|
|
37
37
|
@recipient = hash
|
38
38
|
end
|
@@ -45,13 +45,16 @@ module GunAccessorySupply
|
|
45
45
|
# * :price [String]
|
46
46
|
def add_item(item = {})
|
47
47
|
requires!(item, :identifier, :upc, :qty)
|
48
|
+
|
48
49
|
@items << item
|
49
50
|
end
|
50
51
|
|
51
52
|
def filename
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
@filename ||= begin
|
54
|
+
timestamp = Time.now.strftime('%Y%m%d%T').gsub(':', '')
|
55
|
+
|
56
|
+
"GUN-ACCESSORY-SUPPLY-#{@po_number}-#{timestamp}.xml"
|
57
|
+
end
|
55
58
|
end
|
56
59
|
|
57
60
|
def submit!
|
@@ -60,7 +63,6 @@ module GunAccessorySupply
|
|
60
63
|
|
61
64
|
def to_xml
|
62
65
|
output = ""
|
63
|
-
|
64
66
|
xml = Builder::XmlMarkup.new(target: output, indent: 2)
|
65
67
|
|
66
68
|
xml.instruct!(:xml)
|
@@ -68,23 +70,23 @@ module GunAccessorySupply
|
|
68
70
|
xml.cXML(timestamp: Time.now) do
|
69
71
|
xml.Header do
|
70
72
|
xml.From do
|
71
|
-
xml.Credential(domain:
|
72
|
-
xml.Identity
|
73
|
-
xml.SharedSecret
|
73
|
+
xml.Credential(domain: GunAccessorySupply.config.xml_domain) do
|
74
|
+
xml.Identity GunAccessorySupply.config.xml_domain
|
75
|
+
xml.SharedSecret GunAccessorySupply.config.xml_secret
|
74
76
|
xml.OrderID @po_number
|
75
77
|
end
|
76
78
|
end
|
77
79
|
xml.To do
|
78
|
-
xml.Credential(domain:
|
79
|
-
xml.Identity
|
80
|
-
xml.SharedSecret
|
80
|
+
xml.Credential(domain: GunAccessorySupply.config.xml_domain) do
|
81
|
+
xml.Identity GunAccessorySupply.config.xml_domain
|
82
|
+
xml.SharedSecret GunAccessorySupply.config.xml_secret
|
81
83
|
xml.OrderID @po_number
|
82
84
|
end
|
83
85
|
end
|
84
86
|
xml.Sender do
|
85
|
-
xml.Credential(domain:
|
86
|
-
xml.Identity
|
87
|
-
xml.SharedSecret
|
87
|
+
xml.Credential(domain: GunAccessorySupply.config.xml_domain) do
|
88
|
+
xml.Identity GunAccessorySupply.config.xml_domain
|
89
|
+
xml.SharedSecret GunAccessorySupply.config.xml_secret
|
88
90
|
xml.OrderID @po_number
|
89
91
|
end
|
90
92
|
end
|
data/lib/gun_accessory_supply.rb
CHANGED
@@ -1,11 +1,8 @@
|
|
1
1
|
require 'gun_accessory_supply/version'
|
2
|
-
|
3
2
|
require 'csv'
|
4
3
|
require 'net/sftp'
|
5
4
|
require 'tempfile'
|
6
|
-
|
7
5
|
require 'active_support/all'
|
8
|
-
|
9
6
|
require 'gun_accessory_supply/base'
|
10
7
|
require 'gun_accessory_supply/catalog'
|
11
8
|
require 'gun_accessory_supply/category'
|
@@ -32,19 +29,19 @@ module GunAccessorySupply
|
|
32
29
|
end
|
33
30
|
|
34
31
|
class Configuration
|
35
|
-
attr_accessor
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
32
|
+
attr_accessor *%i(
|
33
|
+
sftp_host
|
34
|
+
sftp_port
|
35
|
+
inventory_filename_prefix
|
36
|
+
xml_domain
|
37
|
+
xml_secret
|
38
|
+
proxy_host
|
39
|
+
proxy_port
|
40
|
+
)
|
42
41
|
|
43
42
|
def initialize
|
44
|
-
@
|
45
|
-
@
|
46
|
-
@ftp_port ||= "2222"
|
47
|
-
@top_level_dir ||= "/out"
|
43
|
+
@sftp_host ||= "50.233.131.250"
|
44
|
+
@sftp_port ||= "2222"
|
48
45
|
end
|
49
46
|
end
|
50
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gun_accessory_supply
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Beninate
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|