class Emarsys::Broadcast::BatchXmlBuilder

Public Instance Methods

build(batch) click to toggle source
# File lib/emarsys/broadcast/batch_xml_builder.rb, line 6
def build(batch)
  raise ArgumentError, 'batch is required' unless batch
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.batch {
      xml.name batch.name
      xml.runDate format_time(batch.send_time)
      xml.properties {
        xml.property(key: :Sender){xml.text batch.sender_id}
        xml.property(key: :Language){xml.text 'en'}
        xml.property(key: :Encoding){xml.text 'UTF-8'}
        xml.property(key: :Domain){xml.text batch.sender_domain}
        xml.property(key: :ImportDelay){xml.text batch.import_delay_hours}
      }
      xml.subject batch.subject
      xml.html batch.body_html
      xml.text batch.body_text
    }
  end 
  builder.to_xml
end

Private Instance Methods

format_time(time) click to toggle source
# File lib/emarsys/broadcast/batch_xml_builder.rb, line 30
def format_time(time)
  time.strftime("%Y-%m-%dT%H:%M:%S%z")
end