Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Empty file modified bin/ruby-mws
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions lib/ruby-mws.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 6 additions & 2 deletions lib/ruby-mws/api/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 32 additions & 0 deletions lib/ruby-mws/api/product.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions lib/ruby-mws/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby-mws/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module MWS
VERSION = "0.1"
VERSION = "0.2"
end
38 changes: 38 additions & 0 deletions spec/ruby-mws/api/product_spec.rb
Original file line number Diff line number Diff line change
@@ -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