Class: Amazon::RecordSalesRanks

Inherits:
Object
  • Object
show all
Includes:
Service
Defined in:
app/services/amazon/record_sales_ranks.rb

Overview

Extracts category-specific sales ranks from Amazon SP-API payloads and writes
their daily time-series projection. The three supported payloads use
different casing and nesting, so normalization lives here rather than in
each ingestion path.

Defined Under Namespace

Classes: Ranking, Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Service

#attributes_used, #build_result, call, #logger

Methods included from Service::Initializer

#initialize

Instance Attribute Details

#catalog_itemObject (readonly)



24
# File 'app/services/amazon/record_sales_ranks.rb', line 24

validates :catalog_item, :source, presence: true

#sourceObject (readonly)



24
# File 'app/services/amazon/record_sales_ranks.rb', line 24

validates :catalog_item, :source, presence: true

Instance Method Details

#callResult

Returns normalized rankings and number of rows inserted/updated.

Returns:

  • (Result)

    normalized rankings and number of rows inserted/updated

Raises:

  • (ArgumentError)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/services/amazon/record_sales_ranks.rb', line 28

def call
  raise ArgumentError, errors.full_messages.to_sentence unless valid?

  extracted_rankings = rankings
  recorded_count = AmazonSalesRankDataPoint.record_all!(
    catalog_item:,
    rankings: extracted_rankings,
    observed_at:,
    source:,
    source_batch_id:
  )

  Result.new(recorded_count:, rankings: extracted_rankings)
end