From 0ae637b262e4e5713ba09595d4f8283c4c957aad Mon Sep 17 00:00:00 2001 From: Will Holcomb Date: Wed, 12 Feb 2014 12:18:40 -0500 Subject: [PATCH 01/24] adding products endpoint --- bin/ruby-mws | 0 lib/ruby-mws.rb | 3 ++- lib/ruby-mws/api/product.rb | 17 +++++++++++++++++ lib/ruby-mws/base.rb | 6 +++++- 4 files changed, 24 insertions(+), 2 deletions(-) mode change 100644 => 100755 bin/ruby-mws create mode 100644 lib/ruby-mws/api/product.rb 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..a34eef7 100644 --- a/lib/ruby-mws.rb +++ b/lib/ruby-mws.rb @@ -56,7 +56,8 @@ 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' -require 'ruby-mws/api/binary_response' \ No newline at end of file +require 'ruby-mws/api/binary_response' diff --git a/lib/ruby-mws/api/product.rb b/lib/ruby-mws/api/product.rb new file mode 100644 index 0000000..706b56f --- /dev/null +++ b/lib/ruby-mws/api/product.rb @@ -0,0 +1,17 @@ +module MWS + module API + + class Product < Base + def_request [:get_matching_product], + :verb => :get, + :uri => '/Products/2011-01-01', + :version => '2011-01-01', + :lists => { + :order_status => "OrderStatus.Status" + }, + :mods => [ + lambda {|r| r.products = r.products.product if r.products} + ] + end + end +end diff --git a/lib/ruby-mws/base.rb b/lib/ruby-mws/base.rb index f8c72e5..b5fb06d 100644 --- a/lib/ruby-mws/base.rb +++ b/lib/ruby-mws/base.rb @@ -16,6 +16,10 @@ def inventory @inventory ||= MWS::API::Inventory.new(@connection) end + def products + @products ||= MWS::API::Product.new(@connection) + end + def reports @reports ||= MWS::API::Report.new(@connection) end @@ -27,4 +31,4 @@ def self.server_time end end -end \ No newline at end of file +end From 187f98d3326e289852cb9addce497adcd2694ac3 Mon Sep 17 00:00:00 2001 From: Will Holcomb Date: Wed, 12 Feb 2014 12:23:00 -0500 Subject: [PATCH 02/24] updating endpoint address --- lib/ruby-mws/api/product.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ruby-mws/api/product.rb b/lib/ruby-mws/api/product.rb index 706b56f..2921e0a 100644 --- a/lib/ruby-mws/api/product.rb +++ b/lib/ruby-mws/api/product.rb @@ -4,8 +4,8 @@ module API class Product < Base def_request [:get_matching_product], :verb => :get, - :uri => '/Products/2011-01-01', - :version => '2011-01-01', + :uri => '/Products/2011-10-01', + :version => '2011-10-01', :lists => { :order_status => "OrderStatus.Status" }, From 647fe23ab6961d3a49fc150dd3401377f3ef845c Mon Sep 17 00:00:00 2001 From: Will Holcomb Date: Wed, 12 Feb 2014 13:04:54 -0500 Subject: [PATCH 03/24] trying to expose marketplace id --- lib/ruby-mws/api/base.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ruby-mws/api/base.rb b/lib/ruby-mws/api/base.rb index a23bcae..4d722be 100644 --- a/lib/ruby-mws/api/base.rb +++ b/lib/ruby-mws/api/base.rb @@ -37,7 +37,7 @@ def send_request(name, params, options={}) params = [default_params(name), params, options, @connection.to_hash].inject :merge params[:lists] ||= {} - params[:lists][:marketplace_id] = "MarketplaceId.Id" + params[:lists][:marketplace_id] ||= "MarketplaceId.Id" query = Query.new params resp = self.class.send(params[:verb], query.request_uri) @@ -76,4 +76,4 @@ def inspect end end -end \ No newline at end of file +end From 6892a2a93ab9f8280a2608e53447b38c11d67c58 Mon Sep 17 00:00:00 2001 From: Will Holcomb Date: Wed, 12 Feb 2014 13:14:03 -0500 Subject: [PATCH 04/24] testing removing marketplace id --- lib/ruby-mws/api/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ruby-mws/api/base.rb b/lib/ruby-mws/api/base.rb index 4d722be..4715446 100644 --- a/lib/ruby-mws/api/base.rb +++ b/lib/ruby-mws/api/base.rb @@ -37,7 +37,7 @@ def send_request(name, params, options={}) params = [default_params(name), params, options, @connection.to_hash].inject :merge params[:lists] ||= {} - params[:lists][:marketplace_id] ||= "MarketplaceId.Id" + #params[:lists][:marketplace_id] = "MarketplaceId.Id" query = Query.new params resp = self.class.send(params[:verb], query.request_uri) From 604e6ecef86cffb4ab6b10314f3aae30fcd6e17d Mon Sep 17 00:00:00 2001 From: Will Holcomb Date: Wed, 12 Feb 2014 14:26:14 -0500 Subject: [PATCH 05/24] reenabling marketplace transform --- lib/ruby-mws/api/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ruby-mws/api/base.rb b/lib/ruby-mws/api/base.rb index 4715446..5546e05 100644 --- a/lib/ruby-mws/api/base.rb +++ b/lib/ruby-mws/api/base.rb @@ -37,7 +37,7 @@ def send_request(name, params, options={}) params = [default_params(name), params, options, @connection.to_hash].inject :merge params[:lists] ||= {} - #params[:lists][:marketplace_id] = "MarketplaceId.Id" + params[:lists][:marketplace_id] = "MarketplaceId.Id" query = Query.new params resp = self.class.send(params[:verb], query.request_uri) From ddba60ac4cb2859c985f8eec5eeb45ac4a92ba1e Mon Sep 17 00:00:00 2001 From: Will Holcomb Date: Wed, 12 Feb 2014 14:52:47 -0500 Subject: [PATCH 06/24] trying to disable for products --- lib/ruby-mws/api/base.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/ruby-mws/api/base.rb b/lib/ruby-mws/api/base.rb index 5546e05..ac1c1d8 100644 --- a/lib/ruby-mws/api/base.rb +++ b/lib/ruby-mws/api/base.rb @@ -37,7 +37,9 @@ def send_request(name, params, options={}) params = [default_params(name), params, options, @connection.to_hash].inject :merge params[:lists] ||= {} - params[:lists][:marketplace_id] = "MarketplaceId.Id" + if not params[:uri].starts_with '/Products' + params[:lists][:marketplace_id] = "MarketplaceId.Id" + end query = Query.new params resp = self.class.send(params[:verb], query.request_uri) From 02c414005b8e213cd3258f3f3251c80d451b8562 Mon Sep 17 00:00:00 2001 From: Will Holcomb Date: Wed, 12 Feb 2014 14:53:50 -0500 Subject: [PATCH 07/24] correct method --- lib/ruby-mws/api/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ruby-mws/api/base.rb b/lib/ruby-mws/api/base.rb index ac1c1d8..e7777aa 100644 --- a/lib/ruby-mws/api/base.rb +++ b/lib/ruby-mws/api/base.rb @@ -37,7 +37,7 @@ def send_request(name, params, options={}) params = [default_params(name), params, options, @connection.to_hash].inject :merge params[:lists] ||= {} - if not params[:uri].starts_with '/Products' + if not params[:uri].start_with? '/Products' params[:lists][:marketplace_id] = "MarketplaceId.Id" end From 09d3d8b6e66436216e915f4f893595fe6c55053f Mon Sep 17 00:00:00 2001 From: Will Holcomb Date: Wed, 12 Feb 2014 14:58:06 -0500 Subject: [PATCH 08/24] showing request variable --- lib/ruby-mws/api/product.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/ruby-mws/api/product.rb b/lib/ruby-mws/api/product.rb index 2921e0a..26db71c 100644 --- a/lib/ruby-mws/api/product.rb +++ b/lib/ruby-mws/api/product.rb @@ -3,14 +3,17 @@ module API class Product < Base def_request [:get_matching_product], - :verb => :get, - :uri => '/Products/2011-10-01', - :version => '2011-10-01', - :lists => { - :order_status => "OrderStatus.Status" + verb: :get, + uri: '/Products/2011-10-01', + version: '2011-10-01', + lists: { + order_status: "OrderStatus.Status" }, - :mods => [ - lambda {|r| r.products = r.products.product if r.products} + mods: [ + lambda { |r| + puts r + r.products = r.products.product if r.products + } ] end end From f0e27a6d76f4723a9ccbbecace3d985dd0cb4ae3 Mon Sep 17 00:00:00 2001 From: Will Holcomb Date: Wed, 12 Feb 2014 15:06:10 -0500 Subject: [PATCH 09/24] prettying --- lib/ruby-mws/api/product.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ruby-mws/api/product.rb b/lib/ruby-mws/api/product.rb index 26db71c..5ad2bf0 100644 --- a/lib/ruby-mws/api/product.rb +++ b/lib/ruby-mws/api/product.rb @@ -11,7 +11,7 @@ class Product < Base }, mods: [ lambda { |r| - puts r + puts r.inspect r.products = r.products.product if r.products } ] From e8783b1213ed5ada91e6bc3b10d2bd1e848f519b Mon Sep 17 00:00:00 2001 From: Will Holcomb Date: Wed, 12 Feb 2014 16:14:19 -0500 Subject: [PATCH 10/24] removing mods --- lib/ruby-mws/api/product.rb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/ruby-mws/api/product.rb b/lib/ruby-mws/api/product.rb index 5ad2bf0..d201343 100644 --- a/lib/ruby-mws/api/product.rb +++ b/lib/ruby-mws/api/product.rb @@ -5,16 +5,8 @@ class Product < Base def_request [:get_matching_product], verb: :get, uri: '/Products/2011-10-01', - version: '2011-10-01', - lists: { - order_status: "OrderStatus.Status" - }, - mods: [ - lambda { |r| - puts r.inspect - r.products = r.products.product if r.products - } - ] + version: '2011-10-01' + ] end end end From 6a70a2bc033e603d2653ae85b4be88a81830ea1f Mon Sep 17 00:00:00 2001 From: Will Holcomb Date: Wed, 12 Feb 2014 16:16:01 -0500 Subject: [PATCH 11/24] typos --- lib/ruby-mws/api/product.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ruby-mws/api/product.rb b/lib/ruby-mws/api/product.rb index d201343..bda9a13 100644 --- a/lib/ruby-mws/api/product.rb +++ b/lib/ruby-mws/api/product.rb @@ -2,11 +2,11 @@ module MWS module API class Product < Base - def_request [:get_matching_product], + def_request + [:get_matching_product], verb: :get, uri: '/Products/2011-10-01', version: '2011-10-01' - ] end end end From 086c9bfcc7a8e7b4968bd9ab10489d79e2ebf894 Mon Sep 17 00:00:00 2001 From: Will Holcomb Date: Wed, 12 Feb 2014 16:16:48 -0500 Subject: [PATCH 12/24] syntax error --- lib/ruby-mws/api/product.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/ruby-mws/api/product.rb b/lib/ruby-mws/api/product.rb index bda9a13..4c70465 100644 --- a/lib/ruby-mws/api/product.rb +++ b/lib/ruby-mws/api/product.rb @@ -2,8 +2,7 @@ module MWS module API class Product < Base - def_request - [:get_matching_product], + def_request [:get_matching_product], verb: :get, uri: '/Products/2011-10-01', version: '2011-10-01' From fd4633630e728e480b65e2c813dd39603d762be9 Mon Sep 17 00:00:00 2001 From: Will Holcomb Date: Wed, 12 Feb 2014 16:39:13 -0500 Subject: [PATCH 13/24] trying to move reformatting to gem --- lib/ruby-mws/api/product.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/ruby-mws/api/product.rb b/lib/ruby-mws/api/product.rb index 4c70465..fa82344 100644 --- a/lib/ruby-mws/api/product.rb +++ b/lib/ruby-mws/api/product.rb @@ -5,7 +5,17 @@ class Product < Base def_request [:get_matching_product], verb: :get, uri: '/Products/2011-10-01', - version: '2011-10-01' + version: '2011-10-01', + mods: [ + lambda do |response| + response.products = response.product.map do |p| + p = p[0] + response = p[:product][:attribute_sets][:item_attributes] + response[:asin] = p[:asin] + response + end + end + ] end end end From b6170dda1093e67f68e35eaf02f8849555155b81 Mon Sep 17 00:00:00 2001 From: Will Holcomb Date: Wed, 12 Feb 2014 16:42:51 -0500 Subject: [PATCH 14/24] debugging --- lib/ruby-mws/api/product.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ruby-mws/api/product.rb b/lib/ruby-mws/api/product.rb index fa82344..4658b03 100644 --- a/lib/ruby-mws/api/product.rb +++ b/lib/ruby-mws/api/product.rb @@ -1,6 +1,5 @@ module MWS module API - class Product < Base def_request [:get_matching_product], verb: :get, @@ -8,6 +7,7 @@ class Product < Base version: '2011-10-01', mods: [ lambda do |response| + puts response response.products = response.product.map do |p| p = p[0] response = p[:product][:attribute_sets][:item_attributes] From d5029d07a201c764fbe4adf647a1c9ce29c33bab Mon Sep 17 00:00:00 2001 From: Will Holcomb Date: Wed, 12 Feb 2014 17:07:39 -0500 Subject: [PATCH 15/24] trying to get to run --- lib/ruby-mws/api/product.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/ruby-mws/api/product.rb b/lib/ruby-mws/api/product.rb index 4658b03..5d2665a 100644 --- a/lib/ruby-mws/api/product.rb +++ b/lib/ruby-mws/api/product.rb @@ -8,12 +8,7 @@ class Product < Base mods: [ lambda do |response| puts response - response.products = response.product.map do |p| - p = p[0] - response = p[:product][:attribute_sets][:item_attributes] - response[:asin] = p[:asin] - response - end + response.product = response.product.attribute_sets.item_attributes end ] end From 6d8c9bb7cc8e9fdc5845d28c15fe61faa642ead1 Mon Sep 17 00:00:00 2001 From: Will Holcomb Date: Wed, 12 Feb 2014 17:09:56 -0500 Subject: [PATCH 16/24] debugging --- lib/ruby-mws/api/product.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ruby-mws/api/product.rb b/lib/ruby-mws/api/product.rb index 5d2665a..0b3e806 100644 --- a/lib/ruby-mws/api/product.rb +++ b/lib/ruby-mws/api/product.rb @@ -8,7 +8,7 @@ class Product < Base mods: [ lambda do |response| puts response - response.product = response.product.attribute_sets.item_attributes + response.product.map { |p| p[:attribute_sets][:item_attributes] } end ] end From d4f5fd7bf7db6d4f88926ab45a37f34d50c1c0b1 Mon Sep 17 00:00:00 2001 From: Will Holcomb Date: Wed, 12 Feb 2014 17:11:11 -0500 Subject: [PATCH 17/24] addressing --- lib/ruby-mws/api/product.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ruby-mws/api/product.rb b/lib/ruby-mws/api/product.rb index 0b3e806..bbb44d9 100644 --- a/lib/ruby-mws/api/product.rb +++ b/lib/ruby-mws/api/product.rb @@ -8,7 +8,7 @@ class Product < Base mods: [ lambda do |response| puts response - response.product.map { |p| p[:attribute_sets][:item_attributes] } + response.product.map { |p| p.attribute_sets.item_attributes } end ] end From f0db59a59322527d02d4e683390757c759bfbfdc Mon Sep 17 00:00:00 2001 From: Will Holcomb Date: Wed, 12 Feb 2014 17:12:13 -0500 Subject: [PATCH 18/24] there has got to be a simpler method for testing --- lib/ruby-mws/api/product.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ruby-mws/api/product.rb b/lib/ruby-mws/api/product.rb index bbb44d9..8d310bd 100644 --- a/lib/ruby-mws/api/product.rb +++ b/lib/ruby-mws/api/product.rb @@ -8,7 +8,7 @@ class Product < Base mods: [ lambda do |response| puts response - response.product.map { |p| p.attribute_sets.item_attributes } + response.product.map { |p| p[0][:attribute_sets][:item_attributes] } end ] end From 8fda1bbe20860ee893029b5372ba4d9fcdd93f08 Mon Sep 17 00:00:00 2001 From: Will Holcomb Date: Wed, 12 Feb 2014 20:13:47 -0500 Subject: [PATCH 19/24] adding additional endpoints --- lib/ruby-mws/api/product.rb | 42 +++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/lib/ruby-mws/api/product.rb b/lib/ruby-mws/api/product.rb index 8d310bd..fba5f34 100644 --- a/lib/ruby-mws/api/product.rb +++ b/lib/ruby-mws/api/product.rb @@ -7,10 +7,48 @@ class Product < Base version: '2011-10-01', mods: [ lambda do |response| - puts response - response.product.map { |p| p[0][:attribute_sets][:item_attributes] } + response.map! do |p| + n = p.product.attribute_sets.item_attributes + n.asin = p.asin + n + end end ] + + def_request [:get_competitive_pricing_for_ASIN], + verb: :get, + uri: '/Products/2011-10-01', + version: '2011-10-01', + mods: [ + lambda do |response| + response.map! do |p| + n = p.product.competitive_pricing + n.prices = n.competitive_prices.competitive_price + n.sales_rankings = p.product.sales_rankings + n.asin = p.asin + n + end + end + ] + + def_request [:get_lowest_offer_listings_for_ASIN], + verb: :get, + uri: '/Products/2011-10-01', + version: '2011-10-01', + mods: [ + lambda do |response| + response.map! do |p| + n = p.product.lowest_offer_listings + n.asin = p.asin + n + end + end + ] + + def_request [:get_product_categories_for_ASIN], + verb: :get, + uri: '/Products/2011-10-01', + version: '2011-10-01' end end end From 48c7e6de39dc7eb6815ab338de96f9608251db55 Mon Sep 17 00:00:00 2001 From: Will Holcomb Date: Wed, 12 Feb 2014 21:33:54 -0500 Subject: [PATCH 20/24] adding product tests --- spec/ruby-mws/api/product_spec.rb | 50 +++++++++++++++++++++++++++++++ spec/spec_helper.rb | 4 +-- 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 spec/ruby-mws/api/product_spec.rb diff --git a/spec/ruby-mws/api/product_spec.rb b/spec/ruby-mws/api/product_spec.rb new file mode 100644 index 0000000..1022d21 --- /dev/null +++ b/spec/ruby-mws/api/product_spec.rb @@ -0,0 +1,50 @@ +require 'spec_helper' + +describe MWS::API::Order do + + before :all do + EphemeralResponse.activate + @mws = MWS.new(auth_params) + end + + context 'requests' do + describe 'get_matching_product' do + it 'should receive a list of products' do + products = @mws.products.get_matching_product :'ASINList.ASIN.1' => 'B002DYJTVW', :'ASINList.ASIN.2' => 'B0018KVHJO' + + products.should be_an_instance_of Array + products.first.should have_key :asin + products.first.should have_key :title + end + end + + describe 'get_competitive_pricing_for_ASIN' do + it 'should recieve competitive pricing for an asin' do + products = @mws.products.get_competitive_pricing_for_ASIN :'ASINList.ASIN.1' => 'B002DYJTVW', :'ASINList.ASIN.2' => 'B0018KVHJO' + + products.should be_an_instance_of Array + products.first.should have_key :asin + products.first.should have_key :prices + end + end + + describe 'get_lowest_offer_listings_for_ASIN' do + it 'should recieve competitive pricing for an asin' do + products = @mws.products.get_lowest_offer_listings_for_ASIN :'ASINList.ASIN.1' => 'B002DYJTVW', :'ASINList.ASIN.2' => 'B0018KVHJO' + + products.should be_an_instance_of Array + products.first.should have_key :asin + products.first.should have_key :lowest_offer_listing + end + end + + describe 'get_lowest_offer_listings_for_ASIN' do + it 'should recieve competitive pricing for an asin' do + category = @mws.products.get_product_categories_for_ASIN ASIN: 'B002DYJTVW' + + category.self.should have_key :product_category_id + category.self.should have_key :product_category_name + end + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7738559..6a144d8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -31,9 +31,9 @@ def auth_params def timestamp # use a recent timestamp here... how to replace this? - "2013-11-17T21:17:59-06:00" + "2014-02-12T20:56:59-05:00" end end class TestWorksError < StandardError -end \ No newline at end of file +end From 001d3b6a8b3ff305f392f1830b23e2caf5565bef Mon Sep 17 00:00:00 2001 From: Will Holcomb Date: Thu, 13 Feb 2014 16:50:54 -0500 Subject: [PATCH 21/24] adding rails rake tasks --- lib/tasks/mws.rake | 88 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 lib/tasks/mws.rake diff --git a/lib/tasks/mws.rake b/lib/tasks/mws.rake new file mode 100644 index 0000000..ded676b --- /dev/null +++ b/lib/tasks/mws.rake @@ -0,0 +1,88 @@ +require 'pp' + +desc "This task is called by the Heroku scheduler add-on" + +namespace :mws do + desc "Test download from BetterMWS" + task :'test-better' => :environment do + asin = 'B002DYJTVW' + url = 'http://api.bettermws.com/v1/lookup?' + params = { + merchant_id: ENV['MERCHANT_ID'], + marketplace_id: ENV['MARKETPLACE_ID'], + asin: asin, + persist: 24, + format: 'json', + ts: Time.now.to_i + } + + url += params.to_query + + url += "&sig=" + Digest::MD5.hexdigest(ENV['AWS_KEY'] + url) + + uri = URI.parse(url) + req = Net::HTTP::Get.new(uri.to_s) + res = Net::HTTP.start(uri.host, uri.port) { |http| http.request(req) } + puts url + puts res.body + end + + desc "Print server time" + task time: :environment do + puts MWS::Base.server_time + end + + desc "List orders" + task orders: :environment do + response = mws.orders.list_orders last_updated_after: 4.hours.ago + + pp response.orders + end + + # rake mws:product[B002DYJTVW,B0018KVHJO] + desc "List product" + task :product, [*1..10].map!{ |i| ("ASINList.ASIN." + i.to_s).to_sym } => :environment do |t, args| + args.with_defaults(:'ASINList.ASIN.1' => 'B002DYJTVW', :'ASINList.ASIN.2' => 'B0018KVHJO') if not args[:'ASINList.ASIN.1'] + + # should be response.products + products = mws.products.get_matching_product args + + pp products + end + + desc "Competitive pricing" + task :cprice, [*1..10].map!{ |i| ("ASINList.ASIN." + i.to_s).to_sym } => :environment do |t, args| + args.with_defaults(:'ASINList.ASIN.1' => 'B002DYJTVW', :'ASINList.ASIN.2' => 'B0018KVHJO') if not args[:'ASINList.ASIN.1'] + + response = mws.products.get_competitive_pricing_for_ASIN args + + pp response + end + + desc "Lowest price listing" + task :lprice, [*1..10].map!{ |i| ("ASINList.ASIN." + i.to_s).to_sym } => :environment do |t, args| + args.with_defaults(:'ASINList.ASIN.1' => 'B002DYJTVW', :'ASINList.ASIN.2' => 'B0018KVHJO') if not args[:'ASINList.ASIN.1'] + + response = mws.products.get_lowest_offer_listings_for_ASIN args + + pp response + end + + desc "Categories" + task :categories, [:asin] => :environment do |t, args| + args.with_defaults(asin: 'B002DYJTVW') + + response = mws.products.get_product_categories_for_ASIN ASIN: args.asin + + pp response + end + + def mws + @mws ||= MWS.new(aws_access_key_id: ENV['AWS_ID'], + secret_access_key: ENV['AWS_KEY'], + seller_id: ENV['MERCHANT_ID'], + marketplace_id: ENV['MARKETPLACE_ID']) + end + + +end From cfc3dc06a8b9ecc5e3758cbe0d3016df41a57896 Mon Sep 17 00:00:00 2001 From: Will Holcomb Date: Thu, 13 Feb 2014 16:57:23 -0500 Subject: [PATCH 22/24] removing BetterMWS --- lib/tasks/mws.rake | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/lib/tasks/mws.rake b/lib/tasks/mws.rake index ded676b..d156997 100644 --- a/lib/tasks/mws.rake +++ b/lib/tasks/mws.rake @@ -1,32 +1,8 @@ require 'pp' -desc "This task is called by the Heroku scheduler add-on" +desc 'Access MWS services' namespace :mws do - desc "Test download from BetterMWS" - task :'test-better' => :environment do - asin = 'B002DYJTVW' - url = 'http://api.bettermws.com/v1/lookup?' - params = { - merchant_id: ENV['MERCHANT_ID'], - marketplace_id: ENV['MARKETPLACE_ID'], - asin: asin, - persist: 24, - format: 'json', - ts: Time.now.to_i - } - - url += params.to_query - - url += "&sig=" + Digest::MD5.hexdigest(ENV['AWS_KEY'] + url) - - uri = URI.parse(url) - req = Net::HTTP::Get.new(uri.to_s) - res = Net::HTTP.start(uri.host, uri.port) { |http| http.request(req) } - puts url - puts res.body - end - desc "Print server time" task time: :environment do puts MWS::Base.server_time From 95abfb9f7db5e9be275b8c26e3963244b605937f Mon Sep 17 00:00:00 2001 From: Will Holcomb Date: Fri, 14 Feb 2014 14:55:03 -0500 Subject: [PATCH 23/24] figured out the constantizing error --- lib/ruby-mws/api/product.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/ruby-mws/api/product.rb b/lib/ruby-mws/api/product.rb index fba5f34..4f24ef7 100644 --- a/lib/ruby-mws/api/product.rb +++ b/lib/ruby-mws/api/product.rb @@ -8,8 +8,8 @@ class Product < Base mods: [ lambda do |response| response.map! do |p| - n = p.product.attribute_sets.item_attributes - n.asin = p.asin + n = p.product.try(:attribute_sets).try(:item_attributes) + n.asin = p.asin if n n end end @@ -22,10 +22,12 @@ class Product < Base mods: [ lambda do |response| response.map! do |p| - n = p.product.competitive_pricing - n.prices = n.competitive_prices.competitive_price - n.sales_rankings = p.product.sales_rankings - n.asin = p.asin + n = p.product.try(:competitive_pricing) + if n + n.prices = n.competitive_prices.competitive_price + n.sales_rankings = p.product.sales_rankings + n.asin = p.asin + end n end end From 11a0d5d6d6e184797b6fb5f8a0d8702522e341ed Mon Sep 17 00:00:00 2001 From: Will Holcomb Date: Fri, 14 Feb 2014 15:19:47 -0500 Subject: [PATCH 24/24] removing prices shortcut --- lib/ruby-mws/api/product.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/ruby-mws/api/product.rb b/lib/ruby-mws/api/product.rb index 4f24ef7..aeab1ef 100644 --- a/lib/ruby-mws/api/product.rb +++ b/lib/ruby-mws/api/product.rb @@ -24,7 +24,6 @@ class Product < Base response.map! do |p| n = p.product.try(:competitive_pricing) if n - n.prices = n.competitive_prices.competitive_price n.sales_rankings = p.product.sales_rankings n.asin = p.asin end