Class: SendGrid::Attachment

Inherits:
Object
  • Object
show all
Defined in:
lib/sendgrid/helpers/mail/attachment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAttachment

Returns a new instance of Attachment.



7
8
9
10
11
12
13
# File 'lib/sendgrid/helpers/mail/attachment.rb', line 7

def initialize
  @content = nil
  @type = nil
  @filename = nil
  @disposition = nil
  @content_id = nil
end

Instance Attribute Details

#content_idObject

Returns the value of attribute content_id.



5
6
7
# File 'lib/sendgrid/helpers/mail/attachment.rb', line 5

def content_id
  @content_id
end

#dispositionObject

Returns the value of attribute disposition.



5
6
7
# File 'lib/sendgrid/helpers/mail/attachment.rb', line 5

def disposition
  @disposition
end

#filenameObject

Returns the value of attribute filename.



5
6
7
# File 'lib/sendgrid/helpers/mail/attachment.rb', line 5

def filename
  @filename
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/sendgrid/helpers/mail/attachment.rb', line 5

def type
  @type
end

Instance Method Details

#contentObject



20
21
22
23
24
25
26
27
28
# File 'lib/sendgrid/helpers/mail/attachment.rb', line 20

def content
  return @encoded_content if @encoded_content

  @encoded_content = if @content.respond_to?(:read)
                       encode @content
                     else
                       @content
                     end
end

#content=(content) ⇒ Object



15
16
17
18
# File 'lib/sendgrid/helpers/mail/attachment.rb', line 15

def content=(content)
  @encoded_content = nil
  @content = content
end

#to_jsonObject



30
31
32
33
34
35
36
37
38
# File 'lib/sendgrid/helpers/mail/attachment.rb', line 30

def to_json(*)
  {
    'content' => content,
    'type' => type,
    'filename' => filename,
    'disposition' => disposition,
    'content_id' => content_id
  }.delete_if { |_, value| value.to_s.strip == '' }
end