Class: Lipseys::Inventory

Inherits:
Base
  • Object
show all
Defined in:
lib/lipseys/inventory.rb

Constant Summary collapse

API_URL =
'https://www.lipseys.com/API/pricequantitycatalog.ashx'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Inventory

Returns a new instance of Inventory.



6
7
8
9
10
# File 'lib/lipseys/inventory.rb', line 6

def initialize(options = {})
  requires!(options, :username, :password)

  @options = options
end

Class Method Details

.all(options = {}, &block) ⇒ Object



12
13
14
# File 'lib/lipseys/inventory.rb', line 12

def self.all(options = {}, &block)
  new(options).all &block
end

.get_quantity_file(options = {}) ⇒ Object



20
21
22
# File 'lib/lipseys/inventory.rb', line 20

def self.get_quantity_file(options = {})
  new(options).get_quantity_file
end

.quantity(options = {}, &block) ⇒ Object



16
17
18
# File 'lib/lipseys/inventory.rb', line 16

def self.quantity(options = {}, &block)
  new(options).all &block
end

Instance Method Details

#all(&block) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/lipseys/inventory.rb', line 24

def all(&block)
  tempfile = stream_to_tempfile(API_URL, @options)

  Lipseys::Parser.parse(tempfile, 'Item') do |node|
    yield map_hash(node)
  end

  tempfile.unlink
end

#get_quantity_fileObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/lipseys/inventory.rb', line 34

def get_quantity_file
  quantity_tempfile = stream_to_tempfile(API_URL, @options)
  tempfile          = Tempfile.new

  Lipseys::Parser.parse(quantity_tempfile, 'Item') do |node|
    tempfile.puts("#{content_for(node, 'ItemNo')},#{content_for(node, 'QtyOnHand')}")
  end

  quantity_tempfile.unlink
  tempfile.close

  tempfile.path
end