Class: RubyIsds::Responses::Messages::Attachment

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_isds/responses/messages/attachment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Attachment

Returns a new instance of Attachment.



7
8
9
10
11
12
# File 'lib/ruby_isds/responses/messages/attachment.rb', line 7

def initialize(hash)
  @file_type = hash['dmMimeType']
  @file_name = hash['dmFileDescr']
  @encoded_content = hash['dmEncodedContent']
  @decoded_content = Base64.decode64(@encoded_content)
end

Instance Attribute Details

#decoded_contentObject

Returns the value of attribute decoded_content.



5
6
7
# File 'lib/ruby_isds/responses/messages/attachment.rb', line 5

def decoded_content
  @decoded_content
end

#encoded_contentObject

Returns the value of attribute encoded_content.



5
6
7
# File 'lib/ruby_isds/responses/messages/attachment.rb', line 5

def encoded_content
  @encoded_content
end

#file_nameObject

Returns the value of attribute file_name.



5
6
7
# File 'lib/ruby_isds/responses/messages/attachment.rb', line 5

def file_name
  @file_name
end

#file_typeObject

Returns the value of attribute file_type.



5
6
7
# File 'lib/ruby_isds/responses/messages/attachment.rb', line 5

def file_type
  @file_type
end

Instance Method Details

#download(destination = '/tmp') ⇒ Object



14
15
16
17
18
19
20
# File 'lib/ruby_isds/responses/messages/attachment.rb', line 14

def download(destination = '/tmp')
  file_destination = "#{destination}/#{@file_name}"
  File.open(file_destination, 'wb') do |f|
    f.write(@decoded_content)
  end
  file_destination
end