lib/lipseys/inventory.rb in lipseys-5.0.1 vs lib/lipseys/inventory.rb in lipseys-6.0.0

- old
+ new

@@ -1,63 +1,31 @@ module Lipseys class Inventory < Base - API_URL = 'http://184.188.80.195/API/pricequantitycatalog.ashx' - def initialize(options = {}) requires!(options, :username, :password) - @options = options + @client = Lipseys::Client.new(username: options[:username], password: options[:password]) end def self.all(options = {}) - new(options).all - end + requires!(options, :username, :password) - def self.quantity(options = {}) new(options).all end + class << self; alias_method :quantity, :all; end - def self.get_quantity_file(options = {}) - new(options).get_quantity_file - end - 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 + @client.items.pricing_quantity_feed[:data][:items].map { |item| map_hash(item) } end - 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 - private - def map_hash(node) + def map_hash(item) { - item_identifier: content_for(node, 'ItemNo'), - quantity: content_for(node, 'QtyOnHand'), - price: content_for(node, 'Price') + item_identifier: item[:itemNumber], + quantity: item[:quantity], + price: item[:price], } end end end