Class: Edi::Houzz::InventorySender
- Inherits:
-
BaseEdiService
- Object
- BaseService
- BaseEdiService
- Edi::Houzz::InventorySender
- Defined in:
- app/services/edi/houzz/inventory_sender.rb
Overview
Service object: inventory sender.
Constant Summary
Constants included from AddressAbbreviator
AddressAbbreviator::MAX_LENGTH
Instance Attribute Summary
Attributes inherited from BaseEdiService
Attributes inherited from BaseService
Instance Method Summary collapse
-
#process(transporter: :http_api, transporter_send_method: 'post', transporter_profile: nil, remote_path:, partner:, category:, edi_communication_logs: nil) ⇒ Object
What type of transporter? sftp supported at the moment.
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
#process(transporter: :http_api, transporter_send_method: 'post', transporter_profile: nil, remote_path:, partner:, category:, edi_communication_logs: nil) ⇒ Object
What type of transporter? sftp supported at the moment
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/services/edi/houzz/inventory_sender.rb', line 8 def process(transporter: :http_api, transporter_send_method: 'post', transporter_profile: nil, # What connection profile to use? see secrets.yml for options remote_path:, # Which uri to send to (no trailing /) partner:, # Which partner to filter edi communication log on ? category:, edi_communication_logs: nil) # Which category to pull, e.g order_confirm edi_communication_logs ||= EdiCommunicationLog.requiring_processing.where(partner: partner).where(category: category).order(:created_at) [edi_communication_logs].flatten.each do |ecl| logger.info "Sending #{category} data #{ecl.data} to #{remote_path} using transporter method: #{transporter_send_method} using profile #{transporter_profile}" if ecl.data ecl.processing! table = CSV.parse(ecl.data, headers: true) table.each_with_index do |inventory_hash, i| inventory_entry = { UpdateInventoryRequest: { SKU: inventory_hash['SupplierSKU'], Action: 'update', Quantity: inventory_hash['Quantity'] } } position = i + 1 interval = (position * 5).seconds HouzzInventoryUpdaterWorker.perform_in(interval, ecl.id, position, table.size, inventory_entry.to_json, transporter.to_s, transporter_profile.to_s, remote_path, transporter_send_method.to_s) end ecl.transmit_datetime = Time.current msg = "Scheduled HouzzInventoryUpdaterWorker for #{table.size} items" ecl.notes = msg logger.info msg ecl.processing else ecl.notes = "Houzz InventorySender: No data!" logger.info "Result: Houzz InventorySender: No data!" ecl.error end end edi_communication_logs end |