scrubdeku 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/SCRuB.rb +137 -0
  3. metadata +59 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9031f253f3fcd999626e4867e9da5771a72becaf
4
+ data.tar.gz: 8b62d47fbe3bbe2617071e56424e60efba02b08a
5
+ SHA512:
6
+ metadata.gz: 26b1ab21441af454099484864dd37d986255849569e885b64cc95eac7673765dc61d3cae51c0f972c0c513f78097f80fc1aca1b1989d9c258376358da66ac0d6
7
+ data.tar.gz: 7005b92b768e6d982ef0c50ffbb7fbd24353970faa37d9e57793aba94a53f2b0eb303414f41e3867aeb50144c4daa8e76dc803673af3ba31a2ac73c3e8b58b1b
@@ -0,0 +1,137 @@
1
+ require 'savon'
2
+ require 'thread'
3
+
4
+ class Array; def in_groups(num_groups)
5
+ return [] if num_groups == 0
6
+ slice_size = (self.size/Float(num_groups)).ceil
7
+ groups = self.each_slice(slice_size).to_a
8
+ end; end
9
+ module Scrub
10
+ class SCClient
11
+ def initialize(server, username, password)
12
+ @generalClient = self.createClient(server, "/scservice.asmx?WSDL", username, password)
13
+ @inventoryClient = self.createClient(server, "/SCInventoryService.asmx?wsdl", username, password)
14
+ end
15
+
16
+ def createClient(server, location, username, password)
17
+ 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)
18
+ end
19
+
20
+ def order_data(orderNumber)
21
+ @generalClient.call(:orders_get_data, message: {'orderId' => orderNumber}).to_hash
22
+ end
23
+
24
+ def getWarehouseInventoryList(warehouseid)
25
+ warehouseInventory = []
26
+ page = 1
27
+ pageLimitReached = false
28
+ while pageLimitReached == false
29
+ puts "Getting page... #{page.to_s}"
30
+ response = self.getWarehouseInventory(warehouseid, page)
31
+ if response.size > 0
32
+ warehouseInventory += response
33
+ page += 1
34
+ elsif response.size == 0
35
+ pageLimitReached = true
36
+ end
37
+ end
38
+ puts "Compacting #{warehouseInventory.size} records..."
39
+ return warehouseInventory.uniq
40
+ end
41
+
42
+ def getWarehouseInventory(warehouseid, page)
43
+ begin
44
+ 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]
45
+ rescue NoMethodError
46
+ []
47
+ rescue
48
+ puts "Retrying..."
49
+ retry
50
+ end
51
+ end
52
+
53
+ def getAllWarehouseSkuList(warehouseArray)
54
+ inventoryArray = []
55
+ warehouseArray.each do |warehouse|
56
+ inventoryArray = inventoryArray | self.getWarehouseInventoryList(warehouse)
57
+ end
58
+ return inventoryArray
59
+ end
60
+
61
+ def getSkuInventoryAllWarehouses(sku)
62
+ begin
63
+ 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]
64
+ rescue Net::OpenTimeout
65
+ retry
66
+ end
67
+ end
68
+
69
+ def getAllWarehousesInventoryTable(skuTable, threads)
70
+ inventory = {}
71
+ skus = skuTable.in_groups(threads)
72
+ lock = Mutex.new
73
+ (0...threads).each do |i|
74
+ Thread.new do
75
+ threadTable = {}
76
+ skus[i].each do |sku|
77
+ puts "Getting data for #{sku}"
78
+ response = self.getSkuInventoryAllWarehouses(sku)
79
+ threadTable[sku] = response
80
+ end
81
+ lock.synchronize do
82
+ inventory.merge!(threadTable)
83
+ end
84
+ end
85
+ end
86
+ return inventory
87
+ end
88
+
89
+ def getInventoryByWarehouse(warehouse, sku)
90
+ self.generalRaw(:get_inventory, {'ProductID' => sku, 'WarehouseID' => warehouse})
91
+ end
92
+
93
+ #Testing/debugging calls
94
+ def generalRaw(call, messageIn)
95
+ @generalClient.call(call, message: messageIn).to_hash
96
+ end
97
+
98
+ def inventoryRaw(call, messageIn)
99
+ @inventoryClient.call(call, message: messageIn).to_hash
100
+ end
101
+
102
+ def operations
103
+ @generalClient.operations
104
+ end
105
+
106
+ def invOperations
107
+ @inventoryClient.operations
108
+ end
109
+ end
110
+
111
+ class Order
112
+ def initialize(order_data)
113
+ @data = order_data
114
+ end
115
+
116
+ def products
117
+ productTable = {}
118
+ @data[:orders_get_data_response][:orders_get_data_result][:order][:items][:order_item].each do |item|
119
+ productTable[item[:product_id]] = {"qty" => item[:qty], "description" => item[:display_name]}
120
+ end
121
+ return productTable
122
+ end
123
+
124
+ def kit_listing
125
+ productTable = {}
126
+ @data[:orders_get_data_response][:orders_get_data_result][:order][:items][:order_item].each do |item|
127
+ buildout = {}
128
+ puts item[:bundle_items][:order_bundle_item]
129
+ item[:bundle_items][:order_bundle_item].each do |bundleItem|
130
+ buildout.merge!("#{bundleItem[:product_id]}" => {'qtyEach' => bundleItem[:qty], 'qtyTotal' => bundleItem[:total_qty]})
131
+ end
132
+ productTable[item[:product_id]] = {"qty" => item[:qty], "description" => item[:display_name], 'components' => buildout}
133
+ end
134
+ return productTable
135
+ end
136
+ end
137
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scrubdeku
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Harold Schreckengost
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: savon
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Simplifies interaction with the SellerCloud SOAP API to enable faster
28
+ development of integrations
29
+ email: harold@haroldmschreckengost.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/SCRuB.rb
35
+ homepage: http://rubygems.org/gems/hola
36
+ licenses:
37
+ - MIT
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 2.6.8
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: A gem used to work with the SellerCloud SOAP API
59
+ test_files: []