lipseys 1.0.1 → 2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ff799fab921f70ff5c91ed11e5596c148076dcb
4
- data.tar.gz: 7925f01de881e55a9fbd923e97506b7b664a48a8
3
+ metadata.gz: 3f9bd15130f7600c855bb9d9d333fd0ffa29976d
4
+ data.tar.gz: 32e12cf0871fd1d207224a1865e0c10d02df27db
5
5
  SHA512:
6
- metadata.gz: a9aad7150067c3cae4d633bce3fa034101e9a416d67109ab90ae5a4f1b3ec3cae4e811858e9b939e630b9d93612bcc049d7a59cad4cebe3e48827e263e2e7831
7
- data.tar.gz: 002b48c898a55357b3cd75a27a8c6bf2d483963d16dced28121389b5c097050f96dc5b2810a5e24b9ab909d1da2e69c4ef3762277bdba9d712ad13f4e6d0383e
6
+ metadata.gz: 1a8b7fa728e9d0089c4f9754a60a3fa757a1c6f5bb0182c83452a6adee3601a3c2f507c6a53575d6c8b2258180172433121c1f447c9b83b2f370ca2382ab03ef
7
+ data.tar.gz: 4f945e0f1070a9e92626e0d04bf0009874ffcc0a3abb4bd1af036e87d473acb48ca64222c831b1511f12cde7d91811d0a3411b38ef20136007c1718aa1796ac8
@@ -1,78 +1,17 @@
1
1
  module Lipseys
2
- # Each method will return an array of catalog items with the following fields:
3
- #
4
- # {
5
- # item_number: content_for(item, 'ItemNo'),
6
- # description_1: content_for(item, 'Desc1'),
7
- # description_2: content_for(item, 'Desc2'),
8
- # upc: content_for(item, 'UPC'),
9
- # manufacturer_model_number: content_for(item, 'MFGModelNo'),
10
- # msrp: content_for(item, 'MSRP'),
11
- # model: content_for(item, 'Model'),
12
- # caliber: content_for(item, 'Caliber'),
13
- # manufacturer: content_for(item, 'MFG'),
14
- # type: content_for(item, 'Type'),
15
- # action: content_for(item, 'Action'),
16
- # barrel: content_for(item, 'Barrel'),
17
- # capacity: content_for(item, 'Capacity'),
18
- # finish: content_for(item, 'Finish'),
19
- # length: content_for(item, 'Length'),
20
- # receiver: content_for(item, 'Receiver'),
21
- # safety: content_for(item, 'Safety'),
22
- # sights: content_for(item, 'Sights'),
23
- # stock_frame_grips: content_for(item, 'StockFrameGrips'),
24
- # magazine: content_for(item, 'Magazine'),
25
- # weight: content_for(item, 'Weight'),
26
- # image: "http://www.lipseys.net/images/#{content_for(item, 'Image')}",
27
- # chamber: content_for(item, 'Chamber'),
28
- # drilled_tapped: (content_for(item, 'DrilledTapped') == 'Y'),
29
- # rate_of_twist: content_for(item, 'RateOfTwist'),
30
- # item_type: content_for(item, 'ItemType'),
31
- # feature_1: content_for(item, 'Feature1'),
32
- # feature_2: content_for(item, 'Feature2'),
33
- # feature_3: content_for(item, 'Feature3'),
34
- # shipping_weight: content_for(item, 'ShippingWeight'),
35
- # bound_book: {
36
- # model: content_for(item, 'BoundBookModel'),
37
- # type: content_for(item, 'BoundBookType'),
38
- # manufacturer: content_for(item, 'BoundBookMFG'),
39
- # },
40
- # nfa: {
41
- # thread_pattern: content_for(item, 'NFAThreadPattern'),
42
- # attach_method: content_for(item, 'NFAAttachMethod'),
43
- # baffle: content_for(item, 'NFABaffle'),
44
- # can_disassemble: (content_for(item, 'NFACanDisassemble') == 'Y'),
45
- # construction: content_for(item, 'NFAConstruction'),
46
- # db_reduction: content_for(item, 'NFAdbReduction'),
47
- # diameter: content_for(item, 'NFADiameter'),
48
- # form_3_caliber: content_for(item, 'NFAForm3Caliber'),
49
- # },
50
- # optic: {
51
- # magnification: content_for(item, 'Magnification'),
52
- # maintube: content_for(item, 'Maintube'),
53
- # objective: content_for(item, 'Objective'),
54
- # adjustable_objective: (content_for(item, 'AdjustableObjective') == 'Y'),
55
- # optic_adjustments: content_for(item, 'OpticAdjustments'),
56
- # reticle: content_for(item, 'Reticle'),
57
- # illuminated_reticle: (content_for(item, 'IlluminatedReticle') == 'Y'),
58
- # }
59
- # }
60
2
  class Catalog < Base
61
3
 
62
4
  API_URL = 'https://www.lipseys.com/API/catalog.ashx'
63
5
 
64
6
  def initialize(options = {})
65
- requires!(options, :email, :password)
66
- @email = options[:email]
67
- @password = options[:password]
68
- end
7
+ requires!(options, :email, :pass)
69
8
 
70
- def self.all(options = {})
71
- new(options).all
9
+ @options = options
72
10
  end
73
11
 
74
- def self.all_as_chunks(size, options = {}, &block)
75
- new(options).all_as_chunks(size, &block)
12
+ def self.all(chunk_size = 15, options = {}, &block)
13
+ requires!(options, :email, :pass)
14
+ new(options).all(chunk_size, &block)
76
15
  end
77
16
 
78
17
  def self.accessories(options = {})
@@ -91,28 +30,37 @@ module Lipseys
91
30
  new(options).optics
92
31
  end
93
32
 
94
- def all
95
- tempfile = stream_to_tempfile(API_URL, default_params)
96
-
97
- items = Array.new
33
+ def all(chunk_size, &block)
34
+ chunker = Lipseys::Chunker.new(chunk_size)
35
+ tempfile = stream_to_tempfile(API_URL, @options)
36
+ inventory = Array.new
98
37
 
99
- Lipseys::Parser.parse(tempfile, 'Item') do |node|
100
- items.push(map_hash(node))
38
+ # Let's get the inventory and toss 'er into an array
39
+ Lipseys::Parser.parse(stream_to_tempfile(Lipseys::Inventory::API_URL, @options), 'Item') do |node|
40
+ inventory.push({
41
+ item_identifier: content_for(node, 'ItemNo'),
42
+ map_price: content_for(node, 'RetailMAP'),
43
+ quantity: content_for(node, 'QtyOnHand'),
44
+ price: content_for(node, 'Price')
45
+ })
101
46
  end
102
47
 
103
- items
104
- end
105
-
106
- def all_as_chunks(size, &block)
107
- chunker = Lipseys::Chunker.new(size)
108
- tempfile = stream_to_tempfile(API_URL, default_params)
109
-
110
48
  Lipseys::Parser.parse(tempfile, 'Item') do |node|
111
49
  if chunker.is_full?
112
50
  yield(chunker.chunk)
113
- chunker.reset
51
+
52
+ chunker.reset!
114
53
  else
115
- chunker.add(map_hash(node))
54
+ hash = map_hash(node)
55
+ availability = inventory.select { |i| i[:item_identifier] == hash[:item_identifier] }.first
56
+
57
+ if availability.present?
58
+ hash[:price] = availability[:price]
59
+ hash[:quantity] = availability[:quantity]
60
+ hash[:map_price] = availability[:map_price]
61
+
62
+ chunker.add(hash)
63
+ end
116
64
  end
117
65
  end
118
66
 
@@ -144,17 +92,10 @@ module Lipseys
144
92
 
145
93
  private
146
94
 
147
- def default_params
148
- {
149
- email: @email,
150
- pass: @password
151
- }
152
- end
153
-
154
95
  def get_items(item_type = nil)
155
- default_params[:itemtype] = item_type unless item_type.nil?
96
+ @options[:itemtype] = item_type unless item_type.nil?
156
97
 
157
- xml_doc = get_response_xml(API_URL, default_params)
98
+ xml_doc = get_response_xml(API_URL, @options)
158
99
 
159
100
  items = Array.new
160
101
 
@@ -167,59 +108,30 @@ module Lipseys
167
108
 
168
109
  def map_hash(node)
169
110
  {
170
- item_number: content_for(node, 'ItemNo'),
171
- description_1: content_for(node, 'Desc1'),
172
- description_2: content_for(node, 'Desc2'),
111
+ name: content_for(node, 'Model'),
173
112
  upc: content_for(node, 'UPC'),
174
- manufacturer_model_number: content_for(node, 'MFGModelNo'),
175
- msrp: content_for(node, 'MSRP'),
176
- model: content_for(node, 'Model'),
177
- caliber: content_for(node, 'Caliber'),
178
- manufacturer: content_for(node, 'MFG'),
179
- type: content_for(node, 'Type'),
180
- action: content_for(node, 'Action'),
181
- barrel: content_for(node, 'Barrel'),
182
- capacity: content_for(node, 'Capacity'),
183
- finish: content_for(node, 'Finish'),
184
- length: content_for(node, 'Length'),
185
- receiver: content_for(node, 'Receiver'),
186
- safety: content_for(node, 'Safety'),
187
- sights: content_for(node, 'Sights'),
188
- stock_frame_grips: content_for(node, 'StockFrameGrips'),
189
- magazine: content_for(node, 'Magazine'),
113
+ short_description: content_for(node, 'Desc1'),
114
+ long_description: "#{content_for(node, 'Desc1')} #{content_for(node, 'Desc2')}",
115
+ category: content_for(node, 'Type'),
116
+ price: nil,
190
117
  weight: content_for(node, 'Weight'),
191
- image: "http://www.lipseys.net/images/#{content_for(node, 'Image')}",
192
- chamber: content_for(node, 'Chamber'),
193
- drilled_tapped: (content_for(node, 'DrilledTapped') == 'Y'),
194
- rate_of_twist: content_for(node, 'RateOfTwist'),
195
- item_type: content_for(node, 'ItemType'),
196
- feature_1: content_for(node, 'Feature1'),
197
- feature_2: content_for(node, 'Feature2'),
198
- feature_3: content_for(node, 'Feature3'),
199
- shipping_weight: content_for(node, 'ShippingWeight'),
200
- bound_book: {
201
- model: content_for(node, 'BoundBookModel'),
202
- type: content_for(node, 'BoundBookType'),
203
- manufacturer: content_for(node, 'BoundBookMFG'),
204
- },
205
- nfa: {
206
- thread_pattern: content_for(node, 'NFAThreadPattern'),
207
- attach_method: content_for(node, 'NFAAttachMethod'),
208
- baffle: content_for(node, 'NFABaffle'),
209
- can_disassemble: (content_for(node, 'NFACanDisassemble') == 'Y'),
210
- construction: content_for(node, 'NFAConstruction'),
211
- db_reduction: content_for(node, 'NFAdbReduction'),
212
- diameter: content_for(node, 'NFADiameter'),
213
- form_3_caliber: content_for(node, 'NFAForm3Caliber'),
214
- },
215
- optic: {
216
- magnification: content_for(node, 'Magnification'),
217
- maintube: content_for(node, 'Maintube'),
218
- objective: content_for(node, 'Objective'),
219
- adjustable_objective: (content_for(node, 'AdjustableObjective') == 'Y'),
220
- optic_adjustments: content_for(node, 'OpticAdjustments'),
221
- reticle: content_for(node, 'Reticle'),
222
- illuminated_reticle: (content_for(node, 'IlluminatedReticle') == 'Y'),
118
+ marp: nil,
119
+ msrp: content_for(node, 'MSRP'),
120
+ item_identifier: content_for(node, 'ItemNo'),
121
+ brand: content_for(node, 'MFG'),
122
+ features: {
123
+ model: content_for(node, 'Model'),
124
+ caliber: content_for(node, 'Caliber'),
125
+ action: content_for(node, 'Action'),
126
+ barrel: content_for(node, 'Barrel'),
127
+ capacity: content_for(node, 'Capacity'),
128
+ finish: content_for(node, 'Finish'),
129
+ length: content_for(node, 'Length'),
130
+ receiver: content_for(node, 'Receiver'),
131
+ safety: content_for(node, 'Safety'),
132
+ sights: content_for(node, 'Sights'),
133
+ magazine: content_for(node, 'Magazine'),
134
+ chamber: content_for(node, 'Chamber')
223
135
  }
224
136
  }
225
137
  end
@@ -11,14 +11,14 @@ module Lipseys
11
11
  end
12
12
 
13
13
  def add(row)
14
- reset if is_full?
14
+ self.reset! if is_full?
15
15
 
16
16
  @chunk.push(row)
17
17
 
18
18
  @current_count += 1
19
19
  end
20
20
 
21
- def reset
21
+ def reset!
22
22
  @chunk.clear
23
23
  end
24
24
 
@@ -1,32 +1,16 @@
1
1
  module Lipseys
2
- # Each method will return an array of inventory items with the following fields:
3
- #
4
- # {
5
- # item_number: content_for(item, 'ItemNo'),
6
- # upc: content_for(item, 'UPC'),
7
- # manufacturer_model_number: content_for(item, 'MFGModelNo'),
8
- # quantity_on_hand: content_for(item, 'QtyOnHand'),
9
- # allocation: (content_for(item, 'Allocation') == 'Y'),
10
- # price: content_for(item, 'Price'),
11
- # on_sale: (content_for(item, 'OnSale') == 'Y'),
12
- # retail_map: content_for(item, 'RetailMAP')
13
- # }
14
2
  class Inventory < Base
15
3
 
16
4
  API_URL = 'https://www.lipseys.com/API/pricequantitycatalog.ashx'
17
5
 
18
6
  def initialize(options = {})
19
- requires!(options, :email, :password)
20
- @email = options[:email]
21
- @password = options[:password]
22
- end
7
+ requires!(options, :email, :pass)
23
8
 
24
- def self.all(options = {})
25
- new(options).all
9
+ @options = options
26
10
  end
27
11
 
28
- def self.all_as_chunks(size, options = {}, &block)
29
- new(options).all_as_chunks(size, &block)
12
+ def self.all(chunk_size = 15, options = {}, &block)
13
+ new(options).all(chunk_size, &block)
30
14
  end
31
15
 
32
16
  def self.accessories(options = {})
@@ -45,26 +29,14 @@ module Lipseys
45
29
  new(options).optics
46
30
  end
47
31
 
48
- def all
49
- tempfile = stream_to_tempfile(API_URL, default_params)
50
-
51
- items = Array.new
52
-
53
- Lipseys::Parser.parse(tempfile, 'Item') do |node|
54
- items.push(map_hash(node))
55
- end
56
-
57
- items
58
- end
59
-
60
- def all_as_chunks(size, &block)
32
+ def all(size, &block)
61
33
  chunker = Lipseys::Chunker.new(size)
62
- tempfile = stream_to_tempfile(API_URL, default_params)
34
+ tempfile = stream_to_tempfile(API_URL, @options)
63
35
 
64
36
  Lipseys::Parser.parse(tempfile, 'Item') do |node|
65
37
  if chunker.is_full?
66
38
  yield(chunker.chunk)
67
- chunker.reset
39
+ chunker.reset!
68
40
  else
69
41
  chunker.add(map_hash(node))
70
42
  end
@@ -98,17 +70,10 @@ module Lipseys
98
70
 
99
71
  private
100
72
 
101
- def default_params
102
- {
103
- email: @email,
104
- pass: @password
105
- }
106
- end
107
-
108
73
  def get_items(item_type = nil)
109
- default_params[:itemtype] = item_type unless item_type.nil?
74
+ @options[:itemtype] = item_type unless item_type.nil?
110
75
 
111
- xml_doc = get_response_xml(API_URL, default_params)
76
+ xml_doc = get_response_xml(API_URL, @options)
112
77
 
113
78
  items = Array.new
114
79
 
@@ -121,14 +86,9 @@ module Lipseys
121
86
 
122
87
  def map_hash(node)
123
88
  {
124
- item_number: content_for(node, 'ItemNo'),
125
- upc: content_for(node, 'UPC'),
126
- manufacturer_model_number: content_for(node, 'MFGModelNo'),
127
- quantity_on_hand: content_for(node, 'QtyOnHand'),
128
- allocation: (content_for(node, 'Allocation') == 'Y'),
129
- price: content_for(node, 'Price'),
130
- on_sale: (content_for(node, 'OnSale') == 'Y'),
131
- retail_map: content_for(node, 'RetailMAP')
89
+ item_identifier: content_for(node, 'ItemNo'),
90
+ quantity: content_for(node, 'QtyOnHand'),
91
+ price: content_for(node, 'Price')
132
92
  }
133
93
  end
134
94
 
@@ -1,3 +1,3 @@
1
1
  module Lipseys
2
- VERSION = "1.0.1"
2
+ VERSION = "2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lipseys
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: '2.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: 2017-04-06 00:00:00.000000000 Z
11
+ date: 2017-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  version: '0'
131
131
  requirements: []
132
132
  rubyforge_project:
133
- rubygems_version: 2.6.7
133
+ rubygems_version: 2.5.1
134
134
  signing_key:
135
135
  specification_version: 4
136
136
  summary: Ruby library for Lipsey's API.