Class: Paubox::Message

Inherits:
Object
  • Object
show all
Includes:
FormatHelper
Defined in:
lib/paubox/message.rb

Overview

The Message class is for building a Paubox email message using a hash.

Direct Known Subclasses

TemplatedMessage

Constant Summary

Constants included from FormatHelper

FormatHelper::BASE64_REGEX

Instance Attribute Summary collapse

Instance Method Summary collapse

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) ⇒ Message

Returns a new instance of Message.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/paubox/message.rb', line 10

def initialize(args)
  @from = args[:from]
  @to = args[:to]
  @cc = args[:cc]
  @bcc = args[:bcc]
  @subject = args[:subject]
  @reply_to = args[:reply_to]
  @text_content = args[:text_content]
  @html_content = args[:html_content]
  @packaged_attachments = []
  @attachments = build_attachments(args[:attachments])
  @allow_non_tls = args.fetch(:allow_non_tls, false)
  @force_secure_notification = args.fetch(:force_secure_notification, nil)
end

Instance Attribute Details

#allow_non_tlsObject

Returns the value of attribute allow_non_tls.



7
8
9
# File 'lib/paubox/message.rb', line 7

def allow_non_tls
  @allow_non_tls
end

#bccObject

Returns the value of attribute bcc.



7
8
9
# File 'lib/paubox/message.rb', line 7

def bcc
  @bcc
end

#ccObject

Returns the value of attribute cc.



7
8
9
# File 'lib/paubox/message.rb', line 7

def cc
  @cc
end

#force_secure_notificationObject

Returns the value of attribute force_secure_notification.



7
8
9
# File 'lib/paubox/message.rb', line 7

def force_secure_notification
  @force_secure_notification
end

#fromObject

Returns the value of attribute from.



7
8
9
# File 'lib/paubox/message.rb', line 7

def from
  @from
end

#html_contentObject

Returns the value of attribute html_content.



7
8
9
# File 'lib/paubox/message.rb', line 7

def html_content
  @html_content
end

#reply_toObject

Returns the value of attribute reply_to.



7
8
9
# File 'lib/paubox/message.rb', line 7

def reply_to
  @reply_to
end

#subjectObject

Returns the value of attribute subject.



7
8
9
# File 'lib/paubox/message.rb', line 7

def subject
  @subject
end

#text_contentObject

Returns the value of attribute text_content.



7
8
9
# File 'lib/paubox/message.rb', line 7

def text_content
  @text_content
end

#toObject

Returns the value of attribute to.



7
8
9
# File 'lib/paubox/message.rb', line 7

def to
  @to
end

Instance Method Details

#add_attachment(file_path) ⇒ Object



29
30
31
32
33
# File 'lib/paubox/message.rb', line 29

def add_attachment(file_path)
  @packaged_attachments << { filename: file_path.split('/').last,
                             content_type: `file --b --mime-type #{file_path}`.chomp,
                             content: Base64.encode64(File.read(file_path)) }
end

#attachmentsObject



35
36
37
# File 'lib/paubox/message.rb', line 35

def attachments
  @packaged_attachments
end

#attachments=(args) ⇒ Object



39
40
41
# File 'lib/paubox/message.rb', line 39

def attachments=(args)
  @attachments = build_attachments(args)
end

#send_message_payloadObject



25
26
27
# File 'lib/paubox/message.rb', line 25

def send_message_payload
  { data: { message: convert_keys_to_json_version(build_parts) } }.to_json
end