rsr_group 3.0.1 → 3.0.2

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
- SHA1:
3
- metadata.gz: 2d660007bcdfce8880a51ab15665a8d83b55fe4f
4
- data.tar.gz: 15faf1b6e152b3a6acb91102905b44c056de3162
2
+ SHA256:
3
+ metadata.gz: 5f1ccfd958f485916952de979f88c61690c73a6f534c10324801cdfb9aef34da
4
+ data.tar.gz: e596d74ed4aaed9db747f0d873844a0dae43c6e9f997def3dd536281745d2d94
5
5
  SHA512:
6
- metadata.gz: 2a7cc57d289350b4bf86604c841b0b3f014f39616cf49ec9a5e6abbb52d85d8ff774f3d18e3422cb279d56672d9070aba00681eeb6d80f1ee918b7540a949d48
7
- data.tar.gz: 98b7e8ac62f25143ab3c7969b0da796882fe6b55ff473d32a363e764833778ed47fb156e6e99d28e359b534d6f577f17765064d53027ddaeeae93ff1e41cbeff
6
+ metadata.gz: 4a8123d177997c6ee26d2a498fb1bf30a1d4f99b1123b893fdd00f3485801c9bb0f10aaf4a9a93127e7b636d3b3a755ec6e529f1bbb2758dbbe05230970d19f4
7
+ data.tar.gz: bf896bd6110264efcfaccb446a940bed7380ff1812db432525abd2fe82f30a6a4ea78834b5279aeafb7c958a53c6b5a59baf32ee0061445b6377eefbf189c029
@@ -0,0 +1,41 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # specify the version you desire here
10
+ - image: circleci/ruby:2.4.1-node-browsers
11
+
12
+ working_directory: ~/repo
13
+
14
+ steps:
15
+ - checkout
16
+
17
+ # Download and cache dependencies
18
+ - restore_cache:
19
+ keys:
20
+ - v1-dependencies-{{ checksum "rsr_group.gemspec" }}
21
+ # fallback to using the latest cache if no exact match is found
22
+ - v1-dependencies-
23
+
24
+ - run:
25
+ name: install dependencies
26
+ command: |
27
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
28
+
29
+ - save_cache:
30
+ paths:
31
+ - ./vendor/bundle
32
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
33
+
34
+ # run tests!
35
+ - run:
36
+ name: run tests
37
+ command: |
38
+ mkdir /tmp/test-results
39
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
40
+
41
+ bundle exec rspec --format documentation $TEST_FILES
@@ -1 +1 @@
1
- 2.3.1
1
+ 2.3.6
@@ -1,6 +1,13 @@
1
1
  module RsrGroup
2
2
  class Base
3
3
 
4
+ KEYDEALER_DIR = 'keydealer'.freeze
5
+ DEFAULT_DIR = 'ftpdownloads'.freeze
6
+ QTY_FILENAME = 'IM-QTY-CSV.csv'.freeze
7
+ MAP_FILENAME = 'retail-map.csv'.freeze
8
+ DEFAULT_CATALOG_FILENAME = 'rsrinventory-new.txt'.freeze
9
+ KEYDEALER_CATALOG_FILENAME = 'rsrinventory-keydlr-new.txt'.freeze
10
+
4
11
  def self.connect(options = {})
5
12
  requires!(options, :username, :password)
6
13
 
@@ -1,14 +1,8 @@
1
1
  module RsrGroup
2
2
  class Catalog < Base
3
3
 
4
- KEYDEALER_DIR = 'keydealer'.freeze
5
- INVENTORY_DIR = 'ftpdownloads'.freeze
6
- INVENTORY_FILENAME = 'rsrinventory-new.txt'.freeze
7
- KEYDEALER_FILENAME = 'rsrinventory-keydlr-new.txt'.freeze
8
-
9
4
  def initialize(options = {})
10
5
  requires!(options, :username, :password)
11
-
12
6
  @options = options
13
7
  end
14
8
 
@@ -20,23 +14,29 @@ module RsrGroup
20
14
  def all(&block)
21
15
  connect(@options) do |ftp|
22
16
  begin
23
- csv_tempfile = Tempfile.new
17
+ tempfile = Tempfile.new
24
18
 
25
19
  if ftp.nlst.include?(KEYDEALER_DIR)
26
20
  ftp.chdir(KEYDEALER_DIR)
27
- ftp.getbinaryfile(KEYDEALER_FILENAME, csv_tempfile.path)
21
+ ftp.getbinaryfile(KEYDEALER_CATALOG_FILENAME, tempfile.path)
28
22
  else
29
- ftp.chdir(INVENTORY_DIR)
30
- ftp.getbinaryfile(INVENTORY_FILENAME, csv_tempfile.path)
23
+ ftp.chdir(DEFAULT_DIR)
24
+ ftp.getbinaryfile(DEFAULT_CATALOG_FILENAME, tempfile.path)
31
25
  end
26
+ ftp.close
27
+
28
+ CSV.foreach(tempfile, { col_sep: ';', quote_char: "\x00" }).each do |row|
29
+ item = process_row(row)
32
30
 
33
- CSV.foreach(csv_tempfile, { col_sep: ';', quote_char: "\x00" }).each do |row|
34
- yield(process_row(row))
31
+ if !row[12].nil? && row[12].to_sym.eql?(:Allocated)
32
+ item[:quantity] = 0
33
+ end
34
+
35
+ yield(item)
35
36
  end
36
37
  end
37
38
 
38
- csv_tempfile.unlink
39
- ftp.close
39
+ tempfile.unlink
40
40
  end
41
41
  end
42
42
 
@@ -48,19 +48,22 @@ module RsrGroup
48
48
  end
49
49
 
50
50
  def process_row(row)
51
+ category_name = row[3].nil? ? nil : RsrGroup::Department.new(row[3]).name
52
+
51
53
  {
52
- upc: sanitize(row[1]),
53
- item_identifier: sanitize(row[0]),
54
- name: sanitize(row[2]),
55
- model: sanitize(row[9]),
54
+ upc: sanitize(row[1]),
55
+ item_identifier: sanitize(row[0]),
56
+ name: sanitize(row[2]),
57
+ model: sanitize(row[9]),
58
+ category: category_name,
59
+ brand: sanitize(row[10]),
60
+ msrp: sanitize(row[5]),
61
+ price: sanitize(row[6]),
62
+ map_price: sanitize(row[70]),
63
+ quantity: (Integer(sanitize(row[8])) rescue 0),
64
+ mfg_number: sanitize(row[11]),
65
+ weight: sanitize(row[7]),
56
66
  short_description: sanitize(row[2]),
57
- category: row[3].nil? ? nil : RsrGroup::Department.new(row[3]).name,
58
- brand: sanitize(row[10]),
59
- map_price: sanitize(row[70]),
60
- price: sanitize(row[6]),
61
- quantity: (Integer(sanitize(row[8])) rescue 0),
62
- mfg_number: sanitize(row[11]),
63
- weight: sanitize(row[7]),
64
67
  long_description: sanitize(row[13]),
65
68
  features: {
66
69
  shipping_length: sanitize(row[74]),
@@ -1,39 +1,40 @@
1
1
  module RsrGroup
2
2
  class Inventory < Base
3
3
 
4
- KEYDEALER_DIR = 'keydealer'.freeze
5
- INVENTORY_DIR = 'ftpdownloads'.freeze
6
- QTY_FILENAME = 'IM-QTY-CSV.csv'.freeze
7
- MAP_FILENAME = 'retail-map.csv'.freeze
8
- INVENTORY_FILENAME = 'rsrinventory-new.txt'.freeze
9
- KEYDEALER_FILENAME = 'rsrinventory-keydlr-new.txt'.freeze
10
-
11
- DEFAULT_SMART_OPTS = {
4
+ # This corresponds with the 'rsrinventory-new.txt' and 'rsrinventory-keydlr-new.txt' files
5
+ # and the +DEFAULT_CATALOG_FILENAME+ and +KEYDEALER_CATALOG_FILENAME+ constants
6
+ DEFAULT_CATALOG_SMART_OPTS = {
12
7
  chunk_size: 500,
13
8
  convert_values_to_numeric: false,
14
- col_sep: ";",
15
- quote_char: "|",
9
+ col_sep: ';',
10
+ quote_char: '|',
16
11
  headers_in_file: false,
17
12
  user_provided_headers: [
18
13
  :item_identifier, :upc, :short_description, :department_number, :manufacturer_id, :retail_price,
19
14
  :price, :weight, :quantity, :model, :manufacturer, :mfg_number, :allocated_closeout_deleted, :long_description,
20
- :image_name, 51.times.map { |i| "state_#{i}".to_sym }, :ships_ground_only, :signature_required, :blocked_from_drop_ship,
21
- :date_entered, :map_price, :image_disclaimer, :length, :width, :height, :null
15
+ :image_name, 51.times.map { |i| "state_#{i}".to_sym }, :ships_ground_only, :signature_required,
16
+ :blocked_from_drop_ship, :date_entered, :map_price, :image_disclaimer, :length, :width, :height, :null
22
17
  ].flatten,
23
18
  remove_unmapped_keys: true,
24
19
  }
25
20
 
21
+ # This corresponds with the 'IM-QTY-CSV.csv' file and the +QTY_FILENAME+ constant
22
+ DEFAULT_QUANTITY_SMART_OPTS = {
23
+ chunk_size: 2000,
24
+ convert_values_to_numeric: false,
25
+ col_sep: ',',
26
+ headers_in_file: false,
27
+ user_provided_headers: [
28
+ :item_identifier,
29
+ :quantity,
30
+ ]
31
+ }
32
+
26
33
  def initialize(options = {})
27
34
  requires!(options, :username, :password)
28
-
29
35
  @options = options
30
36
  end
31
37
 
32
- def self.get_quantity_file(options = {})
33
- requires!(options, :username, :password)
34
- new(options).get_quantity_file
35
- end
36
-
37
38
  def self.quantity(options = {}, &block)
38
39
  requires!(options, :username, :password)
39
40
  new(options).quantity &block
@@ -51,59 +52,32 @@ module RsrGroup
51
52
  # Is this a key dealer?
52
53
  if ftp.nlst.include?(KEYDEALER_DIR)
53
54
  ftp.chdir(KEYDEALER_DIR)
54
- # Pull from the FTP and save as a temp file
55
- ftp.getbinaryfile(KEYDEALER_FILENAME, tempfile.path)
55
+ # Pull from the FTP and save to a tempfile
56
+ ftp.getbinaryfile(KEYDEALER_CATALOG_FILENAME, tempfile.path)
56
57
  else
57
- ftp.chdir(INVENTORY_DIR)
58
- # Pull from the FTP and save as a temp file
59
- ftp.getbinaryfile(INVENTORY_FILENAME, tempfile.path)
58
+ ftp.chdir(DEFAULT_DIR)
59
+ # Pull from the FTP and save to a tempfile
60
+ ftp.getbinaryfile(DEFAULT_CATALOG_FILENAME, tempfile.path)
60
61
  end
62
+ ftp.close
61
63
 
62
- SmarterCSV.process(tempfile, DEFAULT_SMART_OPTS) do |chunk|
64
+ SmarterCSV.process(tempfile, DEFAULT_CATALOG_SMART_OPTS) do |chunk|
63
65
  chunk.each do |item|
66
+ if !item[:allocated_closeout_deleted].nil? && item[:allocated_closeout_deleted].to_sym.eql?(:Allocated)
67
+ item[:quantity] = 0
68
+ else
69
+ item[:quantity] = item[:quantity].to_i
70
+ end
71
+
64
72
  yield(item)
65
73
  end
66
74
  end
67
75
 
68
76
  tempfile.unlink
69
- ftp.close
70
- end
71
- end
72
-
73
- def get_quantity_file
74
- connect(@options) do |ftp|
75
- quantity_tempfile = Tempfile.new
76
- tempfile = Tempfile.new(['quantity-', '.csv'])
77
-
78
- # Is this a key dealer?
79
- if ftp.nlst.include?(KEYDEALER_DIR)
80
- ftp.chdir(KEYDEALER_DIR)
81
- # Pull from the FTP and save as a temp file
82
- ftp.getbinaryfile(QTY_FILENAME, quantity_tempfile.path)
83
- else
84
- ftp.chdir(INVENTORY_DIR)
85
- # Pull from the FTP and save as a temp file
86
- ftp.getbinaryfile(QTY_FILENAME, quantity_tempfile.path)
87
- end
88
-
89
- ftp.close
90
-
91
- SmarterCSV.process(quantity_tempfile.open, {
92
- chunk_size: 100,
93
- force_utf8: true,
94
- convert_values_to_numeric: false,
95
- user_provided_headers: [:item_identifier, :quantity]
96
- }) do |chunk|
97
- chunk.each do |item|
98
- tempfile.puts("#{item[:item_identifier]},#{item[:quantity].to_i}")
99
- end
100
- end
101
-
102
- quantity_tempfile.unlink
103
- tempfile.path
104
77
  end
105
78
  end
106
79
 
80
+ # Parse through the 'IM-QTY-CSV.csv' file
107
81
  def quantity(&block)
108
82
  connect(@options) do |ftp|
109
83
  tempfile = Tempfile.new
@@ -114,23 +88,15 @@ module RsrGroup
114
88
  # Pull from the FTP and save as a temp file
115
89
  ftp.getbinaryfile(QTY_FILENAME, tempfile.path)
116
90
  else
117
- ftp.chdir(INVENTORY_DIR)
91
+ ftp.chdir(DEFAULT_DIR)
118
92
  # Pull from the FTP and save as a temp file
119
93
  ftp.getbinaryfile(QTY_FILENAME, tempfile.path)
120
94
  end
121
95
  ftp.close
122
96
 
123
- smart_opts = {
124
- col_sep: ",",
125
- headers_in_file: false,
126
- user_provided_headers: [
127
- :item_identifier,
128
- :quantity
129
- ]
130
- }
131
-
132
- SmarterCSV.process(tempfile, smart_opts) do |chunk|
97
+ SmarterCSV.process(tempfile, DEFAULT_QUANTITY_SMART_OPTS) do |chunk|
133
98
  chunk.each do |item|
99
+ item[:quantity] = item[:quantity].to_i
134
100
  yield(item)
135
101
  end
136
102
  end
@@ -1,3 +1,3 @@
1
1
  module RsrGroup
2
- VERSION = '3.0.1'.freeze
2
+ VERSION = '3.0.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsr_group
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dale Campbell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-17 00:00:00.000000000 Z
11
+ date: 2018-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: smarter_csv
@@ -101,11 +101,11 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
+ - ".circleci/config.yml"
104
105
  - ".gitignore"
105
106
  - ".rspec"
106
107
  - ".ruby-gemset"
107
108
  - ".ruby-version"
108
- - ".travis.yml"
109
109
  - Gemfile
110
110
  - LICENSE.txt
111
111
  - README.md
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  version: '0'
149
149
  requirements: []
150
150
  rubyforge_project:
151
- rubygems_version: 2.6.12
151
+ rubygems_version: 2.7.7
152
152
  signing_key:
153
153
  specification_version: 4
154
154
  summary: RSR Group Ruby library
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.3.1
5
- before_install: gem install bundler -v 1.13.1