Class: Paubox::TemplatedMessage

Inherits:
Message
  • Object
show all
Defined in:
lib/paubox/templated_message.rb

Overview

The TemplatedMessage class is for building a Paubox email message from a dynamic template, using a hash.

Constant Summary

Constants included from FormatHelper

FormatHelper::BASE64_REGEX

Instance Attribute Summary collapse

Attributes inherited from Message

#allow_non_tls, #bcc, #cc, #force_secure_notification, #from, #html_content, #reply_to, #subject, #text_content, #to

Instance Method Summary collapse

Methods inherited from Message

#add_attachment, #attachments, #attachments=

Methods included from FormatHelper

#base64_encode_if_needed, #base64_encoded?, #convert_keys_to_json_version, #ruby_to_json_key, #squish, #string_or_array_to_array

Constructor Details

#initialize(args) ⇒ TemplatedMessage

Returns a new instance of TemplatedMessage.



9
10
11
12
13
14
# File 'lib/paubox/templated_message.rb', line 9

def initialize(args)
  @template_name = args[:template][:name]
  @template_values = args[:template][:values]

  super
end

Instance Attribute Details

#template_nameObject

Returns the value of attribute template_name.



6
7
8
# File 'lib/paubox/templated_message.rb', line 6

def template_name
  @template_name
end

#template_valuesObject

Returns the value of attribute template_values.



6
7
8
# File 'lib/paubox/templated_message.rb', line 6

def template_values
  @template_values
end

Instance Method Details

#send_message_payloadObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/paubox/templated_message.rb', line 16

def send_message_payload
  # template name and values must be outside the `message` object
  msg = convert_keys_to_json_version(build_parts)

  template_params = {
    template_name: @template_name,
    template_values: @template_values.to_json
  }

  { data: { message: convert_keys_to_json_version(build_parts) }.merge(template_params) }.to_json
end