Class: Edi::Amazon::ListingItemSchemaRetriever

Inherits:
BaseEdiService show all
Defined in:
app/services/edi/amazon/listing_item_schema_retriever.rb

Constant Summary

Constants included from Edi::AddressAbbreviator

Edi::AddressAbbreviator::MAX_LENGTH

Instance Attribute Summary

Attributes inherited from BaseEdiService

#orchestrator

Instance Method Summary collapse

Methods inherited from BaseEdiService

#duplicate_po_already_notified?, #initialize, #mark_duplicate_po_as_notified, #report_order_creation_issues, #safe_process_edi_communication_log

Methods included from Edi::AddressAbbreviator

#abbreviate_street, #collect_street_originals, #record_address_abbreviation_notes

Methods inherited from BaseService

#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #options, #tagged_logger

Constructor Details

This class inherits a constructor from Edi::BaseEdiService

Instance Method Details

#process(product_type:, locale: nil, file_info: {}) ⇒ Object

Retrieve catalog item information for the provided ASIN



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/services/edi/amazon/listing_item_schema_retriever.rb', line 6

def process(product_type:, locale: nil, file_info: {})
  # see: https://developer-docs.amazon.com/sp-api/docs/product-type-api-use-case-guide#retrieve-the-product-type-definition
  # url = "https://#{host}/definitions/2020-09-01/productTypes/#{product_type_name}?marketplaceIds=#{marketplace}&requirements=LISTING"
  # method = 'GET'

  if product_type.blank?
    logger.error "ListingItemSchemaRetriever#process called with blank product_type — skipping API call"
    return []
  end

  uri = Addressable::URI.parse("#{orchestrator.product_type_schema_message_remote_path}#{product_type}")
  marketplace_id = orchestrator.marketplace
  query_values = {
    'marketplaceIds' => marketplace_id,
    'requirements' => 'LISTING' # LISTING returns all attributes vs LISTING_OFFER_ONLY and LISTING_PRODUCT_ONLY which return a subset
  }
  uri.query_values = query_values

  remote_path = uri.to_s
  logger.info "Requesting from #{remote_path}"
  ecls = Edi::Amazon::Retriever.new(options).process transporter: orchestrator.transporter,
                                                     transporter_profile: orchestrator.transporter_profile,
                                                     data_type: 'json',
                                                     remote_path: remote_path,
                                                     partner: orchestrator.partner,
                                                     category: :listing_item_schema,
                                                     store_to_upload: false,
                                                     file_info: file_info
  ecls.first # we only deal with one ecl
end