sports_south 3.0.4 → 4.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: b8ffcf4d3fbb056d53b5cdb05ea2dd3174ca8fd306b0721f0c067a523b86339b
4
- data.tar.gz: 814ed8f3c6649ee0fb52bdc024ee934d919976613270d71f91167adc8634e74d
3
+ metadata.gz: 14f58435980d9c679d29c36d8539f634fc438d05797ed712993c89dd51ec1ce8
4
+ data.tar.gz: ef5c4b09f54268ac9de6b5c427d4cbfba6b4af90c92fc3ac0625f423674f9305
5
5
  SHA512:
6
- metadata.gz: 881d8cbd200ae7b66ca98f04b39c6bfbf1efe86a416b8d509711e7b029e74c954441bb1b8f2411fdeef7b4e1e8a28b278e35808913e7f1458e07af20d5a97ac8
7
- data.tar.gz: af555a914628c4b1217a506ff1b345e6a2b6f4f07e10cf27c5438ce4be0584f8b056c885d0fa443b672b329ac65a4bf8ad37865355aa5f3a7a7c3f7e0c7db117
6
+ metadata.gz: 49e51b8c47c04e4a98f95f5d488ab3a9282d2d7e4db96c521a5c366cbedc2c3da23b2e2dbf66356680976d5710c30540d318025f8faede2d98a20835621cfa7a
7
+ data.tar.gz: 46e39889b90fa2bf4b6e3f986c5e3f4fcd89356fe242282b84ab728ea2430d14a463b1fd0b0b474caf6f5370147d13173ca8f99a7710981684589278e1730493
@@ -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 "sports_south.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
@@ -36,7 +36,7 @@ module SportsSouth
36
36
  @brands = SportsSouth::Brand.all(options)
37
37
  end
38
38
 
39
- def self.all(options = {}, &block)
39
+ def self.all(options = {})
40
40
  requires!(options, :username, :password)
41
41
 
42
42
  if options[:last_updated]
@@ -47,24 +47,20 @@ module SportsSouth
47
47
 
48
48
  options[:last_item] ||= '-1'
49
49
 
50
- new(options).all &block
50
+ new(options).all
51
51
  end
52
52
 
53
- def self.get_description(item_number, options = {})
54
- requires!(options, :username, :password)
55
-
56
- new(options, :username, :password)
57
- end
58
-
59
- def all(&block)
53
+ def all
60
54
  http, request = get_http_and_request(API_URL, '/DailyItemUpdate')
61
55
 
62
56
  request.set_form_data(form_params(@options).merge({
63
57
  LastUpdate: @options[:last_updated],
64
58
  LastItem: @options[:last_item].to_s
65
59
  }))
66
-
60
+
61
+ items = []
67
62
  tempfile = download_to_tempfile(http, request)
63
+
68
64
  tempfile.rewind
69
65
 
70
66
  Nokogiri::XML::Reader.from_io(tempfile).each do |reader|
@@ -73,12 +69,21 @@ module SportsSouth
73
69
 
74
70
  node = Nokogiri::XML.parse(reader.outer_xml)
75
71
 
76
- yield map_hash(node.css(ITEM_NODE_NAME), @options[:full_product])
72
+ _map_hash = map_hash(node.css(ITEM_NODE_NAME), @options[:full_product])
73
+
74
+ items << _map_hash unless _map_hash.nil?
77
75
  end
78
76
 
79
77
  tempfile.close
80
78
  tempfile.unlink
81
- true
79
+
80
+ assign_brand_names(items)
81
+ end
82
+
83
+ def self.get_description(item_number, options = {})
84
+ requires!(options, :username, :password)
85
+
86
+ new(options, :username, :password)
82
87
  end
83
88
 
84
89
  def get_description(item_number)
@@ -98,7 +103,6 @@ module SportsSouth
98
103
 
99
104
  def map_hash(node, full_product = false)
100
105
  category = @categories.find { |category| category[:category_id] == content_for(node, 'CATID') }
101
- brand = @brands.find { |brand| brand[:brand_id] == content_for(node, 'ITBRDNO') }
102
106
  features = self.map_features(category.except(:category_id, :department_id, :department_description, :description), node)
103
107
 
104
108
  model = content_for(node, 'IMODEL')
@@ -130,7 +134,7 @@ module SportsSouth
130
134
  caliber: caliber,
131
135
  action: action,
132
136
  map_price: content_for(node, 'MFPRC'),
133
- brand: brand.present? ? brand[:name] : nil,
137
+ brand: content_for(node, 'ITBRDNO').presence,
134
138
  features: features,
135
139
  unit_of_measure: UNITS_OF_MEASURE.fetch(content_for(node, 'UOM'), nil)
136
140
  }
@@ -138,15 +142,15 @@ module SportsSouth
138
142
 
139
143
  def map_features(attributes, node)
140
144
  features = {
141
- attributes[:attribute_1] => content_for(node, 'ITATR1'),
142
- attributes[:attribute_2] => content_for(node, 'ITATR2'),
143
- attributes[:attribute_3] => content_for(node, 'ITATR3'),
144
- attributes[:attribute_4] => content_for(node, 'ITATR4'),
145
- attributes[:attribute_5] => content_for(node, 'ITATR5'),
146
- attributes[:attribute_6] => content_for(node, 'ITATR6'),
147
- attributes[:attribute_7] => content_for(node, 'ITATR7'),
148
- attributes[:attribute_8] => content_for(node, 'ITATR8'),
149
- attributes[:attribute_9] => content_for(node, 'ITATR9'),
145
+ attributes[:attribute_1] => content_for(node, 'ITATR1'),
146
+ attributes[:attribute_2] => content_for(node, 'ITATR2'),
147
+ attributes[:attribute_3] => content_for(node, 'ITATR3'),
148
+ attributes[:attribute_4] => content_for(node, 'ITATR4'),
149
+ attributes[:attribute_5] => content_for(node, 'ITATR5'),
150
+ attributes[:attribute_6] => content_for(node, 'ITATR6'),
151
+ attributes[:attribute_7] => content_for(node, 'ITATR7'),
152
+ attributes[:attribute_8] => content_for(node, 'ITATR8'),
153
+ attributes[:attribute_9] => content_for(node, 'ITATR9'),
150
154
  attributes[:attribute_10] => content_for(node, 'ITATR10'),
151
155
  attributes[:attribute_11] => content_for(node, 'ITATR11'),
152
156
  attributes[:attribute_12] => content_for(node, 'ITATR12'),
@@ -165,5 +169,22 @@ module SportsSouth
165
169
  features.symbolize_keys!
166
170
  end
167
171
 
172
+ def assign_brand_names(items)
173
+ brand_ids = items.collect { |item| item[:brand] }.uniq.compact
174
+
175
+ brand_ids.each do |brand_id|
176
+ brand_name = @brands.find { |brand| brand[:brand_id] == brand_id }.try(:[], :name)
177
+
178
+ next if brand_name.nil?
179
+
180
+ items.map! do |item|
181
+ item[:brand] = brand_name if item[:brand] == brand_id
182
+ item
183
+ end
184
+ end
185
+
186
+ items
187
+ end
188
+
168
189
  end
169
190
  end
@@ -1,3 +1,3 @@
1
1
  module SportsSouth
2
- VERSION = '3.0.4'.freeze
2
+ VERSION = '4.0.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sports_south
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.4
4
+ version: 4.0.0
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-23 00:00:00.000000000 Z
11
+ date: 2019-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -115,6 +115,7 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
+ - ".circleci/config.yml"
118
119
  - ".gitignore"
119
120
  - ".rspec"
120
121
  - ".ruby-gemset"