Skip to content

product type definitions and product pricing methods #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions lib/muffin_man.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
require "muffin_man/feeds/v20210630"
require "muffin_man/notifications/v1"
require "muffin_man/merchant_fulfillment/v0"
require "muffin_man/definitions/v20200901"
require "muffin_man/awd/v20240509"
require "muffin_man/sellers/v1"
require "muffin_man/vendor_direct_fulfillment_inventory/v1"
Expand Down
31 changes: 31 additions & 0 deletions lib/muffin_man/definitions/v20200901.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

module MuffinMan
module Definitions
class V20200901 < SpApiClient
def search_definitions_product_types(marketplace_ids, keywords: nil)
@local_var_path = "/definitions/2020-09-01/productTypes"
@marketplace_ids = marketplace_ids.is_a?(Array) ? marketplace_ids : [marketplace_ids]
@keywords = keywords.is_a?(Array) ? keywords : [keywords]
@query_params = { marketplaceIds: @marketplace_ids.join(",") }
@query_params["keywords"] = @keywords.join(",") if keywords
@request_type = "GET"
call_api
end

def get_definitions_product_type(product_type, marketplace_ids, seller_id: nil, product_type_version: nil,
requirements: nil, requirements_enforced: nil, locale: nil)
@local_var_path = "/definitions/2020-09-01/productTypes/#{product_type}"
@marketplace_ids = marketplace_ids.is_a?(Array) ? marketplace_ids : [marketplace_ids]
@query_params = { marketplaceIds: @marketplace_ids.join(",") }
@query_params["sellerId"] = seller_id if seller_id
@query_params["productTypeVersion"] = product_type_version if product_type_version
@query_params["requirements"] = requirements.join(",") if requirements
@query_params["requirementsEnforced"] = requirements_enforced if requirements_enforced
@query_params["locale"] = locale if locale
@request_type = "GET"
call_api
end
end
end
end
82 changes: 82 additions & 0 deletions lib/muffin_man/product_pricing/v0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
module MuffinMan
module ProductPricing
class V0 < SpApiClient
GET_PRICING_PARAMS = %w[Asins Skus ItemCondition CustomerType].freeze
GET_COMPETITIVE_PRICE_PARAMS = %w[Asins Skus CustomerType].freeze
GET_LISTING_OFFERS_PARAMS = %w[CustomerType].freeze
GET_ITEM_OFFERS_PARAMS = %w[CustomerType].freeze

def get_pricing(marketplace_id, item_type='Asin', params = {})
@local_var_path = '/products/pricing/v0/price'
@params = { 'MarketplaceId' => marketplace_id, 'ItemType' => item_type }
@params.merge! params.slice(*GET_PRICING_PARAMS)
@query_params = hash_to_sp_api_uri_params(@params)
@request_type = "GET"
call_api
end

def get_competitive_pricing(marketplace_id, item_type='Asin', params = {})
@local_var_path = '/products/pricing/v0/competitivePrice'
Expand All @@ -14,6 +26,76 @@ def get_competitive_pricing(marketplace_id, item_type='Asin', params = {})
call_api
end

def get_listing_offers(marketplace_id, item_condition, seller_sku, params = {})
@local_var_path = "/products/pricing/v0/listings/#{seller_sku}/offers"
@params = { 'MarketplaceId' => marketplace_id, 'ItemCondition ' => item_condition }
@params.merge! params.slice(*GET_LISTING_OFFERS_PARAMS)
@query_params = hash_to_sp_api_uri_params(@params)
@request_type = "GET"
call_api
end

def get_item_offers(marketplace_id, item_condition, asin, params = {})
@local_var_path = "/products/pricing/v0/items/#{asin}/offers"
@params = { 'MarketplaceId' => marketplace_id, 'ItemCondition ' => item_condition }
@params.merge! params.slice(*GET_ITEM_OFFERS_PARAMS)
@query_params = hash_to_sp_api_uri_params(@params)
@request_type = "GET"
call_api
end

# params is a hash with the following structure:
# [
# {
# "marketplace_id": "marketplace_id1",
# "asin": "asin1",
# "condition": "New",
# "customer_type": "Consumer" # Optional
# ]
def get_item_offers_batch(params = {})
@local_var_path = "/batches/products/pricing/v0/itemOffers"
requests = []
params.each do |p|
request = {
"uri" => "/products/pricing/v0/items/#{p[:asin]}/offers",
"method" => "GET",
"MarketplaceId" => p[:marketplace_id],
"ItemCondition" => p[:condition]
}
request["CustomerType"] = p[:customer_type] if p[:customer_type]
requests << request
end
@request_body = { "requests" => requests }
@request_type = "POST"
call_api
end

# params is a hash with the following structure:
# [
# {
# "marketplace_id": "marketplace_id1",
# "seller_sku": "sku1",
# "condition": "New",
# "customer_type": "Consumer" # Optional
# ]
def get_listing_offers_batch(params = {})
@local_var_path = "/batches/products/pricing/v0/listingOffers"
requests = []
params.each do |p|
request = {
"uri" => "/products/pricing/v0/listings/#{p[:seller_sku]}/offers",
"method" => "GET",
"MarketplaceId" => p[:marketplace_id],
"ItemCondition" => p[:condition]
}
request["CustomerType"] = p[:customer_type] if p[:customer_type]
requests << request
end
@request_body = { "requests" => requests }
@request_type = "POST"
call_api
end

private

# SP APIs expect param array on the form of Asins=Asin1%2CAsin2 (%2C is url escaped for ,) ...
Expand Down