Class: WebhookProcessors::AmazonSpApiProcessor

Inherits:
Object
  • Object
show all
Defined in:
app/services/webhook_processors/amazon_sp_api_processor.rb

Overview

Processor for Amazon SP-API notifications, drained from SQS into
webhook_logs by AmazonSqsNotificationPollerWorker
(category = notificationType downcased).

Handlers stay thin and hand off to existing Amazon EDI machinery.
Categories without a handler complete as 'noted' — observability first;
a per-type action lands together with its subscription.

Examples:

WebhookProcessors::AmazonSpApiProcessor.call(webhook_log)

See Also:

  • doc/tasks/202607152125_AMAZON_SPAPI_SQS_NOTIFICATIONSdoc/tasks/202607152125_AMAZON_SPAPI_SQS_NOTIFICATIONS.md

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(webhook_log) ⇒ AmazonSpApiProcessor

Returns a new instance of AmazonSpApiProcessor.

Parameters:

  • webhook_log (WebhookLog)

    the notification row to process



28
29
30
31
# File 'app/services/webhook_processors/amazon_sp_api_processor.rb', line 28

def initialize(webhook_log)
  @webhook_log = webhook_log
  @data = webhook_log.data
end

Class Method Details

.call(webhook_log) ⇒ Hash

Process one SP-API notification row.

Parameters:

  • webhook_log (WebhookLog)

    provider 'amazon_sp_api', category = notificationType downcased

Returns:

  • (Hash)

    result stored on WebhookLog#response_data



23
24
25
# File 'app/services/webhook_processors/amazon_sp_api_processor.rb', line 23

def self.call(webhook_log)
  new(webhook_log).call
end

Instance Method Details

#callHash

Returns result stored on WebhookLog#response_data.

Returns:

  • (Hash)

    result stored on WebhookLog#response_data



34
35
36
37
38
39
40
41
42
43
# File 'app/services/webhook_processors/amazon_sp_api_processor.rb', line 34

def call
  case @webhook_log.category
  when 'feed_processing_finished' then feed_processing_finished
  when 'report_processing_finished' then report_processing_finished
  when 'listings_item_issues_change' then listings_item_issues_change
  when 'any_offer_changed' then any_offer_changed
  else
    { status: 'noted', reason: "no handler for #{@webhook_log.category}" }
  end
end