sports_south 3.0.2 → 3.0.3

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: 7d132005031036050cb4e55d76aa4455d519fd69
4
- data.tar.gz: 946d58824e49f0e1cce45a0dacc8353130bc91b4
2
+ SHA256:
3
+ metadata.gz: b736895ad6b25eaba7670b07b9c656540af38f4f10f9dd1e33a98a4b6a0a53a4
4
+ data.tar.gz: fa5df6f96b4e6dcda10e5d15e14a2aaa14413d4987d951dad85a399e3e89bb98
5
5
  SHA512:
6
- metadata.gz: b009cb4927ed59d0ca25afd0e5a74b7ae475f4438161b7d7ade10aec49a6fa583690cb80a4cda0031f60d29c6c16ab90c6b980bd828ce6dd9ccd31f214e1db54
7
- data.tar.gz: e7878d0042ed306f8fdc67b10cbcb8c2b6d1c9dc47f6eeb5473d9534aceca9a55e3d2bb0902b241bf1dfe28bfb35c11e9de05303975dfd400baab0940061b8cc
6
+ metadata.gz: d1faa1e1fe88d5cd8a5570c09f358c025b9e9fc53bf77c94d19c22d2157dd63f0ef3d14398de0871fafd3a6de2f7bb07d2d41c616546fa285ecda70a60289add
7
+ data.tar.gz: d2bb33af61ab8f14ad44b4aa121105f45f5be2a4c84ac6a590c5073a6845a725c811440bbff33a3d8e2edbf92f462ee7c26393ffcb4b225649b6c49b1bef3b2f
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3.1
1
+ 2.3.7
data/lib/sports_south.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  require 'sports_south/version'
2
2
 
3
+ require 'cgi'
3
4
  require 'json'
4
5
  require 'net/http'
5
6
  require 'nokogiri'
7
+ require 'tempfile'
6
8
 
7
9
  require 'sports_south/base'
8
10
  require 'sports_south/brand'
@@ -1,5 +1,3 @@
1
- require 'cgi'
2
-
3
1
  module SportsSouth
4
2
  # Holds methods common to all classes.
5
3
  class Base
@@ -50,10 +48,12 @@ module SportsSouth
50
48
  # http, request = get_http_and_request(<api_url>, <endpoint>)
51
49
  def self.get_http_and_request(api_url, endpoint)
52
50
  uri = URI([api_url, endpoint].join)
51
+
53
52
  http = Net::HTTP.new(uri.host, uri.port)
54
53
  http.read_timeout = TIMEOUT
54
+
55
55
  request = Net::HTTP::Post.new(uri.request_uri)
56
- request['User-Agent'] = USER_AGENT
56
+ request['User-Agent'] = USER_AGENT
57
57
  request['Content-Type'] = CONTENT_TYPE
58
58
 
59
59
  return http, request
@@ -72,5 +72,34 @@ module SportsSouth
72
72
  end
73
73
  def sanitize_response(*args); self.class.sanitize_response(*args); end
74
74
 
75
+ def download_to_tempfile(http, request)
76
+ preformatted_tempfile = Tempfile.new(['preformatted-', '.txt'])
77
+
78
+ # Stream the response to disk.
79
+ # This file is not yet valid XML (the angle brackets are escaped).
80
+ http.request(request) do |response|
81
+ File.open(preformatted_tempfile, 'w') do |file|
82
+ response.read_body do |chunk|
83
+ file.write(chunk.force_encoding('UTF-8'))
84
+ end
85
+ end
86
+ end
87
+ preformatted_tempfile.close
88
+
89
+ # Now we need to read the file line-by-line and unescape the angle brackets.
90
+ # The new (properly formatted) XML will be in a secondary tempfile.
91
+ converted_tempfile = Tempfile.new(['formated-', '.xml'])
92
+
93
+ File.open(preformatted_tempfile, 'r') do |file|
94
+ file.each_line do |line|
95
+ converted_tempfile.puts CGI.unescapeHTML(line)
96
+ end
97
+ end
98
+
99
+ # Return the (still opened) tempfile
100
+ # Since it's sill open you may need to '#rewind' it first before usage
101
+ return converted_tempfile
102
+ end
103
+
75
104
  end
76
105
  end
@@ -2,6 +2,7 @@ module SportsSouth
2
2
  class Catalog < Base
3
3
 
4
4
  API_URL = 'http://webservices.theshootingwarehouse.com/smart/inventory.asmx'
5
+ ITEM_NODE_NAME = 'Table'
5
6
 
6
7
  CATALOG_CODES = {
7
8
  'S' => :special,
@@ -62,13 +63,22 @@ module SportsSouth
62
63
  LastUpdate: @options[:last_updated],
63
64
  LastItem: @options[:last_item].to_s
64
65
  }))
66
+
67
+ tempfile = download_to_tempfile(http, request)
68
+ tempfile.rewind
65
69
 
66
- response = http.request(request)
67
- xml_doc = Nokogiri::XML(sanitize_response(response))
70
+ Nokogiri::XML::Reader.from_io(tempfile).each do |reader|
71
+ next unless reader.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT
72
+ next unless reader.name == ITEM_NODE_NAME
73
+
74
+ node = Nokogiri::XML.parse(reader.outer_xml)
68
75
 
69
- xml_doc.css('Table').map do |item|
70
- yield(map_hash(item, @options[:full_product]))
76
+ yield map_hash(node.css('Table'), @options[:full_product])
71
77
  end
78
+
79
+ tempfile.close
80
+ tempfile.unlink
81
+ true
72
82
  end
73
83
 
74
84
  def get_description(item_number)
@@ -101,27 +111,18 @@ module SportsSouth
101
111
  caliber = features[:gauge]
102
112
  end
103
113
 
104
- if features[:action]
105
- action = features[:action]
106
- end
107
-
108
- if full_product
109
- long_description = self.get_description(content_for(node, 'ITEMNO'))
110
- end
111
-
112
- if features.respond_to?(:[]=)
113
- features[:series] = series
114
- end
114
+ action = features[:action] if features[:action]
115
+ features[:series] = series if features.respond_to?(:[]=)
115
116
 
116
117
  {
117
- name: "#{model} #{series} #{mfg_number}".gsub(/\s+/, ' ').rstrip,
118
+ name: "#{model} #{series} #{mfg_number}".gsub(/\s+/, ' ').strip,
118
119
  model: model,
119
120
  upc: content_for(node, 'ITUPC').rjust(12, "0"),
120
121
  item_identifier: content_for(node, 'ITEMNO'),
121
122
  quantity: content_for(node, 'QTYOH').to_i,
122
123
  price: content_for(node, 'CPRC'),
123
124
  short_description: content_for(node, 'SHDESC'),
124
- long_description: long_description,
125
+ long_description: (full_product ? get_description(content_for(node, 'ITEMNO')) : nil),
125
126
  category: category[:description],
126
127
  product_type: ITEM_TYPES[content_for(node, 'ITYPE')],
127
128
  mfg_number: mfg_number,
@@ -1,3 +1,3 @@
1
1
  module SportsSouth
2
- VERSION = '3.0.2'.freeze
2
+ VERSION = '3.0.3'.freeze
3
3
  end
data/sports_south.gemspec CHANGED
@@ -4,8 +4,6 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'sports_south/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.required_ruby_version = '~> 2.0'
8
-
9
7
  spec.name = "sports_south"
10
8
  spec.version = SportsSouth::VERSION
11
9
  spec.authors = ["Dale Campbell"]
@@ -22,8 +20,8 @@ Gem::Specification.new do |spec|
22
20
 
23
21
  spec.add_dependency "nokogiri", "~> 1.6"
24
22
 
25
- spec.add_development_dependency "bundler", "~> 1.12"
26
23
  spec.add_development_dependency "activesupport", "~> 5"
24
+ spec.add_development_dependency "bundler", "~> 1.12"
27
25
  spec.add_development_dependency "net-http-spy", "~> 0.2"
28
26
  spec.add_development_dependency "rake", "~> 10.0"
29
27
  spec.add_development_dependency "rspec", "~> 3.3"
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.2
4
+ version: 3.0.3
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-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -25,33 +25,33 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
28
+ name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.12'
33
+ version: '5'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.12'
40
+ version: '5'
41
41
  - !ruby/object:Gem::Dependency
42
- name: activesupport
42
+ name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '5'
47
+ version: '1.12'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '5'
54
+ version: '1.12'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: net-http-spy
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -119,7 +119,6 @@ files:
119
119
  - ".rspec"
120
120
  - ".ruby-gemset"
121
121
  - ".ruby-version"
122
- - ".travis.yml"
123
122
  - Gemfile
124
123
  - LICENSE.txt
125
124
  - README.md
@@ -150,9 +149,9 @@ require_paths:
150
149
  - lib
151
150
  required_ruby_version: !ruby/object:Gem::Requirement
152
151
  requirements:
153
- - - "~>"
152
+ - - ">="
154
153
  - !ruby/object:Gem::Version
155
- version: '2.0'
154
+ version: '0'
156
155
  required_rubygems_version: !ruby/object:Gem::Requirement
157
156
  requirements:
158
157
  - - ">="
@@ -160,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
159
  version: '0'
161
160
  requirements: []
162
161
  rubyforge_project:
163
- rubygems_version: 2.6.12
162
+ rubygems_version: 2.7.7
164
163
  signing_key:
165
164
  specification_version: 4
166
165
  summary: Sports South API Ruby library.
data/.travis.yml DELETED
@@ -1,4 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.2.0
4
- before_install: gem install bundler -v 1.10.6