class SportsSouth::Inventory
Constants
- API_URL
- ITEM_NODE_NAME
Public Class Methods
all(options = {})
click to toggle source
# File lib/sports_south/inventory.rb, line 22 def self.all(options = {}) requires!(options, :username, :password) if options[:last_updated].present? options[:last_updated] = options[:last_updated].strftime('%Y-%m-%dT%H:%M:00.00%:z') else options[:last_updated] = '1990-09-25T14:15:47-04:00' end options[:last_item] ||= '-1' new(options).all end
get(item_identifier, options = {})
click to toggle source
# File lib/sports_south/inventory.rb, line 36 def self.get(item_identifier, options = {}) requires!(options, :username, :password) new(options).get(item_identifier) end
get_quantity_file(options = {})
click to toggle source
# File lib/sports_south/inventory.rb, line 13 def self.get_quantity_file(options = {}) requires!(options, :username, :password) options[:last_updated] = '1990-09-25T14:15:47-04:00' options[:last_item] = '-1' new(options).get_quantity_file end
new(options = {})
click to toggle source
# File lib/sports_south/inventory.rb, line 7 def initialize(options = {}) requires!(options, :username, :password) @options = options end
quantity(options = {})
click to toggle source
# File lib/sports_south/inventory.rb, line 91 def self.quantity(options = {}) requires!(options, :username, :password) if options[:last_updated].present? options[:last_updated] = options[:last_updated].to_s("yyyy-MM-ddTHH:mm:sszzz") else options[:last_updated] = '1990-09-25T14:15:47-04:00' end options[:last_item] ||= '-1' new(options).all end
Public Instance Methods
all()
click to toggle source
# File lib/sports_south/inventory.rb, line 41 def all http, request = get_http_and_request(API_URL, '/IncrementalOnhandUpdate') request.set_form_data(form_params = form_params(@options).merge({ SinceDateTime: @options[:last_updated], LastItem: @options[:last_item].to_s })) items = [] tempfile = download_to_tempfile(http, request) tempfile.rewind Nokogiri::XML::Reader.from_io(tempfile).each do |reader| next unless reader.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT next unless reader.name == ITEM_NODE_NAME node = Nokogiri::XML.parse(reader.outer_xml) _map_hash = map_hash(node.css(ITEM_NODE_NAME)) items << _map_hash unless _map_hash.nil? end tempfile.close tempfile.unlink items end
get(item_identifier)
click to toggle source
# File lib/sports_south/inventory.rb, line 105 def get(item_identifier) http, request = get_http_and_request(API_URL, '/OnhandInquiry') request.set_form_data(form_params(@options).merge({ ItemNumber: item_identifier })) response = http.request(request) xml_doc = Nokogiri::XML(sanitize_response(response)) end
get_quantity_file()
click to toggle source
# File lib/sports_south/inventory.rb, line 71 def get_quantity_file tempfile = Tempfile.new http, request = get_http_and_request(API_URL, '/IncrementalOnhandUpdate') request.set_form_data(form_params = form_params(@options).merge({ SinceDateTime: @options[:last_updated], LastItem: @options[:last_item].to_s })) response = http.request(request) xml_doc = Nokogiri::XML(sanitize_response(response)) xml_doc.css('Onhand').map do |item| tempfile.puts("#{content_for(item, 'I')},#{content_for(item, 'Q')}") end tempfile.close tempfile.path end
Protected Instance Methods
map_hash(node)
click to toggle source
# File lib/sports_south/inventory.rb, line 116 def map_hash(node) { item_identifier: content_for(node, 'I'), quantity: content_for(node, 'Q').to_i, price: content_for(node, 'C') } end