blastramp 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +8 -3
- data/lib/blastramp.rb +2 -0
- data/lib/blastramp/inventory_count.rb +10 -0
- data/lib/blastramp/inventory_count_query.rb +22 -11
- data/lib/blastramp/session.rb +2 -1
- data/lib/blastramp/version.rb +1 -1
- data/lib/ext.rb +6 -0
- data/spec/blastramp/inventory_count_query_spec.rb +28 -2
- data/spec/fixtures/inventory_count_query/many.xml +4 -4
- data/spec/spec_helper.rb +1 -1
- metadata +4 -2
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -11,11 +11,16 @@ Usage example
|
|
11
11
|
blastramp = Blastramp::Session.new('vendor_code', 'vendor_access_key')
|
12
12
|
|
13
13
|
# Get array of inventory counts for a product SKU at all warehouses:
|
14
|
-
inventory_counts = blastramp.inventory_counts.
|
14
|
+
inventory_counts = blastramp.inventory_counts.find('1000-BLK-M')
|
15
15
|
|
16
|
-
|
17
|
-
inventory_count = blastramp.inventory_counts.
|
16
|
+
# Get a single inventory count for one warehouse id:
|
17
|
+
inventory_count = blastramp.inventory_counts.find_by_whid('1000-BLK-M','0001')
|
18
18
|
|
19
|
+
# Get # of available_to_sell units from an inventory_count
|
20
|
+
inventory_count.available_to_sell
|
21
|
+
inventory_count.backordered
|
22
|
+
inventory_count.total_shipped
|
23
|
+
|
19
24
|
# Create order:
|
20
25
|
order = Blastramp::OrderUpload.new
|
21
26
|
order.session = blastramp
|
data/lib/blastramp.rb
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
module Blastramp
|
2
|
+
class InventoryCount
|
3
|
+
def initialize(hash)
|
4
|
+
hash.each do |k,v|
|
5
|
+
self.instance_variable_set("@#{k}", v) ## create and initialize an instance variable for this key/value pair
|
6
|
+
self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")}) ## create the getter that returns the instance variable
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -6,8 +6,15 @@ module Blastramp
|
|
6
6
|
def initialize(session)
|
7
7
|
@session = session
|
8
8
|
end
|
9
|
+
|
10
|
+
# Returns a new, unpersisted Blastramp::InventoryCount
|
11
|
+
def build(values = {})
|
12
|
+
inventory_count = Blastramp::InventoryCount.new(values)
|
13
|
+
# inventory_count.session = session
|
14
|
+
inventory_count
|
15
|
+
end
|
9
16
|
|
10
|
-
def
|
17
|
+
def find(sku)
|
11
18
|
# Get a list of InventoryCounts from Blastramp
|
12
19
|
response = session.request 'InventoryCountQuery' do
|
13
20
|
http.headers["SOAPAction"] = "http://chrome52/webservices/InventoryCountQuery"
|
@@ -19,18 +26,22 @@ module Blastramp
|
|
19
26
|
}
|
20
27
|
end
|
21
28
|
|
22
|
-
#
|
23
|
-
|
24
|
-
|
25
|
-
#
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
# inventory_count
|
31
|
-
# end
|
29
|
+
# Make sure we always have an array of handles even if the result only contains one
|
30
|
+
handles = [response[:query_results][:counts][:inventory_count]].flatten.reject(&:blank?)
|
31
|
+
|
32
|
+
# Create partial InventoryCount entities
|
33
|
+
handles.collect do |handle|
|
34
|
+
inventory_count = build(handle)
|
35
|
+
inventory_count
|
36
|
+
end
|
32
37
|
|
33
38
|
end
|
39
|
+
|
40
|
+
def find_by_whid(sku, whid)
|
41
|
+
counts = self.find(sku)
|
42
|
+
counts = counts.select{|i| i.whid == whid}
|
43
|
+
count = counts[0]
|
44
|
+
end
|
34
45
|
|
35
46
|
end
|
36
47
|
end
|
data/lib/blastramp/session.rb
CHANGED
@@ -25,9 +25,10 @@ module Blastramp
|
|
25
25
|
def request(action, &block)
|
26
26
|
response = client.request :soap, action, &block
|
27
27
|
response_hash = response.to_hash
|
28
|
-
|
28
|
+
action = action.snake_case
|
29
29
|
response_key = "#{action}_response".intern
|
30
30
|
result_key = "#{action}_result".intern
|
31
|
+
|
31
32
|
if response_hash[response_key] && response_hash[response_key][result_key]
|
32
33
|
response_hash[response_key][result_key]
|
33
34
|
else
|
data/lib/blastramp/version.rb
CHANGED
data/lib/ext.rb
ADDED
@@ -10,14 +10,40 @@ describe Blastramp::InventoryCountQuery do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
describe "
|
13
|
+
describe "inventory_count_query" do
|
14
14
|
it "uses InventoryCountQuery on API" do
|
15
15
|
savon.expects('InventoryCountQuery').with(
|
16
16
|
'VendorCode' => 'ABC',
|
17
17
|
'VendorAccessKey' => 'TWX45IX2R9G35394',
|
18
18
|
'Sku' => 'AAA-01-XX').returns(:many)
|
19
|
-
subject.
|
19
|
+
subject.find('AAA-01-XX')
|
20
20
|
end
|
21
|
+
|
22
|
+
context "when many InventoryCounts exist" do
|
23
|
+
before :each do
|
24
|
+
savon.stubs('InventoryCountQuery').returns(:many)
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:results) { subject.find('AAA-01-XX') }
|
28
|
+
|
29
|
+
it "returns an InventoryCount object for each result" do
|
30
|
+
results.size.should == 2
|
31
|
+
results.all? { |result| result.should be_instance_of(Blastramp::InventoryCount) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when one InventoryCount is requested" do
|
36
|
+
before :each do
|
37
|
+
savon.stubs('InventoryCountQuery').returns(:many)
|
38
|
+
end
|
39
|
+
|
40
|
+
let(:result) { subject.find_by_whid('AAA-01-XX','0001') }
|
41
|
+
|
42
|
+
it "returns a single InventoryCount object" do
|
43
|
+
result.should be_instance_of(Blastramp::InventoryCount)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
21
47
|
end
|
22
48
|
|
23
49
|
end
|
@@ -2,8 +2,8 @@
|
|
2
2
|
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
3
3
|
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
4
4
|
<soap:Body>
|
5
|
-
<
|
6
|
-
<
|
5
|
+
<InventoryCountQueryResponse xmlns="http://chrome52/webservices/">
|
6
|
+
<InventoryCountQueryResult>
|
7
7
|
<Result>SUCCESS</Result>
|
8
8
|
<ErrorDesc></ErrorDesc>
|
9
9
|
<ErrorNumber>0</ErrorNumber>
|
@@ -58,7 +58,7 @@ xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
|
58
58
|
</InventoryCount>
|
59
59
|
</Counts>
|
60
60
|
</QueryResults>
|
61
|
-
</
|
62
|
-
</
|
61
|
+
</InventoryCountQueryResult>
|
62
|
+
</InventoryCountQueryResponse>
|
63
63
|
</soap:Body>
|
64
64
|
</soap:Envelope>
|
data/spec/spec_helper.rb
CHANGED
@@ -7,7 +7,7 @@ RSpec.configure do |config|
|
|
7
7
|
config.include Savon::Spec::Macros
|
8
8
|
|
9
9
|
config.before :each do
|
10
|
-
# Ensure we don't actually send
|
10
|
+
# Ensure we don't actually send finds over the network
|
11
11
|
HTTPI.expects(:get).never
|
12
12
|
HTTPI.expects(:post).never
|
13
13
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- cnantais
|
@@ -97,9 +97,11 @@ files:
|
|
97
97
|
- Rakefile
|
98
98
|
- blastramp.gemspec
|
99
99
|
- lib/blastramp.rb
|
100
|
+
- lib/blastramp/inventory_count.rb
|
100
101
|
- lib/blastramp/inventory_count_query.rb
|
101
102
|
- lib/blastramp/session.rb
|
102
103
|
- lib/blastramp/version.rb
|
104
|
+
- lib/ext.rb
|
103
105
|
- spec/blastramp/inventory_count_query_spec.rb
|
104
106
|
- spec/blastramp/session_spec.rb
|
105
107
|
- spec/fixtures/inventory_count_query/many.xml
|