Class: Viewpoint::EWS::FileAttachment
- Inherits:
-
Attachment
- Object
- Attachment
- Viewpoint::EWS::FileAttachment
- Defined in:
- lib/model/file_attachment.rb
Overview
This class represents a file attachment item. You can save this object to a file withthe #save_to_file method.
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
Attributes inherited from Attachment
Attributes included from Model
#ews_methods, #ews_methods_undef
Instance Method Summary collapse
-
#initialize(attachment_id) ⇒ FileAttachment
constructor
A new instance of FileAttachment.
-
#save_to_file(base_dir = nil, file_name = @file_name) ⇒ Object
Save this FileAttachment object to a file.
Constructor Details
#initialize(attachment_id) ⇒ FileAttachment
Returns a new instance of FileAttachment.
27 28 29 30 31 32 33 34 35 |
# File 'lib/model/file_attachment.rb', line 27 def initialize() @id = conn = Viewpoint::EWS::EWS.instance resp = conn.ews.([]) @file_name = resp.items.first[:file_attachment][:name][:text] # content in Base64 @content = resp.items.first[:file_attachment][:content][:text] end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
25 26 27 |
# File 'lib/model/file_attachment.rb', line 25 def content @content end |
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
25 26 27 |
# File 'lib/model/file_attachment.rb', line 25 def file_name @file_name end |
Instance Method Details
#save_to_file(base_dir = nil, file_name = @file_name) ⇒ Object
Save this FileAttachment object to a file. By default it saves it to the original file’s name in the current working directory.
43 44 45 46 47 48 49 |
# File 'lib/model/file_attachment.rb', line 43 def save_to_file(base_dir = nil, file_name = @file_name) base_dir << '/' unless(base_dir.nil? or base_dir.end_with?('/')) File.open("#{base_dir}#{file_name}", 'w+') do |f| f.write(Base64.decode64(@content)) end true end |