Class: Edi::MiraklSeller::ProductDataSender

Inherits:
BaseEdiService show all
Defined in:
app/services/edi/mirakl_seller/product_data_sender.rb

Overview

Service object: product data sender.

Defined Under Namespace

Classes: RateLimitedError

Constant Summary collapse

RATE_WINDOW =
15.minutes

Constants included from RequestIdentifiable

RequestIdentifiable::REQUEST_ID_HEADERS

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

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

Methods included from RequestIdentifiable

#partner_request_id

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, #process, #tagged_logger

Constructor Details

This class inherits a constructor from Edi::BaseEdiService

Instance Method Details

#call(edi_communication_logs = nil) ⇒ Object

Retrieves messages according to the partner config



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/services/edi/mirakl_seller/product_data_sender.rb', line 20

def call(edi_communication_logs = nil)
  unless ready?
    raise RateLimitedError,
          "Mirakl allows one product data file per #{RATE_WINDOW.inspect}; retry after the rate window"
  end

  Edi::MiraklSeller::Sender.new(orchestrator, options).call(
    transporter: orchestrator.transporter,
    transporter_profile: orchestrator.transporter_profile,
    remote_path: orchestrator.product_data_remote_path,
    partner: orchestrator.partner,
    category: :product_data,
    edi_communication_logs:
  )
end

#ready?Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
# File 'app/services/edi/mirakl_seller/product_data_sender.rb', line 9

def ready?
  last_ecl = EdiCommunicationLog.where(
    partner: orchestrator.partner,
    category: :product_data,
    state: 'processed'
  ).order(:updated_at).last

  last_ecl.nil? || last_ecl.updated_at <= RATE_WINDOW.ago
end