class Scrub::SCClient
Public Class Methods
new(server, username, password)
click to toggle source
# File lib/scrubdeku.rb, line 11 def initialize(server, username, password) @generalClient = self.createClient(server, "/scservice.asmx?WSDL", username, password) @inventoryClient = self.createClient(server, "/SCInventoryService.asmx?wsdl", username, password) end
Public Instance Methods
createClient(server, location, username, password)
click to toggle source
# File lib/scrubdeku.rb, line 16 def createClient(server, location, username, password) return Savon.client(wsdl: "#{server}#{location}", soap_header: {'AuthHeader' => {:@xmlns => "http://api.sellercloud.com/", 'UserName' => username, 'Password' => password}}, env_namespace: :soap, pretty_print_xml: true) end
generalRaw(call, messageIn)
click to toggle source
Testing/debugging calls
# File lib/scrubdeku.rb, line 110 def generalRaw(call, messageIn) @generalClient.call(call, message: messageIn).to_hash end
getAllWarehouseSkuList(warehouseArray)
click to toggle source
# File lib/scrubdeku.rb, line 57 def getAllWarehouseSkuList(warehouseArray) inventoryArray = [] warehouseArray.each do |warehouse| inventoryArray = inventoryArray | self.getWarehouseInventoryList(warehouse) end return inventoryArray end
getAllWarehousesInventoryTable(skuTable, threads)
click to toggle source
# File lib/scrubdeku.rb, line 73 def getAllWarehousesInventoryTable(skuTable, threads) inventory = {} skus = skuTable.in_groups(threads) lock = Mutex.new threadList = [] (0...threads).each do |i| threadList << Thread.new do threadTable = {} skus[i].each do |sku| puts "Getting data for #{sku}" response = self.getSkuInventoryAllWarehouses(sku) threadTable[sku] = response end lock.synchronize do inventory.merge!(threadTable) end end end threadList.each{|thr| thr.join} return inventory end
getInventoryByWarehouse(warehouse, sku)
click to toggle source
# File lib/scrubdeku.rb, line 95 def getInventoryByWarehouse(warehouse, sku) self.inventoryRaw(:get_inventory, {'ProductID' => sku, 'WarehouseID' => warehouse}) end
getProductNameFromSku(sku)
click to toggle source
# File lib/scrubdeku.rb, line 99 def getProductNameFromSku(sku) begin self.generalRaw(:get_product_info, {'id' => sku})[:get_product_info_response][:get_product_info_result][:product_name] rescue Net::OpenTimeout, Errno::ECONNRESET, Savon::HTTPError, Savon::SOAPFault retry rescue NoMethodError "" end end
getShippedOrdersByNum(startDate, endDate=startDate, clientID)
click to toggle source
# File lib/scrubdeku.rb, line 126 def getShippedOrdersByNum(startDate, endDate=startDate, clientID) orders = [] self.generalRaw(:get_shipped_orders_by_company_and_date_range, {'StartDate' => startDate, 'EndDate' => endDate, 'ClientID' => clientID})[:get_shipped_orders_by_company_and_date_range_response][:get_shipped_orders_by_company_and_date_range_result][:diffgram][:document_element][:shipped_orders].each do |order| orders.push(order[:order_id]) end return orders end
getSkuInventoryAllWarehouses(sku)
click to toggle source
# File lib/scrubdeku.rb, line 65 def getSkuInventoryAllWarehouses(sku) begin response = self.generalRaw(:get_product_inventory_for_all_warehouses, {'ProductID' => sku})[:get_product_inventory_for_all_warehouses_response][:get_product_inventory_for_all_warehouses_result][:get_product_inventory_for_all_warehouses_response_type] rescue Net::OpenTimeout, Errno::ECONNRESET retry end end
getWarehouseInventory(warehouseid, page)
click to toggle source
# File lib/scrubdeku.rb, line 46 def getWarehouseInventory(warehouseid, page) begin response = @inventoryClient.call(:product_warehouse_inventory_get, message: {'WarehouseID' => warehouseid, 'pageNumber' => page}).to_hash[:product_warehouse_inventory_get_response][:product_warehouse_inventory_get_result][:string] rescue NoMethodError [] rescue Net::OpenTimeout, Errno::ECONNRESET puts "Retrying..." retry end end
getWarehouseInventoryList(warehouseid)
click to toggle source
# File lib/scrubdeku.rb, line 28 def getWarehouseInventoryList(warehouseid) warehouseInventory = [] page = 1 pageLimitReached = false while pageLimitReached == false puts "Getting page... #{page.to_s}" response = self.getWarehouseInventory(warehouseid, page) if response.size > 0 warehouseInventory += response page += 1 elsif response.size == 0 pageLimitReached = true end end puts "Compacting #{warehouseInventory.size} records..." return warehouseInventory.uniq end
invOperations()
click to toggle source
# File lib/scrubdeku.rb, line 122 def invOperations @inventoryClient.operations end
inventoryRaw(call, messageIn)
click to toggle source
# File lib/scrubdeku.rb, line 114 def inventoryRaw(call, messageIn) @inventoryClient.call(call, message: messageIn).to_hash end
operations()
click to toggle source
# File lib/scrubdeku.rb, line 118 def operations @generalClient.operations end
order_data(orderNumber)
click to toggle source
# File lib/scrubdeku.rb, line 20 def order_data(orderNumber) begin @generalClient.call(:orders_get_data, message: {'orderId' => orderNumber}).to_hash rescue Net::OpenTimeout retry end end