Class: Mandrill::WebHook::Attachment

Inherits:
Hash
  • Object
show all
Defined in:
lib/mandrill/web_hook/attachment.rb

Overview

Wraps an individual (file) attachment as part of a Mandrill event payload.

Each attachment is described in the raw Mandrill payload as a hash with three elements:

'name' => the filename
'type' => the content mime type
'content' => the raw content, which will be base64-encoded if not plain text

Direct Known Subclasses

Image

Instance Method Summary collapse

Instance Method Details

#base64Object

Returns a boolean for whether the attachment content is base64 encoded



28
29
30
# File 'lib/mandrill/web_hook/attachment.rb', line 28

def base64
  self['base64']
end

#contentObject

Returns the raw attachment content, which may be base64 encoded



23
24
25
# File 'lib/mandrill/web_hook/attachment.rb', line 23

def content
  self['content']
end

#decoded_contentObject

Returns the decoded content for the attachment



33
34
35
36
37
38
39
40
41
# File 'lib/mandrill/web_hook/attachment.rb', line 33

def decoded_content
  if base64
    Base64.decode64(content)
  else
    content
  end
rescue # any decoding error, just return the content
  content
end

#nameObject

Returns the attachment name



13
14
15
# File 'lib/mandrill/web_hook/attachment.rb', line 13

def name
  self['name']
end

#typeObject

Returns the attachment mime type



18
19
20
# File 'lib/mandrill/web_hook/attachment.rb', line 18

def type
  self['type']
end