zanders 2.1.9 → 2.2.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
  SHA1:
3
- metadata.gz: 4c9d991d9c21ff134173d15b7dd05b35e81d53b7
4
- data.tar.gz: 6d6dd7552e2479e68d669700efc711019e66f25f
3
+ metadata.gz: d5d7e6a4096227d06b1e0a090631b24735fb61cf
4
+ data.tar.gz: 345f6eda3f0c9076cc88b11f5ff6cccc4f295122
5
5
  SHA512:
6
- metadata.gz: 1278a4f53ab409df4f814d4556ee64c85296781fc7c885c7f213576f7af77ebfb4e6c4b1c998485386e97c0ace843e647cb477e2f75b117127d03fd52598e29f
7
- data.tar.gz: 4987f1d12526ed1b1955d4231da3ccc62b923e215943923b503af8331b46c1db0115ff2b5d9b448d991d6ce82f48fdab7d0e178c5d7a457cfb817af4749ec71b
6
+ metadata.gz: d95b63f373522484dc5e441a6a273a1f3083f100acf677c1270a4eb21f87172adbfe27ec9e561b5b0a46655c32203ecd6dcb8dee45d6096fc1807adb250d08ac
7
+ data.tar.gz: 4f762542df84434be54b9c252aa79fc2ca319c2ffb8742069a72d4e376e64583634ea1d4ba3c14ec437384a645ad7e201b6242dfd0076ec37f9c1175da06a3b2
data/lib/zanders/base.rb CHANGED
@@ -40,6 +40,23 @@ module Zanders
40
40
  end
41
41
  end
42
42
 
43
+ def get_file(filename)
44
+ connect(@options) do |ftp|
45
+ begin
46
+ tempfile = Tempfile.new
47
+
48
+ ftp.chdir(Zanders.config.ftp_directory)
49
+ ftp.getbinaryfile(filename, tempfile.path)
50
+
51
+ tempfile.close
52
+
53
+ tempfile
54
+ ensure
55
+ ftp.close
56
+ end
57
+ end
58
+ end
59
+
43
60
  def content_for(xml_doc, field)
44
61
  node = xml_doc.css(field).first
45
62
 
@@ -18,36 +18,25 @@ module Zanders
18
18
  end
19
19
 
20
20
  def all(chunk_size, &block)
21
- chunker = Zanders::Chunker.new(chunk_size)
21
+ chunker = Zanders::Chunker.new(chunk_size)
22
+ tempfile = get_file(CATALOG_FILENAME)
23
+ xml_doc = Nokogiri::XML(tempfile.open)
22
24
 
23
- connect(@options) do |ftp|
24
- begin
25
- csv_tempfile = Tempfile.new
26
-
27
- ftp.chdir(Zanders.config.ftp_directory)
28
- ftp.getbinaryfile(CATALOG_FILENAME, csv_tempfile.path)
29
-
30
- xml_doc = Nokogiri::XML(csv_tempfile)
31
-
32
- xml_doc.xpath("//ZandersDataOut").each do |item|
33
- if chunker.is_full?
34
- yield(chunker.chunk)
35
-
36
- chunker.reset!
37
- else
38
- chunker.add(map_hash(item, @options[:full_product].present?))
39
- end
40
- end
25
+ xml_doc.xpath("//ZandersDataOut").each do |item|
26
+ if chunker.is_full?
27
+ yield(chunker.chunk)
41
28
 
42
- if chunker.chunk.count > 0
43
- yield(chunker.chunk)
44
- end
45
-
46
- csv_tempfile.unlink
47
- ensure
48
- ftp.close
29
+ chunker.reset!
30
+ else
31
+ chunker.add(map_hash(item, @options[:full_product].present?))
49
32
  end
50
33
  end
34
+
35
+ if chunker.chunk.count > 0
36
+ yield(chunker.chunk)
37
+ end
38
+
39
+ tempfile.unlink
51
40
  end
52
41
 
53
42
  protected
@@ -14,42 +14,55 @@ module Zanders
14
14
  new(options).all(chunk_size, &block)
15
15
  end
16
16
 
17
+ def self.get_quantity_file(options = {})
18
+ requires!(options, :username, :password)
19
+ new(options).get_quantity_file
20
+ end
21
+
17
22
  def self.quantity(chunk_size = 100, options = {}, &block)
18
23
  requires!(options, :username, :password)
19
24
  new(options).all(chunk_size, &block)
20
25
  end
21
26
 
22
- def all(chunk_size, &block)
23
- chunker = Zanders::Chunker.new(chunk_size)
27
+ def self.get_file(options = {})
28
+ requires!(options, :username, :password)
29
+ new(options).get_file
30
+ end
24
31
 
25
- connect(@options) do |ftp|
26
- begin
27
- tempfile = Tempfile.new
32
+ def all(chunk_size, &block)
33
+ chunker = Zanders::Chunker.new(chunk_size)
34
+ tempfile = get_file(INVENTORY_FILENAME)
35
+ xml_doc = Nokogiri::XML(tempfile.open)
28
36
 
29
- ftp.chdir(Zanders.config.ftp_directory)
30
- ftp.getbinaryfile(INVENTORY_FILENAME, tempfile.path)
37
+ xml_doc.xpath('//ZandersDataOut').each do |item|
38
+ if chunker.is_full?
39
+ yield(chunker.chunk)
31
40
 
32
- xml_doc = Nokogiri::XML(tempfile)
41
+ chunker.reset!
42
+ else
43
+ chunker.add(map_hash(item))
44
+ end
45
+ end
33
46
 
34
- xml_doc.xpath('//ZandersDataOut').each do |item|
35
- if chunker.is_full?
36
- yield(chunker.chunk)
47
+ if chunker.chunk.count > 0
48
+ yield(chunker.chunk)
49
+ end
37
50
 
38
- chunker.reset!
39
- else
40
- chunker.add(map_hash(item))
41
- end
42
- end
51
+ tempfile.unlink
52
+ end
43
53
 
44
- if chunker.chunk.count > 0
45
- yield(chunker.chunk)
46
- end
54
+ def get_quantity_file
55
+ inventory_tempfile = get_file(INVENTORY_FILENAME)
56
+ tempfile = Tempfile.new
57
+ xml_doc = Nokogiri::XML(inventory_tempfile.open)
47
58
 
48
- tempfile.unlink
49
- ensure
50
- ftp.close
51
- end
59
+ xml_doc.xpath('//ZandersDataOut').each do |item|
60
+ tempfile.write("#{content_for(item, 'ITEMNO')},#{content_for(item, 'AVAILABLE')}\n")
52
61
  end
62
+
63
+ inventory_tempfile.unlink
64
+
65
+ tempfile
53
66
  end
54
67
 
55
68
  private
@@ -1,3 +1,3 @@
1
1
  module Zanders
2
- VERSION = "2.1.9".freeze
2
+ VERSION = "2.2.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zanders
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.9
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Knight
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-24 00:00:00.000000000 Z
11
+ date: 2018-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri