bill_hicks 2.1.4 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bill_hicks/base.rb +17 -0
- data/lib/bill_hicks/inventory.rb +46 -25
- data/lib/bill_hicks/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a9bf35ce7df7b67c93b47936309a3641eb7f455
|
4
|
+
data.tar.gz: b12c4e7d2b36d8b4c128a884031ea40361b3bcfe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8834a97ba02ed8cf1e2f5d290523719ffa2816b62f6fc68482cfc739b277869af7580c37538fdc1e66fa09b9083aa3613c684f86925c79fb47543bf0d1f68be
|
7
|
+
data.tar.gz: 2e2428f0371992e6972603955ff1d5be212aeb90abed38580c3e74a51a08d4bc03a832b48714b501a5d352b4fe7c58ea857ae72b096bfbfd1f37fcaa0d483248
|
data/lib/bill_hicks/base.rb
CHANGED
@@ -40,5 +40,22 @@ module BillHicks
|
|
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(BillHicks.config.top_level_dir)
|
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
|
end
|
44
61
|
end
|
data/lib/bill_hicks/inventory.rb
CHANGED
@@ -15,6 +15,11 @@ module BillHicks
|
|
15
15
|
@options = options
|
16
16
|
end
|
17
17
|
|
18
|
+
def self.get_quantity_file(options = {})
|
19
|
+
requires!(options, :username, :password)
|
20
|
+
new(options).get_quantity_file
|
21
|
+
end
|
22
|
+
|
18
23
|
def self.quantity(chunk_size = 15, options = {}, &block)
|
19
24
|
requires!(options, :username, :password)
|
20
25
|
new(options).all(chunk_size, &block)
|
@@ -26,33 +31,49 @@ module BillHicks
|
|
26
31
|
end
|
27
32
|
|
28
33
|
def all(chunk_size, &block)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
qty_avail: :quantity,
|
43
|
-
}
|
44
|
-
}) do |chunk|
|
45
|
-
chunk.each do |item|
|
46
|
-
item.except!(:product)
|
47
|
-
end
|
48
|
-
|
49
|
-
yield(chunk)
|
50
|
-
end
|
51
|
-
ensure
|
52
|
-
tempfile.unlink
|
53
|
-
ftp.close
|
34
|
+
quantity_tempfile = get_file(INVENTORY_FILENAME)
|
35
|
+
|
36
|
+
SmarterCSV.process(quantity_tempfile.open, {
|
37
|
+
chunk_size: chunk_size,
|
38
|
+
force_utf8: true,
|
39
|
+
convert_values_to_numeric: false,
|
40
|
+
key_mapping: {
|
41
|
+
product: :item_identifier,
|
42
|
+
qty_avail: :quantity,
|
43
|
+
}
|
44
|
+
}) do |chunk|
|
45
|
+
chunk.each do |item|
|
46
|
+
item.except!(:product)
|
54
47
|
end
|
48
|
+
|
49
|
+
yield(chunk)
|
55
50
|
end
|
51
|
+
|
52
|
+
quantity_tempfile.unlink
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_quantity_file
|
56
|
+
quantity_tempfile = get_file(INVENTORY_FILENAME)
|
57
|
+
tempfile = Tempfile.new
|
58
|
+
|
59
|
+
SmarterCSV.process(quantity_tempfile.open, {
|
60
|
+
chunk_size: 100,
|
61
|
+
force_utf8: true,
|
62
|
+
convert_values_to_numeric: false,
|
63
|
+
key_mapping: {
|
64
|
+
product: :item_identifier,
|
65
|
+
qty_avail: :quantity,
|
66
|
+
}
|
67
|
+
}) do |chunk|
|
68
|
+
chunk.each do |item|
|
69
|
+
tempfile.puts("#{item[:item_identifier]},#{item[:quantity]}")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
quantity_tempfile.unlink
|
74
|
+
tempfile.close
|
75
|
+
|
76
|
+
tempfile.path
|
56
77
|
end
|
57
78
|
|
58
79
|
alias quantity all
|
data/lib/bill_hicks/version.rb
CHANGED