gun_accessory_supply 0.0.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: adf4003e7ce333052c677e91eb6e09a72c38e158b9331d684b08aaffd3d9a867
4
- data.tar.gz: d1108146ba8e8a17e9a1afa4d9e6620f5bab0703b285e415d122a5cbff8eb060
3
+ metadata.gz: e62de40dc12dccc647ef63845db30843ffebcc34dc972b983902386d41f4f12a
4
+ data.tar.gz: 23f95cfda894bb0476cb8a96074e714ba973fa081cae653fce88c530acec842f
5
5
  SHA512:
6
- metadata.gz: ab3795c87f78a0fdda4e9bde251e140078043b8bd49fb93eec5c3943a18524085baaa190b3dbdd63c65a28a05edeed7958f056e6bca3141f17e711a8da235f4d
7
- data.tar.gz: 5ae910db9102ee76f8fec9978c8107e148a8a4e29d7367d67364bcf5def128a6372487ce7271bf8e1f68fa8110f9237062d0be0078cf22832b50428054c56959
6
+ metadata.gz: f1faa623eafd0163d25e2c40dde87cd29f40f4691a2bac13d151c4023dc51b8ebc2fb2dd9a6a434c217349124f9d4fc5823dfc7966d7cc8ccb5d6ae6dff5b70c
7
+ data.tar.gz: a3d45f7e90194b901f9a8d48fc51b7eb9d2a21bf6b87e7d987eef5f2f9baa6fa1600525ffde72fc906948094e37ad8eec66ac0c1a31baac51036ab039e4985db
@@ -6,8 +6,8 @@ require 'gun_accessory_supply/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "gun_accessory_supply"
8
8
  spec.version = GunAccessorySupply::VERSION
9
- spec.authors = ["Tony Beninate"]
10
- spec.email = ["tonybeninate@icloud.com"]
9
+ spec.authors = ["Tony Beninate", "Jeffrey Dill"]
10
+ spec.email = ["tonybeninate@icloud.com", "jeffdill2@gmail.com"]
11
11
 
12
12
  spec.summary = %q{Ruby library for Gun Accessory Supply}
13
13
  spec.description = %q{}
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_runtime_dependency "activesupport", ">= 5", "< 7"
25
25
  spec.add_runtime_dependency "net-sftp"
26
+ spec.add_runtime_dependency "cxml"
26
27
 
27
28
  spec.add_development_dependency "bundler", ">= 1.15"
28
29
  spec.add_development_dependency "rake", "~> 12.3.0"
@@ -37,9 +37,7 @@ module GunAccessorySupply
37
37
  # Instance methods become class methods through inheritance
38
38
  def connect(options)
39
39
  self.class.connect(options) do |sftp|
40
- begin
41
- yield(sftp)
42
- end
40
+ yield(sftp)
43
41
  end
44
42
  end
45
43
 
@@ -53,27 +51,36 @@ module GunAccessorySupply
53
51
  end
54
52
  end
55
53
 
56
- def get_file(filename, file_directory=nil)
54
+ def get_file(filename, file_directory = nil)
57
55
  connect(@options) do |sftp|
58
- begin
59
- tempfile = Tempfile.new
56
+ tempfile = Tempfile.new
60
57
 
61
- sftp.download!(File.join(file_directory, filename), tempfile.path)
58
+ sftp.download!(File.join(file_directory, filename), tempfile.path)
62
59
 
63
- return tempfile
64
- end
60
+ return tempfile
65
61
  end
66
62
  end
67
63
 
68
- def get_most_recent_file(file_prefix, file_directory=nil)
69
- filenames = []
70
-
64
+ def get_full_filenames(filename_regexes = [], file_directory = nil)
71
65
  connect(@options) do |sftp|
72
- sftp.dir.foreach(file_directory) { |entry| filenames << entry.name }
73
- filename = filenames.select{ |n| n.include?(file_prefix) }.sort.last
66
+ filenames = sftp.dir.entries(file_directory).map(&:name)
67
+ full_regex = Regexp.union(*filename_regexes)
74
68
 
75
- tempfile = self.get_file(filename, file_directory)
76
- return tempfile
69
+ return filenames.select { |filename| filename =~ full_regex }
70
+ end
71
+ end
72
+
73
+ def get_most_recent_file(file_prefix, file_directory = nil)
74
+ connect(@options) do |sftp|
75
+ filename = sftp.
76
+ dir.
77
+ entries(file_directory).
78
+ map(&:name).
79
+ select { |filename| filename.include?(file_prefix) }.
80
+ sort.
81
+ last
82
+
83
+ return get_file(filename, file_directory)
77
84
  end
78
85
  end
79
86
 
@@ -73,28 +73,25 @@ module GunAccessorySupply
73
73
  xml.Credential(domain: GunAccessorySupply.config.xml_domain) do
74
74
  xml.Identity GunAccessorySupply.config.xml_domain
75
75
  xml.SharedSecret GunAccessorySupply.config.xml_secret
76
- xml.OrderID @po_number
77
76
  end
78
77
  end
79
78
  xml.To do
80
79
  xml.Credential(domain: GunAccessorySupply.config.xml_domain) do
81
80
  xml.Identity GunAccessorySupply.config.xml_domain
82
81
  xml.SharedSecret GunAccessorySupply.config.xml_secret
83
- xml.OrderID @po_number
84
82
  end
85
83
  end
86
84
  xml.Sender do
87
85
  xml.Credential(domain: GunAccessorySupply.config.xml_domain) do
88
86
  xml.Identity GunAccessorySupply.config.xml_domain
89
87
  xml.SharedSecret GunAccessorySupply.config.xml_secret
90
- xml.OrderID @po_number
91
88
  end
92
89
  end
93
90
  end
94
91
 
95
92
  xml.Request do
96
93
  xml.OrderRequest do
97
- xml.OrderRequestHeader(orderDate: Time.now, type: 'new') do
94
+ xml.OrderRequestHeader(orderDate: Time.now, type: 'new', orderID: @po_number) do
98
95
  xml.ShipTo do
99
96
  xml.Address(addressID: @ship_to_id) do
100
97
  xml.Name @recipient[:dealer_name]
@@ -0,0 +1,39 @@
1
+ module GunAccessorySupply
2
+ class PO < Base
3
+
4
+ def initialize(options = {})
5
+ requires!(options, :username, :password)
6
+
7
+ @options = options
8
+ end
9
+
10
+ def self.file_names(options = {}, po_numbers = [])
11
+ requires!(options, :username, :password)
12
+
13
+ new(options).file_names(po_numbers)
14
+ end
15
+
16
+ def self.file_data(options = {}, filename)
17
+ requires!(options, :username, :password)
18
+
19
+ new(options).download(filename)
20
+ end
21
+
22
+ def file_names(po_numbers = [])
23
+ filename_regexes = if po_numbers.empty?
24
+ [/#{GunAccessorySupply.config.po_filename_prefix}.*.xml/]
25
+ else
26
+ po_numbers.map do |po_number|
27
+ /#{GunAccessorySupply.config.po_filename_prefix}.*#{po_number}.xml/
28
+ end
29
+ end
30
+
31
+ get_full_filenames(filename_regexes, 'out')
32
+ end
33
+
34
+ def file_data(filename)
35
+ CXML::Parser.new.parse(get_file(filename, 'out').read)
36
+ end
37
+
38
+ end
39
+ end
@@ -1,39 +1,38 @@
1
1
  module GunAccessorySupply
2
2
  class Tracking < Base
3
3
 
4
- BASE_TRACKING_FILE_DIRECTORY = "%s-TRACK".freeze
5
- BASE_TRACKING_FILE_NAME = "%s_PackageTracking.csv".freeze
6
- CARRIER = 'UPS'.freeze
7
-
8
4
  def initialize(options = {})
9
- requires!(options, :username, :password, :dealer_number)
5
+ requires!(options, :username, :password)
10
6
 
11
7
  @options = options
12
- @dealer_number = options[:dealer_number]
13
8
  end
14
9
 
15
- def self.fetch_data(options = {})
16
- requires!(options, :username, :password, :dealer_number)
10
+ def self.file_names(options = {}, po_numbers = [])
11
+ requires!(options, :username, :password)
17
12
 
18
- new(options).fetch_data
13
+ new(options).file_names(po_numbers)
19
14
  end
20
15
 
21
- def fetch_data
22
- tracking_file_name = BASE_TRACKING_FILE_NAME % @dealer_number
23
- tracking_file_directory = BASE_TRACKING_FILE_DIRECTORY % @dealer_number
24
- tracking_file = get_file(tracking_file_name, tracking_file_directory)
25
-
26
- tracking_details = CSV.foreach(tracking_file, { headers: :first_row }).map do |row|
27
- {
28
- po_number: row['USR_VEND_ORD_NO'],
29
- carrier: CARRIER,
30
- tracking_numbers: [row['TRK_NO_1'], row['TRK_NO_2'], row['TRK_NO_3'], row['TRK_NO_4'], row['TRK_NO_5']].reject(&:blank?),
31
- }
16
+ def self.file_data(options = {}, filename)
17
+ requires!(options, :username, :password)
18
+
19
+ new(options).download(filename)
20
+ end
21
+
22
+ def file_names(po_numbers = [])
23
+ filename_regexes = if po_numbers.empty?
24
+ [/#{GunAccessorySupply.config.tracking_filename_prefix}.*.xml/]
25
+ else
26
+ po_numbers.map do |po_number|
27
+ /#{GunAccessorySupply.config.tracking_filename_prefix}.*#{po_number}.xml/
28
+ end
32
29
  end
33
30
 
34
- tracking_file.unlink
31
+ get_full_filenames(filename_regexes, 'out')
32
+ end
35
33
 
36
- tracking_details
34
+ def file_data(filename)
35
+ CXML::Parser.new.parse(get_file(filename, 'out').read)
37
36
  end
38
37
 
39
38
  end
@@ -1,3 +1,3 @@
1
1
  module GunAccessorySupply
2
- VERSION = '0.0.5'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
@@ -1,12 +1,15 @@
1
- require 'gun_accessory_supply/version'
1
+ require 'active_support/all'
2
2
  require 'csv'
3
+ require 'cxml'
3
4
  require 'net/sftp'
4
5
  require 'tempfile'
5
- require 'active_support/all'
6
+
7
+ require 'gun_accessory_supply/version'
6
8
  require 'gun_accessory_supply/base'
7
9
  require 'gun_accessory_supply/catalog'
8
10
  require 'gun_accessory_supply/category'
9
11
  require 'gun_accessory_supply/inventory'
12
+ require 'gun_accessory_supply/po'
10
13
  require 'gun_accessory_supply/order'
11
14
  require 'gun_accessory_supply/tracking'
12
15
  require 'gun_accessory_supply/user'
@@ -33,6 +36,8 @@ module GunAccessorySupply
33
36
  sftp_host
34
37
  sftp_port
35
38
  inventory_filename_prefix
39
+ po_filename_prefix
40
+ tracking_filename_prefix
36
41
  xml_domain
37
42
  xml_secret
38
43
  proxy_host
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gun_accessory_supply
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Beninate
8
+ - Jeffrey Dill
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2022-08-25 00:00:00.000000000 Z
12
+ date: 2022-10-14 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: activesupport
@@ -44,6 +45,20 @@ dependencies:
44
45
  - - ">="
45
46
  - !ruby/object:Gem::Version
46
47
  version: '0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: cxml
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: bundler
49
64
  requirement: !ruby/object:Gem::Requirement
@@ -89,6 +104,7 @@ dependencies:
89
104
  description: ''
90
105
  email:
91
106
  - tonybeninate@icloud.com
107
+ - jeffdill2@gmail.com
92
108
  executables: []
93
109
  extensions: []
94
110
  extra_rdoc_files: []
@@ -108,6 +124,7 @@ files:
108
124
  - lib/gun_accessory_supply/category.rb
109
125
  - lib/gun_accessory_supply/inventory.rb
110
126
  - lib/gun_accessory_supply/order.rb
127
+ - lib/gun_accessory_supply/po.rb
111
128
  - lib/gun_accessory_supply/tracking.rb
112
129
  - lib/gun_accessory_supply/user.rb
113
130
  - lib/gun_accessory_supply/version.rb