Class: PostageApp::Mailer::Attachments

Inherits:
Hash
  • Object
show all
Defined in:
lib/postageapp/mailer/mailer_3.rb,
lib/postageapp/mailer/mailer_4.rb

Overview

Wrapper for creating attachments Attachments sent to PostageApp are in the following format:

'filename.ext' => {
  content_type: 'content/type',
  content: 'base64_encoded_content'
 }

Instance Method Summary collapse

Methods inherited from Hash

#dig, #recursive_stringify_keys!

Constructor Details

#initialize(message) ⇒ Attachments

Returns a new instance of Attachments.



38
39
40
41
42
# File 'lib/postageapp/mailer/mailer_3.rb', line 38

def initialize(message)
  @_message = message

  message.arguments['attachments'] ||= { }
end

Instance Method Details

#[]=(filename, attachment) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/postageapp/mailer/mailer_3.rb', line 44

def []=(filename, attachment)
  default_content_type = MIME::Types.type_for(filename).first.content_type rescue ''

  case (attachment)
  when Hash
    content_type = attachment[:content_type] || default_content_type
    content = Base64.encode64(attachment[:body])
  else
    content_type = default_content_type
    content = Base64.encode64(attachment)
  end

  @_message.arguments['attachments'][filename] = {
    'content_type' => content_type,
    'content' => content
  }
end