Class: MuffinMan::CatalogItems::BaseApi

Inherits:
SpApiClient show all
Defined in:
lib/muffin_man/catalog_items/base_api.rb

Direct Known Subclasses

V20201201, V20220401

Constant Summary collapse

SANDBOX_KEYWORDS =
"shoes".freeze
SANDBOX_ASIN =
"B07N4M94X4".freeze
SANDBOX_MARKETPLACE_IDS =
"ATVPDKIKX0DER".freeze
SEARCH_CATALOG_ITEMS_PARAMS =
[].freeze
BASE_SEARCH_CATALOG_ITEMS_PARAMS =
%w[
  includedData
  brandNames
  classificationIds
  pageSize
  pageToken
  keywordsLocale
  locale
].freeze
GET_CATALOG_ITEM_PARAMS =
%w[includedData locale].freeze
DEFAULT_IDENTIFERS_TYPE =
"ASIN".freeze
API_VERSION =
"2020-12-01".freeze

Constants inherited from SpApiClient

SpApiClient::ACCESS_TOKEN_URL, SpApiClient::AWS_REGION_MAP, SpApiClient::SERVICE_NAME, SpApiClient::UNPROCESSABLE_ENTITY_STATUS_CODE

Instance Attribute Summary collapse

Attributes inherited from SpApiClient

#access_token_cache_key, #aws_access_key_id, #aws_secret_access_key, #client_id, #client_secret, #config, #credentials, #local_var_path, #pii_data_elements, #query_params, #refresh_token, #region, #request_body, #request_type, #sandbox, #scope, #sts_iam_role_arn

Instance Method Summary collapse

Methods inherited from SpApiClient

#initialize

Constructor Details

This class inherits a constructor from MuffinMan::SpApiClient

Instance Attribute Details

#asinObject (readonly)

Returns the value of attribute asin.



7
8
9
# File 'lib/muffin_man/catalog_items/base_api.rb', line 7

def asin
  @asin
end

#keywordsObject (readonly)

Returns the value of attribute keywords.



7
8
9
# File 'lib/muffin_man/catalog_items/base_api.rb', line 7

def keywords
  @keywords
end

#marketplace_idsObject (readonly)

Returns the value of attribute marketplace_ids.



7
8
9
# File 'lib/muffin_man/catalog_items/base_api.rb', line 7

def marketplace_ids
  @marketplace_ids
end

#paramsObject (readonly)

Returns the value of attribute params.



7
8
9
# File 'lib/muffin_man/catalog_items/base_api.rb', line 7

def params
  @params
end

Instance Method Details

#get_catalog_item(asin, marketplace_ids, params = {}, api_version = API_VERSION) ⇒ Object

rubocop:enable Metrics/CyclomaticComplexity



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/muffin_man/catalog_items/base_api.rb', line 51

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

#search_catalog_items(keywords, marketplace_ids, params = {}, api_version = API_VERSION) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/muffin_man/catalog_items/base_api.rb', line 25

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]
  @identifiers = params["identifiers"].is_a?(Array) ? params["identifiers"] : [params["identifiers"]]
  validate_keywords_and_identifiers
  @marketplace_ids = marketplace_ids.is_a?(Array) ? marketplace_ids : [marketplace_ids]
  @params = params
  @local_var_path = "/catalog/#{api_version}/items"
  @query_params = {
    "marketplaceIds" => @marketplace_ids.join(",")
  }
  @query_params["keywords"] = @keywords.join(",") if @keywords.any?
  if @identifiers.any?
    @query_params["identifiers"] = @identifiers.join(",")
    @query_params["identifiersType"] = params["identifiersType"] || DEFAULT_IDENTIFERS_TYPE
  end
  @query_params.merge!(@params.slice(*search_catalog_items_params))
  @request_type = "GET"
  call_api
end