Class: SocketLabs::InjectionApi::Message::BulkMessage

Inherits:
MessageBase
  • Object
show all
Defined in:
lib/socketlabs/injectionapi/message/bulk_message.rb

Instance Attribute Summary collapse

Attributes inherited from MessageBase

#api_template, #charset, #html_body, #mailing_id, #message_id, #plain_text_body, #subject

Instance Method Summary collapse

Methods inherited from MessageBase

#add_attachment, #add_custom_header, #attachments, #attachments=, #custom_headers, #custom_headers=, #from_email_address, #from_email_address=, #reply_to_email_address, #reply_to_email_address=

Constructor Details

#initialize(arguments = nil) ⇒ BulkMessage

Returns a new instance of BulkMessage.



9
10
11
12
13
# 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

Instance Attribute Details

#global_merge_dataObject

Returns the value of attribute global_merge_data.



15
16
17
# File 'lib/socketlabs/injectionapi/message/bulk_message.rb', line 15

def global_merge_data
  @global_merge_data
end

Instance Method Details

#add_global_merge_data(key, value) ⇒ Object



35
36
37
# 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) ⇒ Object

Add an BulkRecipient to the To recipient list.

Parameters:

  • email_address (String)
  • friendly_name (String) (defaults to: nil)
  • merge_data (Array) (defaults to: nil)


31
32
33
# 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_jsonObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/socketlabs/injectionapi/message/bulk_message.rb', line 44

def to_json
  {
    subject: @subject,
    textBody: @plain_text_body,
    htmlBody: @html_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_recipientObject

Get the To BulkRecipient list



18
19
20
# File 'lib/socketlabs/injectionapi/message/bulk_message.rb', line 18

def to_recipient
  @to_recipient
end

#to_recipient=(value) ⇒ Object

Set the To BulkRecipient list



22
23
24
25
# 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_sObject



39
40
41
42
# 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