Class: Edi::MiraklSeller::Retriever
- Inherits:
-
BaseService
- Object
- BaseService
- Edi::MiraklSeller::Retriever
- Defined in:
- app/services/edi/mirakl_seller/retriever.rb
Overview
I connect to a transport, retrieve files and save them in the Edi Communication log
Instance Method Summary collapse
- #instantiate_transporter(transporter, transporter_profile = nil) ⇒ Object
- #make_call(path_for_call, transport, file_pattern, partner, category, data_type) ⇒ Object
- #process(transporter: :http_api, transporter_profile: nil, remote_path:, file_pattern: nil, partner:, category:, data_type: 'json') ⇒ Object
Methods inherited from BaseService
#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #options, #tagged_logger
Constructor Details
This class inherits a constructor from BaseService
Instance Method Details
#instantiate_transporter(transporter, transporter_profile = nil) ⇒ Object
42 43 44 45 |
# File 'app/services/edi/mirakl_seller/retriever.rb', line 42 def instantiate_transporter(transporter, transporter_profile = nil) # It doesn't matter what we get in the params, mirakl only has 1 transporter Transport::MiraklTransporter.new({profile: transporter_profile}) end |
#make_call(path_for_call, transport, file_pattern, partner, category, data_type) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/services/edi/mirakl_seller/retriever.rb', line 20 def make_call(path_for_call, transport, file_pattern, partner, category, data_type) data = transport.batch_download_data(path_for_call, file_pattern)["response"] json_hash = JSON.parse(data).with_indifferent_access rescue nil if json_hash.nil? ErrorReporting.error("Mirakl Retriever. Received empty response calling this path: #{path_for_call}") else EdiCommunicationLog.transaction do if data data_blob = json_hash.to_json end edi_log = nil unless json_hash[:total_count].to_i.zero? # just skip generating edi communication logs if no records to process edi_log = EdiCommunicationLog.new(partner: partner,category: category,data: data_blob,data_type: data_type,transmit_datetime: Time.current) edi_log.save! logger.info "Order retrieving saved to edi log #{edi_log.id}" end edi_log end end json_hash end |
#process(transporter: :http_api, transporter_profile: nil, remote_path:, file_pattern: nil, partner:, category:, data_type: 'json') ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/services/edi/mirakl_seller/retriever.rb', line 6 def process(transporter: :http_api, transporter_profile: nil, # Transporter profile for sftp connection, see secrets.yml remote_path:, # Directory to pull from, usually specified in partner configuration file_pattern: nil, # Regexp file pattern to match partner:, # Name of partner for creating log entry category:, # Category for log entry data_type: 'json') transport = instantiate_transporter(transporter, transporter_profile) json = make_call(remote_path, transport, file_pattern, partner, category, data_type) # TODO: Mirakl allows pagination. Since we retrieve new orders every 5 minutes, it's very unlikely we # will ever need pagination. If so, see Channel Engine retriever as an example. end |