Class: Edi::Openai::ProductDataProcessor

Inherits:
BaseEdiService show all
Defined in:
app/services/edi/openai/product_data_processor.rb

Overview

Builds the OpenAI Ads product feed (a GMC-compatible CSV of our sellable
catalog) and stages it as an outbound EdiCommunicationLog for Sender.

Reuses Feed::OpenaiAds::CatalogFeedGenerator for the catalog → CSV mapping.

Constant Summary

Constants included from AddressAbbreviator

AddressAbbreviator::MAX_LENGTH

Instance Attribute Summary

Attributes inherited from BaseEdiService

#orchestrator

Attributes inherited from BaseService

#options

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 AddressAbbreviator

#abbreviate_street, #collect_street_originals, #record_address_abbreviation_notes

Methods inherited from BaseService

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

Constructor Details

This class inherits a constructor from Edi::BaseEdiService

Instance Method Details

#processEdiCommunicationLog

Returns the staged outbound feed (state ready).

Returns:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/services/edi/openai/product_data_processor.rb', line 10

def process
  EdiCommunicationLog.transaction do
    logger.info "Generating OpenAI Ads product feed for partner #{orchestrator.partner}"
    # OpenAI's feed connection is single-currency (Supported currencies: USD in
    # the Ads Manager), so ship only the USD catalog. The combined US+CA scope
    # sent ~700 CAD-priced rows (the CA catalog) that the USD connection rejected,
    # loading zero products.
    result = Feed::OpenaiAds::CatalogFeedGenerator.new.process(catalogs: Catalog.for_google_feed.where(currency: 'USD'))

    EdiCommunicationLog.create_outbound_file_from_data(
      data:           result.csv,
      file_extension: 'csv',
      partner:        orchestrator.partner,
      category:       'product_data',
      data_type:      'csv',
      file_info:      { product_count: result.product_count }
    )
  end
end