class SocketLabs::InjectionApi::Message::BulkMessage

Attributes

global_merge_data[RW]

Public Class Methods

new(arguments = nil) click to toggle source
Calls superclass method
# File lib/socketlabs/injectionapi/message/bulk_message.rb, line 9
def initialize(arguments = nil)
  super
  @to_recipient = Array.new
  @global_merge_data = Array.new
end

Public Instance Methods

add_global_merge_data(key, value) click to toggle source
# File lib/socketlabs/injectionapi/message/bulk_message.rb, line 35
def add_global_merge_data(key, value)
  @global_merge_data.push(MergeData.new(key, value))
end
add_to_recipient(email_address, friendly_name = nil, merge_data = nil) click to toggle source

Add an BulkRecipient to the To recipient list. @param [String] email_address @param [String] friendly_name @param [Array] merge_data

# File lib/socketlabs/injectionapi/message/bulk_message.rb, line 31
def add_to_recipient(email_address, friendly_name = nil, merge_data = nil)
  convert_bulk_recipient(@to_recipient, email_address, friendly_name, merge_data)
end
to_json() click to toggle source
# File lib/socketlabs/injectionapi/message/bulk_message.rb, line 44
def to_json
  {
    subject: @subject,
    textBody: @plain_text_body,
    htmlBody: @html_body,
    amp_Body: @amp_body,
    apiTemplate: @api_template,
    mailingId: @mailing_id,
    messageId: @message_id,
    charSet: @charset,
    from: @from_email_address,
    replyTo: @reply_to_email_address,
    attachments: @attachments,
    customHeaders: @custom_headers,
    to: @to_recipient,
    global_merge_data: @global_merge_data
  }
end
to_recipient() click to toggle source

Get the To BulkRecipient list

# File lib/socketlabs/injectionapi/message/bulk_message.rb, line 18
def to_recipient
  @to_recipient
end
to_recipient=(value) click to toggle source

Set the To BulkRecipient list

# File lib/socketlabs/injectionapi/message/bulk_message.rb, line 22
def to_recipient=(value)
  @to_recipient = Array.new
  convert_bulk_recipient(@to_email_address, value)
end
to_s() click to toggle source
# File lib/socketlabs/injectionapi/message/bulk_message.rb, line 39
def to_s
  c = @to_recipient.any? ? @to_recipient.count : 0
  "Recipients: #{c}, Subject: '#{@subject}'"
end

Private Instance Methods

convert_bulk_recipient(array_instance, recipient, friendly_name = nil, merge_data = nil) click to toggle source
# File lib/socketlabs/injectionapi/message/bulk_message.rb, line 64
def convert_bulk_recipient(array_instance, recipient, friendly_name = nil, merge_data = nil)

  if recipient.kind_of? Array
    convert_bulk_recipient_array(array_instance, recipient)
  else
    convert_bulk_recipient_object(array_instance, recipient, friendly_name, merge_data)
  end
end
convert_bulk_recipient_array(array_instance, value) click to toggle source
# File lib/socketlabs/injectionapi/message/bulk_message.rb, line 91
def convert_bulk_recipient_array(array_instance, value)

  if value.kind_of? Array
    value.each do |x|
      convert_email_address_object(array_instance, x)
    end
  end

end
convert_bulk_recipient_object(array_instance, recipient, friendly_name = nil, merge_data = nil) click to toggle source
# File lib/socketlabs/injectionapi/message/bulk_message.rb, line 73
def convert_bulk_recipient_object(array_instance, recipient, friendly_name = nil, merge_data = nil)
  unless recipient.nil?

    if recipient.kind_of? BulkRecipient
      array_instance.push(recipient)

    elsif recipient.kind_of? String
      array_instance.push(BulkRecipient.new(recipient, { :friendly_name => friendly_name, :merge_data => merge_data }))

    elsif recipient.kind_of? Hash or recipient.kind_of? OpenStruct
      array_instance.push(BulkRecipient.new(email_address[:email_address], { :friendly_name => email_address[:friendly_name], :merge_data => email_address[:merge_data] }, ))

    end

  end

end