Class: SocketLabs::InjectionApi::Message::BulkRecipient
- Inherits:
-
Object
- Object
- SocketLabs::InjectionApi::Message::BulkRecipient
- Includes:
- SocketLabs::InjectionApi, Core
- Defined in:
- lib/socketlabs/injectionapi/message/bulk_recipient.rb
Overview
Represents an individual BulkRecipient for a message. Example:
email_address1 = BulkRecipient.new("[email protected]")
email_address2 = BulkRecipient.new("[email protected]", "Recipient")
email_address3 = BulkRecipient.new("[email protected]", "Recipient")
email_address3.merge_data.push(MergeData.new("name1", "value1"))
email_address3.add_merge_data("name2", "value2")
Constant Summary
Constants included from SocketLabs::InjectionApi
Instance Attribute Summary collapse
-
#email_address ⇒ Object
A valid email address.
-
#friendly_name ⇒ Object
The friendly or display name for the recipient.
-
#merge_data ⇒ Object
Merge data unique to the instance of the bulk recipient.
Instance Method Summary collapse
-
#add_merge_data(key, value) ⇒ Object
Add to an Array of MergeData.
-
#initialize(email_address, arguments = nil) ⇒ BulkRecipient
constructor
Creates a new instance of the BulkRecipient class.
-
#is_valid ⇒ Boolean
Determines if the BulkRecipient is valid.
-
#to_s ⇒ String
Represents the BulkRecipient as a string.
Constructor Details
#initialize(email_address, arguments = nil) ⇒ BulkRecipient
Creates a new instance of the BulkRecipient class.
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 |
# File 'lib/socketlabs/injectionapi/message/bulk_recipient.rb', line 30 def initialize( email_address, arguments = nil ) @email_address = email_address @merge_data = Array.new unless arguments.nil? || arguments.empty? unless arguments[:friendly_name].nil? || arguments[:friendly_name].empty? @friendly_name = arguments[:friendly_name] end unless arguments[:merge_data].nil? || arguments[:merge_data].empty? unless arguments[:merge_data].nil? || arguments[:merge_data].empty? arguments[:merge_data].each do |value| if value.instance_of? MergeData @merge_data.push(value) elsif value.instance_of? Hash @merge_data.push(MergeData.new(value[:key], value[:value])) end end end end end end |
Instance Attribute Details
#email_address ⇒ Object
A valid email address.
21 22 23 |
# File 'lib/socketlabs/injectionapi/message/bulk_recipient.rb', line 21 def email_address @email_address end |
#friendly_name ⇒ Object
The friendly or display name for the recipient.
23 24 25 |
# File 'lib/socketlabs/injectionapi/message/bulk_recipient.rb', line 23 def friendly_name @friendly_name end |
#merge_data ⇒ Object
Merge data unique to the instance of the bulk recipient.
25 26 27 |
# File 'lib/socketlabs/injectionapi/message/bulk_recipient.rb', line 25 def merge_data @merge_data end |
Instance Method Details
#add_merge_data(key, value) ⇒ Object
Add to an Array of MergeData
62 63 64 |
# File 'lib/socketlabs/injectionapi/message/bulk_recipient.rb', line 62 def add_merge_data(key, value) @merge_data.push(MergeData.new(key, value)) end |
#is_valid ⇒ Boolean
Determines if the BulkRecipient is valid. Does simple syntax validation on the email address.
68 69 70 |
# File 'lib/socketlabs/injectionapi/message/bulk_recipient.rb', line 68 def is_valid StringExtension.new.is_valid_email_address(@email_address) end |
#to_s ⇒ String
Represents the BulkRecipient as a string
74 75 76 77 78 79 80 81 |
# File 'lib/socketlabs/injectionapi/message/bulk_recipient.rb', line 74 def to_s if @friendly_name.nil? || @friendly_name.empty? @email_address else "#{@friendly_name} <#{@email_address}>" end end |