Class: Feed::Google::MerchantApi::ReportPuller
- Inherits:
-
Object
- Object
- Feed::Google::MerchantApi::ReportPuller
- Defined in:
- app/services/feed/google/merchant_api/report_puller.rb
Overview
Pulls the Merchant API's product_view report (both feed labels in one
call — the query is account-wide, not per feed label) and persists each
row's aggregated status + item issues onto the matching CatalogItem
(google_report), so ListingIssues::GoogleAdapter can map them to
listing_issues without calling the API live. Mirrors
Edi::Wayfair::CatalogReadV2Retriever: a nightly pull persists the
marketplace's own signals; the adapter only ever reads stored data.
offerId in the report response IS the catalog_item id — no id-matching
step is needed, unlike Wayfair (see
GoogleProductPresenter#id: "the unique id for us will be
the catalog item id").
Feed is an ActiveRecord model, so this uses the compact
class Feed::Google::… form (matching Client).
Defined Under Namespace
Classes: PersistenceError, Result
Constant Summary collapse
- QUERY =
idis required in the SELECT or the API 400s; feed_label/status/issues
are what ListingIssues::GoogleAdapter reads back offgoogle_report. 'SELECT id, offer_id, feed_label, aggregated_reporting_context_status, item_issues FROM product_view'
Instance Method Summary collapse
-
#initialize(client: Feed::Google::MerchantApi::Client.new, logger: Rails.logger) ⇒ ReportPuller
constructor
A new instance of ReportPuller.
- #pull ⇒ Feed::Google::MerchantApi::ReportPuller::Result
Constructor Details
#initialize(client: Feed::Google::MerchantApi::Client.new, logger: Rails.logger) ⇒ ReportPuller
Returns a new instance of ReportPuller.
40 41 42 43 |
# File 'app/services/feed/google/merchant_api/report_puller.rb', line 40 def initialize(client: Feed::Google::MerchantApi::Client.new, logger: Rails.logger) @client = client @logger = logger end |
Instance Method Details
#pull ⇒ Feed::Google::MerchantApi::ReportPuller::Result
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/services/feed/google/merchant_api/report_puller.rb', line 46 def pull rows = @client.search_reports(query: QUERY) matched = 0 errors = [] rows.each do |row| offer_id = row['offerId'] next if offer_id.blank? begin matched += 1 if persist(offer_id, row) rescue StandardError => e errors << "#{offer_id}: #{e.class}: #{e.}" end end result = Result.new(rows: rows.size, matched:, errors:) @logger.info "[Feed::Google::MerchantApi::ReportPuller] #{result.to_h}" raise PersistenceError, "#{errors.size} row(s) failed to persist: #{errors.first(5).join('; ')}" if errors.any? result end |