class CreatesendRails::SmartEmailFormatter

Public Class Methods

new(message) click to toggle source
# File lib/createsend-rails/smart_email_formatter.rb, line 9
def initialize(message)
  @message = message
end

Public Instance Methods

format() click to toggle source
# File lib/createsend-rails/smart_email_formatter.rb, line 3
def format
  request_body.deep_reject! { |_k, v| v.blank? }
end

Private Instance Methods

recipients() click to toggle source
# File lib/createsend-rails/smart_email_formatter.rb, line 17
def recipients
  {
    to: @message.to,
    cc: @message.cc,
    bcc: @message.bcc,
    ConsentToTrack: values.try(:[], :consent_to_track) || 'Yes' # That's not clean, should find better way?
  }.symbolize_keys!
end
request_body() click to toggle source
# File lib/createsend-rails/smart_email_formatter.rb, line 13
def request_body
  recipients.merge!(data: values)
end
values() click to toggle source
# File lib/createsend-rails/smart_email_formatter.rb, line 26
def values
  return if @message.try(:body).empty?
  JSON.parse(@message&.body&.raw_source).symbolize_keys!
end