Sha256: 575a01d340b1c1f6868c8866d8a1c793f07d1e9b5ec398b8265e11a0f456946a

Contents?: true

Size: 1.83 KB

Versions: 11

Compression:

Stored size: 1.83 KB

Contents

module MuffinMan
  module CatalogItems
    class V20201201 < SpApiClient
      SANDBOX_KEYWORDS = "shoes".freeze
      SANDBOX_ASIN = "B07N4M94X4".freeze
      SANDBOX_MARKETPLACE_IDS = "ATVPDKIKX0DER".freeze
      attr_reader :keywords, :asin, :marketplace_ids, :params

      SEARCH_CATALOG_ITEMS_PARAMS = %w[
        includedData
        brandNames
        classificationIds
        pageSize
        pageToken
        keywordsLocale
        locale
      ].freeze
      GET_CATALOG_ITEM_PARAMS = %w[includedData locale].freeze

      def search_catalog_items(keywords, marketplace_ids, params = {})
        if sandbox
          keywords = SANDBOX_KEYWORDS
          marketplace_ids = SANDBOX_MARKETPLACE_IDS
          params = {}
        end
        @keywords = keywords.is_a?(Array) ? keywords : [keywords]
        @marketplace_ids = marketplace_ids.is_a?(Array) ? marketplace_ids : [marketplace_ids]
        @params = params
        @local_var_path = "/catalog/2020-12-01/items"
        @query_params = {
          "keywords" => @keywords.join(","),
          "marketplaceIds" => @marketplace_ids.join(",")
        }
        @query_params.merge!(@params.slice(*SEARCH_CATALOG_ITEMS_PARAMS))
        @request_type = "GET"
        call_api
      end

      def get_catalog_item(asin, marketplace_ids, params = {})
        if sandbox
          asin = SANDBOX_ASIN
          marketplace_ids = SANDBOX_MARKETPLACE_IDS
          params = {}
        end
        @asin = asin
        @marketplace_ids = marketplace_ids.is_a?(Array) ? marketplace_ids : [marketplace_ids]
        @params = params
        @local_var_path = "/catalog/2020-12-01/items/#{@asin}"
        @query_params = { "marketplaceIds" => @marketplace_ids.join(",") }
        @query_params.merge!(@params.slice(*GET_CATALOG_ITEM_PARAMS))
        @request_type = "GET"
        call_api
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
muffin_man-1.4.5 lib/muffin_man/catalog_items/v20201201.rb
muffin_man-1.4.4 lib/muffin_man/catalog_items/v20201201.rb
muffin_man-1.4.3 lib/muffin_man/catalog_items/v20201201.rb
muffin_man-1.4.2 lib/muffin_man/catalog_items/v20201201.rb
muffin_man-1.4.1 lib/muffin_man/catalog_items/v20201201.rb
muffin_man-1.4.0 lib/muffin_man/catalog_items/v20201201.rb
muffin_man-1.3.0 lib/muffin_man/catalog_items/v20201201.rb
muffin_man-1.2.0 lib/muffin_man/catalog_items/v20201201.rb
muffin_man-1.1.0 lib/muffin_man/catalog_items/v20201201.rb
muffin_man-1.0.2 lib/muffin_man/catalog_items/v20201201.rb
muffin_man-1.0.1 lib/muffin_man/catalog_items/v20201201.rb