Class: Edi::Walmart::ListingMessageFeedSender

Inherits:
FeedMessageSender show all
Defined in:
app/services/edi/walmart/listing_message_feed_sender.rb

Constant Summary

Constants included from AddressAbbreviator

AddressAbbreviator::MAX_LENGTH

Instance Attribute Summary

Attributes inherited from BaseEdiService

#orchestrator

Instance Method Summary collapse

Methods inherited from FeedMessageSender

#ecl_in_queue, #instantiate_transporter

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

Constructor Details

This class inherits a constructor from Edi::BaseEdiService

Instance Method Details

#feed_categoryObject



21
22
23
# File 'app/services/edi/walmart/listing_message_feed_sender.rb', line 21

def feed_category
  'listing_feed'
end

#feed_typeObject

Sends item listing feeds to Walmart Marketplace API
See: https://developer.walmart.com/us-marketplace/docs/feeds-overview

Feed types for items:

  • MP_ITEM: Item setup and update
  • MP_MAINTENANCE: Item maintenance
  • RETIRE_ITEM: Retire items


13
14
15
# File 'app/services/edi/walmart/listing_message_feed_sender.rb', line 13

def feed_type
  'MP_ITEM'
end

#process(edi_communication_logs = nil) ⇒ Object

Override to use multipart form upload for item feeds



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/services/edi/walmart/listing_message_feed_sender.rb', line 26

def process(edi_communication_logs = nil)
  feed_transport = instantiate_transporter(orchestrator.transporter, orchestrator.transporter_profile)

  edi_communication_logs ||= ecl_in_queue
  [edi_communication_logs].flatten.each do |ecl|
    logger.info "[Walmart ListingFeedSender] Sending listing feed to #{orchestrator.partner}"

    query_str = "?feedType=#{feed_type}"
    url = "#{orchestrator.feed_message_remote_path}#{query_str}"

    # Use multipart form upload for item feeds
    res = feed_transport.send_feed_data(ecl.data, url, 'POST')

    # Read the response body once (HTTP::Response::Body can only be consumed once)
    response_body = res[:http_result]&.body.to_s

    ecl.notes = "HTTP CODE: #{res[:http_result]&.code}, HTTP BODY: #{response_body.first(500)}, Timestamp: #{Time.current.to_datetime.to_fs(:crm_default)}"
    logger.info "[Walmart ListingFeedSender] Result: HTTP CODE: #{res[:http_result]&.code}"

    if res[:success] && response_body.present?
      json_hash = JSON.parse(response_body).with_indifferent_access
      res_feed_id = json_hash[:feedId]
      ecl.transaction_id = res_feed_id
      ecl.transmit_datetime = Time.current
      ecl.start_process!
      logger.info "[Walmart ListingFeedSender] Feed submitted successfully, feedId: #{res_feed_id}"
    else
      logger.error "[Walmart ListingFeedSender] Feed submission failed: #{response_body}"
      ecl.error
    end
  end

  edi_communication_logs
end

#query_paramObject



17
18
19
# File 'app/services/edi/walmart/listing_message_feed_sender.rb', line 17

def query_param
  nil
end