Class: Edi::MftGateway::Sender
- Inherits:
-
BaseEdiService
- Object
- BaseService
- BaseEdiService
- Edi::MftGateway::Sender
- Defined in:
- app/services/edi/mft_gateway/sender.rb
Overview
Service object: 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
- #instantiate_transporter(transporter, transporter_profile = nil) ⇒ Object
-
#process(remote_path:, partner:, category:, transporter: :http_api, transporter_send_method: 'post', transporter_profile: nil, edi_communication_logs: nil) ⇒ Object
What type of transporter? sftp supported at the moment.
- #sanitize_json_for_transmit(ecl) ⇒ Object
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
#instantiate_transporter(transporter, transporter_profile = nil) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/services/edi/mft_gateway/sender.rb', line 43 def instantiate_transporter(transporter, transporter_profile = nil) case transporter when :sftp 'Transport::SftpConnection'.constantize.new(transporter_profile) when :basic_http_api Transport::BasicHttpApiConnection.new({ profile: transporter_profile }) when :http_api Transport::HttpApiConnection.new({ profile: transporter_profile }) else raise "Unknown transporter: #{transporter}" end end |
#process(remote_path:, partner:, category:, transporter: :http_api, transporter_send_method: 'post', transporter_profile: nil, 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 |
# File 'app/services/edi/mft_gateway/sender.rb', line 8 def process(remote_path:, partner:, category:, transporter: :http_api, transporter_send_method: 'post', transporter_profile: nil, # What connection profile to use? see secrets.yml for options, # Which uri to send to (no trailing /), # Which partner to filter edi communication log on ?, edi_communication_logs: nil) # Which category to pull, e.g order_confirm transport = instantiate_transporter(transporter, transporter_profile) edi_communication_logs ||= EdiCommunicationLog.requiring_processing.where(partner: partner).where(category: category).order(:created_at) [edi_communication_logs].flatten.each do |ecl| # this is kind of hacky but allows us to reuse our cancellation flow and get MFT to send an 870 as required by *&^&*^ Canadian Tire/DSCO remote_path.gsub!('ediType=855', 'ediType=870') if category == :order_acknowledge && partner == :mft_gateway_canadian_tire && ecl.data&.index('"AcknowledgementType":"RD"') # ASCII-safe JSON before transmit so reprocess of logs created # before the build-time sanitization also clears N3 alphanumeric. data_to_send = sanitize_json_for_transmit(ecl) logger.info "Sending #{category} data #{data_to_send} to #{remote_path} using transporter method: #{transporter_send_method} using profile #{transporter_profile}" # 12345678.md56816be8c9e5f6f4a27b9b8911b87a4fa.neworders res = transport.send_data(data_to_send, remote_path, transporter_send_method) ecl.transmit_datetime = Time.current ecl.notes = "HTTP CODE: #{res[:http_result].try(:status)}, ATTEMPT NUMBER: #{res[:attempt_number_reached]}, HTTP BODY: #{res[:http_result].try(:body)}" logger.info "Result: HTTP CODE: #{res[:http_result].try(:status)}, ATTEMPT NUMBER: #{res[:attempt_number_reached]}, HTTP BODY: #{res[:http_result].try(:body)}" if res[:success] ecl.complete! else ecl.error end end edi_communication_logs end |
#sanitize_json_for_transmit(ecl) ⇒ Object
35 36 37 38 39 40 41 |
# File 'app/services/edi/mft_gateway/sender.rb', line 35 def sanitize_json_for_transmit(ecl) return ecl.data unless ecl.data_type == 'json' && ecl.data.present? Heatwave::Normalizers.deep_ascii_safe(JSON.parse(ecl.data)).to_json rescue JSON::ParserError ecl.data end |