sports_south 2.0.3 → 2.0.4

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: ed2f3a2e646f6849503c9090cd5699e0156ff250
4
- data.tar.gz: c64f1f2b7e3cc2f239364d608b143a0646f70efb
3
+ metadata.gz: 34ff8eafee6d8b855e8d46a14297dfaa086ab27f
4
+ data.tar.gz: b7abf90f19cc28af2916df3a345fde61534ea122
5
5
  SHA512:
6
- metadata.gz: c7eca833567c6c25ae3a4557f9ffbfa7932e1bfbaef31174cfb5db3f6d5573ab4f60fb755700c1e0cc00d3455575b11185ba25d3b2d0e93c91c06586c44d91d2
7
- data.tar.gz: ededb2f69ebcc2c7c9883b9dea95d000e036920488a627387c37e759ac3b427f8d967ba4533aa0a110fbdc02fe09c15c35fac78d8d16cf1058ea01a4ed22fba5
6
+ metadata.gz: c152cb8465053591736a65d37f5a8e9dde43536bba758c91b704df3525595b6f4752f7ccd82987c0e450592508962a557181d5da7d017b26442448fa02060e30
7
+ data.tar.gz: 8a09d81975ece026091695cd0bd64299c8d21162eebec928985af22e1ea436d72a2a9f6be474f4683f434d6a871df297c31c0195fc83e0fb3d91f51a5e5e01ce
@@ -57,11 +57,10 @@ module SportsSouth
57
57
  end
58
58
  def get_http_and_request(*args); self.class.get_http_and_request(*args); end
59
59
 
60
- def self.not_authenticated?(xml_doc)
60
+ def not_authenticated?(xml_doc)
61
61
  msg = content_for(xml_doc, 'ERROR')
62
62
  (msg =~ /Authentication Failed/i) || (msg =~ /NOT AUTHENTICATED/i)
63
63
  end
64
- def not_authenticated?(*args); self.class.not_authenticated?(*args); end
65
64
 
66
65
  # HACK: We have to fix the malformed XML response SS is currently returning.
67
66
  def self.sanitize_response(response)
@@ -3,11 +3,21 @@ module SportsSouth
3
3
 
4
4
  API_URL = 'http://webservices.theshootingwarehouse.com/smart/inventory.asmx'
5
5
 
6
+ def initialize(options = {})
7
+ requires!(options, :username, :password)
8
+
9
+ @options = options
10
+ end
11
+
6
12
  def self.all(options = {})
7
13
  requires!(options, :username, :password)
8
14
 
15
+ new(options).all
16
+ end
17
+
18
+ def all
9
19
  http, request = get_http_and_request(API_URL, '/BrandUpdate')
10
- request.set_form_data(form_params(options))
20
+ request.set_form_data(form_params(@options))
11
21
 
12
22
  response = http.request(request)
13
23
  xml_doc = Nokogiri::XML(sanitize_response(response))
@@ -19,9 +29,9 @@ module SportsSouth
19
29
 
20
30
  protected
21
31
 
22
- def self.map_hash(node)
32
+ def map_hash(node)
23
33
  {
24
- id: content_for(node, 'BRDNO'),
34
+ brand_id: content_for(node, 'BRDNO'),
25
35
  name: content_for(node, 'BRDNM'),
26
36
  url: content_for(node, 'BRDURL'),
27
37
  item_count: content_for(node, 'ITCOUNT')
@@ -25,7 +25,9 @@ module SportsSouth
25
25
  def initialize(options = {})
26
26
  requires!(options, :username, :password)
27
27
 
28
- @options = options
28
+ @options = options
29
+ @categories = SportsSouth::Category.all(options)
30
+ @brands = SportsSouth::Brand.all(options)
29
31
  end
30
32
 
31
33
  def self.all(chunk_size = 15, options = {}, &block)
@@ -60,7 +62,7 @@ module SportsSouth
60
62
 
61
63
  chunker.reset!
62
64
  else
63
- chunker.add(self.map_hash(item))
65
+ chunker.add(map_hash(item))
64
66
  end
65
67
 
66
68
  if chunker.chunk.count > 0
@@ -72,23 +74,27 @@ module SportsSouth
72
74
  protected
73
75
 
74
76
  def map_hash(node)
77
+ category = @categories.find { |category| category[:category_id] == content_for(node, 'CATID') }
78
+ brand = @brands.find { |brand| brand[:brand_id] == content_for(node, 'ITBRDNO') }
79
+
75
80
  {
76
- upc: content_for(node, 'ITUPC'),
77
- item_identifier: content_for(node, 'ITEMNO'),
78
- quantity: content_for(node, 'QTYOH').to_i,
79
- price: content_for(node, 'CPRC'),
80
- short_description: content_for(node, 'SHDESC'),
81
- long_description: content_for(node, 'IDESC'),
82
- category: content_for(node, 'CATID'),
83
- product_type: ITEM_TYPES[content_for(node, 'ITYPE')],
84
- mfg_number: content_for(node, 'IMFGNO'),
85
- weight: content_for(node, 'WTPBX'),
86
- map_price: content_for(node, 'MFPRC'),
87
- brand: content_for(node, 'ITBRDNO'),
81
+ upc: content_for(node, 'ITUPC'),
82
+ item_identifier: content_for(node, 'ITEMNO'),
83
+ quantity: content_for(node, 'QTYOH').to_i,
84
+ price: content_for(node, 'CPRC'),
85
+ short_description: content_for(node, 'SHDESC'),
86
+ long_description: content_for(node, 'IDESC'),
87
+ category: category[:department_description],
88
+ sub_category: category[:description],
89
+ product_type: ITEM_TYPES[content_for(node, 'ITYPE')],
90
+ mfg_number: content_for(node, 'IMFGNO'),
91
+ weight: content_for(node, 'WTPBX'),
92
+ map_price: content_for(node, 'MFPRC'),
93
+ brand: brand[:name],
88
94
  features: {
89
95
  length: content_for(node, 'LENGTH'),
90
96
  height: content_for(node, 'HEIGHT'),
91
- width: content_for(node, 'WIDTH')
97
+ width: content_for(node, 'WIDTH')
92
98
  }
93
99
  }
94
100
  end
@@ -3,11 +3,21 @@ module SportsSouth
3
3
 
4
4
  API_URL = 'http://webservices.theshootingwarehouse.com/smart/inventory.asmx'
5
5
 
6
+ def initialize(options = {})
7
+ requires!(options, :username, :password)
8
+
9
+ @options = options
10
+ end
11
+
6
12
  def self.all(options = {})
7
13
  requires!(options, :username, :password)
8
14
 
15
+ new(options).all
16
+ end
17
+
18
+ def all
9
19
  http, request = get_http_and_request(API_URL, '/CategoryUpdate')
10
- request.set_form_data(form_params(options))
20
+ request.set_form_data(form_params(@options))
11
21
 
12
22
  response = http.request(request)
13
23
  xml_doc = Nokogiri::XML(sanitize_response(response))
@@ -19,7 +29,7 @@ module SportsSouth
19
29
 
20
30
  protected
21
31
 
22
- def self.map_hash(node)
32
+ def map_hash(node)
23
33
  {
24
34
  category_id: content_for(node, 'CATID'),
25
35
  description: content_for(node, 'CATDES'),
@@ -1,3 +1,3 @@
1
1
  module SportsSouth
2
- VERSION = '2.0.3'
2
+ VERSION = '2.0.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sports_south
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dale Campbell