Permalink
Browse files

Build inventory requests fill out SellerSku items if skus have been p…

…rovided
  • Loading branch information...
1 parent 189ecaa commit 72d550186dc1c46acc43a7f25a1a9941975e2a7d csaunders committed Apr 16, 2012
Showing with 41 additions and 9 deletions.
  1. +26 −7 lib/active_fulfillment/fulfillment/services/amazon_mws.rb
  2. +15 −2 test/unit/services/amazon_mws_test.rb
@@ -11,7 +11,7 @@ class AmazonMarketplaceWebService < Service
SIGNATURE_VERSION = 2
SIGNATURE_METHOD = "SHA256"
- VERSION = "2011-01-01"
+ VERSION = "2010-10-01"
SUCCESS, FAILURE, ERROR = 'Accepted', 'Failure', 'Error'
@@ -66,9 +66,17 @@ class AmazonMarketplaceWebService < Service
:sku => "Item.member.%d.SellerSKU",
:network_sku => "Item.member.%d.FulfillmentNetworkSKU",
:item_disposition => "Item.member.%d.OrderItemDisposition"
+ },
+ :list_inventory => {
+ :sku => "SellerSkus.member.%d"
}
}
+ ACTIONS = {
+ :outbound => "FulfillmentOutboundShipment",
+ :inventory => "FulfillmentInventory"
+ }
+
OPERATIONS = {
:outbound => {
:status => 'GetServiceStatus',
@@ -79,7 +87,7 @@ class AmazonMarketplaceWebService < Service
:inventory => {
:get => 'ListInventorySupply',
:list => 'ListInventorySupply',
- :list_next => 'ListInventorySupply'
+ :list_next => 'ListInventorySupplyByNextToken'
}
}
@@ -105,6 +113,10 @@ def initialize(options = {})
super
end
+ def seller_id=(seller_id)
+ @seller_id = seller_id
+ end
+
def endpoint
ENDPOINTS[@options[:endpoint] || :us]
end
@@ -160,11 +172,11 @@ def fetch_tracking_numbers(order_ids, options = {})
end
def commit(verb, service, op, params)
- uri = URI.parse("#{endpoint}/#{OPERATIONS[service][op]}/#{VERSION}")
+ uri = URI.parse("https://#{endpoint}/#{ACTIONS[service]}/#{VERSION}")
signature = sign(verb, uri, params)
query = build_query(params) + "&Signature=#{signature}"
headers = build_headers(query)
-
+
data = ssl_post(uri.to_s, query, headers)
response = parse_response(service, op, data)
Response.new(success?(response), message_from(response), response)
@@ -278,7 +290,7 @@ def sign(http_verb, uri, options)
string_to_sign += build_query(options)
# remove trailing newline created by encode64
- Base64.encode64(OpenSSL::HMAC.digest(SIGNATURE_METHOD, @options[:password], string_to_sign)).chomp
+ escape(Base64.encode64(OpenSSL::HMAC.digest(SIGNATURE_METHOD, @options[:password], string_to_sign)).chomp)
end
def md5_content(content)
@@ -304,6 +316,7 @@ def build_basic_api_query(options)
opts["Version"] = VERSION unless opts["Version"]
opts["SignatureMethod"] = "Hmac#{SIGNATURE_METHOD}" unless opts["SignatureMethod"]
opts["SignatureVersion"] = SIGNATURE_VERSION unless opts["SignatureVersion"]
+ opts["SellerId"] = @seller_id unless opts["SellerId"] || !@seller_id
opts
end
@@ -332,12 +345,18 @@ def build_get_current_fulfillment_orders_request(options = {})
def build_inventory_list_request(options = {})
start_time = options.delete(:start_time) || 1.day.ago
- response_group = options.delete(:start_time) || "Basic"
+ response_group = options.delete(:response_group) || "Basic"
params = {
:Action => OPERATIONS[:inventory][:list],
- :QueryStartDateTime => start_time.iso8601,
:ResponseGroup => response_group
}
+ if skus = options.delete(:skus)
+ skus.each_with_index do |sku, index|
+ params[LOOKUPS[:list_inventory][:sku] % (index + 1)] = sku
+ end
+ else
+ params[:QueryStartDateTime] = options.delete(:start_time) || 1.day.ago
+ end
build_basic_api_query(params.merge(options))
end
@@ -55,15 +55,28 @@ def test_build_basic_api_query
assert_equal AmazonMarketplaceWebService::VERSION, opts["Version"]
end
+ def test_build_inventory_list_request
+ skus = ["CITADELS", "INNOVATION", "JAIPUR"]
+ request_params = @service.build_inventory_list_request(:skus => skus)
+ keys = request_params.keys
+
+ assert keys.include?("SellerSkus.member.1")
+ assert keys.include?("SellerSkus.member.2")
+ assert keys.include?("SellerSkus.member.3")
+ assert_equal 'CITADELS', request_params['SellerSkus.member.1']
+ assert_equal 'INNOVATION', request_params['SellerSkus.member.2']
+ assert_equal 'JAIPUR', request_params["SellerSkus.member.3"]
+ end
+
def test_create_signature
service = AmazonMarketplaceWebService.new(:login => "0PExampleR2", :password => "sekrets")
- expected_signature = "39XxH6iKLysjjDmWZSkyr2z8iSxfECHBYE1Pd0Qqpwo="
+ expected_signature = "39XxH6iKLysjjDmWZSkyr2z8iSxfECHBYE1Pd0Qqpwo%3D"
options = {
"AWSAccessKeyId" => "0PExampleR2",
"Action" => "SubmitFeed",
"FeedType" => "_POST_INVENTORY_AVAILABILITY_DATA_",
"Marketplace" => "ATExampleER",
- "Merchant" => "A1ExampleE6",
+ "Merchant" => "A1ExampleE6",
"SignatureMethod" => "HmacSHA256",
"SignatureVersion" => "2",
"Timestamp" => "2009-08-20T01:10:27.607Z",

0 comments on commit 72d5501

Please sign in to comment.