Class: SocketLabs::InjectionApi::Core::Serialization::MessageJson

Inherits:
Object
  • Object
show all
Defined in:
lib/socketlabs/injectionapi/core/serialization/message_json.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMessageJson

Returns a new instance of MessageJson.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 32

def initialize

  @subject = nil
  @plain_text_body = nil
  @html_body = nil
  @amp_body = nil 
  @api_template = nil
  @mailing_id = nil
  @message_id = nil
  @charset = nil
  @from_email_address = nil
  @reply_to = nil
  @merge_data = MergeDataJson.new
  @attachments = Array.new
  @custom_headers = Array.new
  @to_email_address = Array.new
  @cc_email_address = Array.new
  @bcc_email_address = Array.new

end

Instance Attribute Details

#amp_bodyObject

the AMP portion of the message body.



15
16
17
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 15

def amp_body
  @amp_body
end

#api_templateObject

the api template.



17
18
19
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 17

def api_template
  @api_template
end

#charsetObject

the optional character set. Default is UTF-8



23
24
25
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 23

def charset
  @charset
end

#from_email_addressObject

the from email address.



25
26
27
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 25

def from_email_address
  @from_email_address
end

#html_bodyObject

the HTML portion of the message body.



13
14
15
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 13

def html_body
  @html_body
end

#mailing_idObject

the custom mailing id.



19
20
21
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 19

def mailing_id
  @mailing_id
end

#merge_dataObject

the the MergeDataJson for the message



29
30
31
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 29

def merge_data
  @merge_data
end

#message_idObject

the custom message id.



21
22
23
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 21

def message_id
  @message_id
end

#plain_text_bodyObject

the plain text portion of the message body.



11
12
13
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 11

def plain_text_body
  @plain_text_body
end

#reply_toObject

the optional reply to email address.



27
28
29
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 27

def reply_to
  @reply_to
end

#subjectObject

the message subject.



9
10
11
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 9

def subject
  @subject
end

Instance Method Details

#add_attachments(value) ⇒ Object

Add an AttachmentJson to the attachments list.

Parameters:



73
74
75
76
77
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 73

def add_attachments(value)
  if value.instance_of? AttachmentJson
    @attachments.push(value)
  end
end

#add_custom_header(value) ⇒ Object

Add a CustomHeaderJson to the custom header list

Parameters:



100
101
102
103
104
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 100

def add_custom_header(value)
  if value.instance_of? CustomHeaderJson
    @custom_headers.push(value)
  end
end

#attachmentsArray

Get the list of attachments.

Returns:

  • (Array)


55
56
57
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 55

def attachments
  @attachments
end

#attachments=(value) ⇒ Object

Set the list of AttachmentJson.

Parameters:

  • value (Array)


60
61
62
63
64
65
66
67
68
69
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 60

def attachments=(value)
  @attachments = Array.new
  unless value.nil? || value.empty?
    value.each do |v1|
      if v1.instance_of? AttachmentJson
        @attachments.push(v1)
      end
    end
  end
end

#bcc_email_addressArray

Get the BCC email address list

Returns:

  • (Array)


144
145
146
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 144

def bcc_email_address
  @bcc_email_address
end

#bcc_email_address=(value) ⇒ Object

Set the BCC email address list

Parameters:

  • value (Array)


149
150
151
152
153
154
155
156
157
158
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 149

def bcc_email_address=(value)
  @bcc_email_address = Array.new
  unless value.nil? || value.empty?
    value.each do |v1|
      if v1.instance_of? AddressJson
        @bcc_email_address.push(v1)
      end
    end
  end
end

#cc_email_addressArray

Get the CC email address list

Returns:

  • (Array)


126
127
128
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 126

def cc_email_address
  @cc_email_address
end

#cc_email_address=(value) ⇒ Object

Set the CC email address list

Parameters:

  • value (Array)


131
132
133
134
135
136
137
138
139
140
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 131

def cc_email_address=(value)
  @cc_email_address = Array.new
  unless value.nil? || value.empty?
    value.each do |v1|
      if v1.instance_of? AddressJson
        @cc_email_address.push(v1)
      end
    end
  end
end

#custom_headersArray

custom_headers Get the list of CustomHeaderJson.

Returns:

  • (Array)


82
83
84
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 82

def custom_headers
  @custom_headers
end

#custom_headers=(value) ⇒ Object

Set the list of CustomHeaderJson.

Parameters:

  • value (Array)


87
88
89
90
91
92
93
94
95
96
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 87

def custom_headers=(value)
  @custom_headers = Array.new
  unless value.nil? || value.empty?
    value.each do |v1|
      if v1.instance_of? CustomHeaderJson
        @custom_headers.push(v1)
      end
    end
  end
end

#to_email_addressArray

Get the To email address list

Returns:

  • (Array)


108
109
110
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 108

def to_email_address
  @to_email_address
end

#to_email_address=(value) ⇒ Object

Set the To email address list

Parameters:

  • value (Array)


113
114
115
116
117
118
119
120
121
122
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 113

def to_email_address=(value)
  @to_email_address = Array.new
  unless value.nil? || value.empty?
    value.each do |v1|
      if v1.instance_of? AddressJson
        @to_email_address.push(v1)
      end
    end
  end
end

#to_hashhash

build json hash for MessageJson

Returns:

  • (hash)


162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/socketlabs/injectionapi/core/serialization/message_json.rb', line 162

def to_hash

  json = {
      :from => @from_email_address.to_hash
  }

  unless @subject.nil? || @subject.empty?
    json[:subject] = @subject
  end

  unless @html_body.nil? || @html_body.empty?
    json[:htmlBody] = @html_body
  end

  unless @amp_body.nil? || @amp_body.empty?
    json[:ampBody] = @amp_body
  end

  unless @plain_text_body.nil? || @plain_text_body.empty?
    json[:textBody] = @plain_text_body
  end

  unless @api_template.nil?
    json[:apiTemplate] = @api_template
  end

  unless @mailing_id.nil? || @mailing_id.empty?
    json[:mailingId] = @mailing_id
  end

  unless @message_id.nil? || @message_id.empty?
    json[:messageId] = @message_id
  end

  unless @reply_to.nil?
    json[:replyTo] = @reply_to.to_hash
  end

  unless @charset.nil? || @charset.empty?
    json[:charSet] = @charset
  end

  unless @to_email_address.nil? || @to_email_address.length == 0
    e = Array.new
    @to_email_address.each do |value|
        e.push(value.to_hash)
    end
    json[:to] = e
  end

  unless @cc_email_address.nil? || @cc_email_address.length == 0
    e = Array.new
    @cc_email_address.each do |value|
      e.push(value.to_hash)
    end
    json[:cc] = e
  end

  unless @bcc_email_address.nil? || @bcc_email_address.length == 0
    e = Array.new
    @bcc_email_address.each do |value|
      e.push(value.to_hash)
    end
    json[:bcc] = e
  end

  unless @custom_headers.nil? || @custom_headers.length == 0
    e = Array.new
    @custom_headers.each do |value|
      e.push(value.to_hash)
    end
    json[:customHeaders] = e
  end

  unless @attachments.nil? || @attachments.length == 0
    e = Array.new
    @attachments.each do |value|
      e.push(value.to_hash)
    end
    json[:attachments] = e
  end

  unless @merge_data.nil? || @merge_data.empty
      json[:mergeData] = @merge_data.to_hash
  end

  json

end