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 = {}) ⇒ Object



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

def self.all(options = {})
  new(options).all
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 = {}) ⇒ Object



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

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

Instance Method Details

#allObject



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

def all
  items    = []
  tempfile = stream_to_tempfile(API_URL, @options)

  Lipseys::Parser.parse(tempfile, 'Item') do |node|
    _map_hash = map_hash(node)

    items << _map_hash unless _map_hash.nil?
  end

  tempfile.unlink

  items
end

#get_quantity_fileObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/lipseys/inventory.rb', line 39

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