blastramp 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- blastramp (0.0.1)
4
+ blastramp (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
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.find_inventory_counts_for_sku('1000-BLK-M')
14
+ inventory_counts = blastramp.inventory_counts.find('1000-BLK-M')
15
15
 
16
- If a warehouse parameter is given, will return a single warehouse inventory_count
17
- inventory_count = blastramp.inventory_counts.find_inventory_counts_for_sku('AAA-01-XX','0001')
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
@@ -1,5 +1,7 @@
1
1
  $LOAD_PATH << File.expand_path(File.join(*%w[ .. lib ]), File.dirname(__FILE__))
2
2
  require 'savon'
3
+ require 'ext'
4
+ require 'blastramp/inventory_count'
3
5
  require 'blastramp/inventory_count_query'
4
6
  require 'blastramp/session'
5
7
 
@@ -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 find_inventory_counts_for_sku(sku)
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
- # # Make sure we always have an array of handles even if the result only contains one
23
- # handles = [response[:query_results][:counts][:inventory_count]].flatten.reject(&:blank?)
24
- #
25
- # # Create partial InventoryCount entities
26
- # handles.collect do |handle|
27
- # inventory_count = build
28
- # inventory_count.persisted = true
29
- # inventory_count.whid = handle[:whid]
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Blastramp
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,6 @@
1
+ module ExtString
2
+ def snake_case
3
+ gsub(/\B[A-Z]/, '_\&').downcase
4
+ end
5
+ end
6
+ String.send(:include, ExtString)
@@ -10,14 +10,40 @@ describe Blastramp::InventoryCountQuery do
10
10
  end
11
11
  end
12
12
 
13
- describe "inventory_count_proxy" do
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.find_inventory_counts_for_sku('AAA-01-XX')
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
- <InventoryCountProxyResponse xmlns="http://chrome52/webservices/">
6
- <InventoryCountProxyResult>
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
- </InventoryCountProxyResult>
62
- </InventoryCountProxyResponse>
61
+ </InventoryCountQueryResult>
62
+ </InventoryCountQueryResponse>
63
63
  </soap:Body>
64
64
  </soap:Envelope>
@@ -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 requests over the network
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
- - 2
9
- version: 0.0.2
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