Sha256: ba267a8d17a4ad04b92e814f49060cad1a9709aef69518d0a3561bbaa15bc19a

Contents?: true

Size: 1.92 KB

Versions: 8

Compression:

Stored size: 1.92 KB

Contents

module MuffinMan
  module CatalogItems
    class BaseApi < 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

      API_VERSION = "2020-12-01".freeze

      def search_catalog_items(keywords, marketplace_ids, params = {}, api_version=API_VERSION)
        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/#{api_version}/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 = {}, api_version=API_VERSION)
        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/#{api_version}/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

8 entries across 8 versions & 1 rubygems

Version Path
muffin_man-1.4.13 lib/muffin_man/catalog_items/base_api.rb
muffin_man-1.4.12 lib/muffin_man/catalog_items/base_api.rb
muffin_man-1.4.11 lib/muffin_man/catalog_items/base_api.rb
muffin_man-1.4.10 lib/muffin_man/catalog_items/base_api.rb
muffin_man-1.4.9 lib/muffin_man/catalog_items/base_api.rb
muffin_man-1.4.8 lib/muffin_man/catalog_items/base_api.rb
muffin_man-1.4.7 lib/muffin_man/catalog_items/base_api.rb
muffin_man-1.4.6 lib/muffin_man/catalog_items/base_api.rb