gun_accessory_supply 0.0.6 → 1.0.1

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: c16419d71639d7b0f6501701a40de275cc70bb2c2378edef32455df9583c8c79
4
- data.tar.gz: a898e1801aeee3f10c56942f056495b43d4f5158e38ceb1527244976c3daa533
3
+ metadata.gz: fa584e428c3c7231eee0cde86090f01a71bcd6cffdba71c1f3a34411bbda8613
4
+ data.tar.gz: 2ca7bd6330a10348cb232df0c3225cde7ae10bf375dbf7088f809d31f3ede77e
5
5
  SHA512:
6
- metadata.gz: 0c618cc69e640ade4b40952af89e1176ee1d707e7c1e492d1eba2b247f7066a86551fb4bd9bf193242cc7d0c4df85108d2d865a51ce3a0b92b06ba7d54818da6
7
- data.tar.gz: 1aaf391a4238b6be337b5d2b65cfb48085d29d875e9ada9769337f4f1ad942d072ad4ea57ecf220b5a2a9d68717bae0811502ff0d58dbeda5d450d9a5522ae67
6
+ metadata.gz: 9db83bb581c99272d4424fd46f8fcb805ff5f98feb590f7d112df711777e8791e7256608a6553b219ea99d1e75dcff40602c54623deea860a10673fb2e977d11
7
+ data.tar.gz: 6086f10d6d784c072901c0ca57b9b62fd3c6021e68ad020dcbd7b8c1f33b13754ddcfba9ce5ba7e837ae0121cb8163cb802d480f5ce5d8a7fef013b236e14ffe
@@ -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
 
@@ -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).file_data(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.6'.freeze
2
+ VERSION = '1.0.1'.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.6
4
+ version: 1.0.1
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