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

Instance Method Summary collapse

Instance Method Details

#contentObject

Returns the raw attachment content, which may be base64 encoded if not plain text



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



28
29
30
31
32
33
34
35
36
# File 'lib/mandrill/web_hook/attachment.rb', line 28

def decoded_content
  if type =~ /^text/
    content
  else # assume it is base64-encoded
    Base64.decode64(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