Class: Lipseys::Catalog
Constant Summary collapse
- CHUNK_SIZE =
500- API_URL =
'https://www.lipseys.com/API/catalog.ashx'- ITEMTYPES =
%w(ACCESSORY FIREARM NFA OPTIC)
Class Method Summary collapse
Instance Method Summary collapse
- #all(&block) ⇒ Object
-
#initialize(options = {}) ⇒ Catalog
constructor
A new instance of Catalog.
Constructor Details
#initialize(options = {}) ⇒ Catalog
Returns a new instance of Catalog.
8 9 10 11 12 |
# File 'lib/lipseys/catalog.rb', line 8 def initialize( = {}) requires!(, :username, :password) = end |
Class Method Details
.all(options = {}, &block) ⇒ Object
14 15 16 17 |
# File 'lib/lipseys/catalog.rb', line 14 def self.all( = {}, &block) requires!(, :username, :password) new().all &block end |
Instance Method Details
#all(&block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/lipseys/catalog.rb', line 19 def all(&block) inventory_tempfile = stream_to_tempfile(Lipseys::Inventory::API_URL, ) catalog_tempfile = stream_to_tempfile(API_URL, ) inventory = Array.new # Let's get the inventory and toss 'er into an array Lipseys::Parser.parse(inventory_tempfile, 'Item') do |node| inventory.push({ item_identifier: content_for(node, 'ItemNo'), map_price: content_for(node, 'RetailMAP'), quantity: content_for(node, 'QtyOnHand'), price: content_for(node, 'Price') }) end Lipseys::Parser.parse(catalog_tempfile, 'Item') do |node| hash = map_hash(node) availability = inventory.select { |i| i[:item_identifier] == hash[:item_identifier] }.first if availability hash[:price] = availability[:price] hash[:quantity] = availability[:quantity] hash[:map_price] = availability[:map_price] end yield hash end inventory_tempfile.unlink catalog_tempfile.unlink true end |