diff --git a/README.markdown b/README.markdown index c7e17ee..f5e4650 100644 --- a/README.markdown +++ b/README.markdown @@ -79,6 +79,28 @@ API This object can be used to access all API services. Below are examples on how to make the different requests that are available so far. Refer to the [Amazon MWS Reference Docs](https://developer.amazonservices.com/) for available fields for each request. +### Products API + +* ListMatchingProducts - Gets a list of products and their attributes, based on a search query + `@mws.products.list_matching_products query: 'Habermaas'` + + `:query` receive any string + `:query_context_id` receive any of the values listed [here](http://docs.developer.amazonservices.com/en_US/products/Products_QueryContextIDs.html) + + +* GetMatchingProduct - Gets a list of products and their attributes, based on a list of ASIN values. + `@mws.products.get_matching_product asin_list: "asincode"` + + `:asin_list` can be an array to retrieve multiple products + + +* GetMatchingProductForId - Gets a list of products and their attributes, based on a list of ASIN, GCID, SellerSKU, UPC, EAN, ISBN, and JAN values + + `@mws.products.get_matching_product_for_id id_list: "B0012KCLIG", id_type: "ASIN"` + + `:id_list` can be an array to retrieve multiple products + `:id_type` can be any of the following ASIN, GCID, SellerSKU, UPC, EAN, ISBN, and JAN + ### Orders API * ListOrders - Gets orders by time range and other parameters diff --git a/bin/ruby-mws b/bin/ruby-mws old mode 100644 new mode 100755 diff --git a/lib/ruby-mws.rb b/lib/ruby-mws.rb index 1694f99..57c6872 100644 --- a/lib/ruby-mws.rb +++ b/lib/ruby-mws.rb @@ -56,6 +56,7 @@ def camelize(first_letter_in_uppercase = true) require 'ruby-mws/api/base' require 'ruby-mws/api/inventory' require 'ruby-mws/api/order' +require 'ruby-mws/api/product' require 'ruby-mws/api/report' require 'ruby-mws/api/query' require 'ruby-mws/api/response' diff --git a/lib/ruby-mws/api/base.rb b/lib/ruby-mws/api/base.rb index a23bcae..8178195 100644 --- a/lib/ruby-mws/api/base.rb +++ b/lib/ruby-mws/api/base.rb @@ -34,10 +34,14 @@ def #{name}(params={}) def send_request(name, params, options={}) # prepare all required params... - params = [default_params(name), params, options, @connection.to_hash].inject :merge + params = [default_params(name), params, options, @connection.to_hash].inject :merge params[:lists] ||= {} - params[:lists][:marketplace_id] = "MarketplaceId.Id" + if self.class.to_s == "MWS::API::Product" + params[:marketplace_id] = @connection.marketplace_id + else + params[:lists][:marketplace_id] = "MarketplaceId.Id" + end query = Query.new params resp = self.class.send(params[:verb], query.request_uri) diff --git a/lib/ruby-mws/api/product.rb b/lib/ruby-mws/api/product.rb new file mode 100644 index 0000000..a44bc6c --- /dev/null +++ b/lib/ruby-mws/api/product.rb @@ -0,0 +1,32 @@ +module MWS + module API + + class Product < Base + def_request [:list_matching_products], + :verb => :get, + :uri => '/Products/2011-10-01', + :version => '2011-10-01', + :mods => [ + lambda {|r| r.products = r.products.product.flatten if r.products} + ] + + def_request [:get_matching_product], + :verb => :get, + :uri => '/Products/2011-10-01', + :version => '2011-10-01', + :lists =>{ + :asin_list => "ASINList.ASIN" + } + + def_request [:get_matching_product_for_id], + :verb => :get, + :uri => '/Products/2011-10-01', + :version => '2011-10-01', + :lists =>{ + :id_list => "IdList.Id" + } + + end + + end +end \ No newline at end of file diff --git a/lib/ruby-mws/base.rb b/lib/ruby-mws/base.rb index f8c72e5..60804e0 100644 --- a/lib/ruby-mws/base.rb +++ b/lib/ruby-mws/base.rb @@ -12,6 +12,10 @@ def orders @orders ||= MWS::API::Order.new(@connection) end + def products + @products ||= MWS::API::Product.new(@connection) + end + def inventory @inventory ||= MWS::API::Inventory.new(@connection) end diff --git a/lib/ruby-mws/version.rb b/lib/ruby-mws/version.rb index 68be4b9..575414a 100644 --- a/lib/ruby-mws/version.rb +++ b/lib/ruby-mws/version.rb @@ -1,3 +1,3 @@ module MWS - VERSION = "0.1" + VERSION = "0.2" end diff --git a/spec/ruby-mws/api/product_spec.rb b/spec/ruby-mws/api/product_spec.rb new file mode 100644 index 0000000..d839ef8 --- /dev/null +++ b/spec/ruby-mws/api/product_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper' + +describe MWS::API::Order do + + before :all do + EphemeralResponse.activate + @mws = MWS.new(auth_params) + end + + context "requests" do + describe "list_matching_products" do + it "should receive a list of products that match" do + products = @mws.products.list_matching_products query: "Habermaas" + products.products.should be_an_instance_of Array + products.products.first.should have_key :attribute_sets + end + end + + describe "get_matching_product" do + it "should receive a list of products that match with ASIN" do + products = @mws.products.get_matching_product asin_list: ["B0012KCLIG","B00000J4XU"] + products.should be_an_instance_of Array + products.first.should have_key :asin + products.first.should have_key :product + end + end + + describe "get_matching_product_for_id" do + it "should receive a list of products that match with IdType and IdList" do + products = @mws.products.get_matching_product_for_id id_list: ["B0012KCLIG","B00000J4XU"], id_type: "ASIN" + products.should be_an_instance_of Array + products.first.should have_key :id_type + products.first.should have_key :products + end + end + end + +end \ No newline at end of file