Class: Aspose::Cloud::Email::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/Email/document.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Document

Returns a new instance of Document.



5
6
7
8
9
# File 'lib/Email/document.rb', line 5

def initialize(filename)
  @filename = filename
  raise 'filename not specified.' if filename.empty?
  @base_uri =  Aspose::Cloud::Common::Product.product_uri + '/email/' + @filename
end

Instance Method Details

#add_attachment(attachment_name, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object

Add email attachment

@param string attachment_name Name of the attachment.


65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/Email/document.rb', line 65

def add_attachment(attachment_name, folder_name = '', storage_type = 'Aspose', storage_name = '')
  raise 'attachment_name not specified.' if attachment_name.empty?

  str_uri = "#{@base_uri}/attachments/#{attachment_name}"
  str_uri = Aspose::Cloud::Common::Utils.append_storage(str_uri,folder_name,storage_name,storage_type)
  signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
  response_stream = RestClient.post(signed_str_uri, '', {:accept=>'application/json'})
  
  valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)
  if valid_output.empty?
     Aspose::Cloud::Common::Utils.download_file(@filename,@filename)
  end
  valid_output
end

#get_attachment(attachment_name, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object

Get attachment from the email document

@param string attachment_name Name of the attachment.


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/Email/document.rb', line 45

def get_attachment(attachment_name, folder_name = '', storage_type = 'Aspose', storage_name = '')
  raise 'attachment_name not specified.' if attachment_name.empty?

  str_uri = "#{@base_uri}/attachments/#{attachment_name}"
  str_uri = Aspose::Cloud::Common::Utils.append_storage(str_uri,folder_name,storage_name,storage_type)
  signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
  response_stream = RestClient.get(signed_str_uri, {:accept=>'application/json'})
  valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)

  if valid_output.empty?
    output_path = "#{Aspose::Cloud::Common::AsposeApp.output_location}#{attachment_name}"
    Aspose::Cloud::Common::Utils.save_file(response_stream,output_path)
  end
  valid_output
end

#get_property(property_name, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object

Get property of the email document

@param string property_name Name of the property.


15
16
17
18
19
20
21
22
# File 'lib/Email/document.rb', line 15

def get_property(property_name, folder_name = '', storage_type = 'Aspose', storage_name = '')
  raise 'property_name not specified.' if property_name.empty?

  str_uri = "#{@base_uri}/properties/#{property_name}"
  str_uri = Aspose::Cloud::Common::Utils.append_storage(str_uri,folder_name,storage_name,storage_type)
  signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
  JSON.parse(RestClient.get(signed_str_uri, {:accept=>'application/json'}))['EmailProperty']['Value']
end

#set_property(property_name, property_value, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object

Set property of the email document

@param string property_name Name of the property.
@param string property_value Value of the property.


29
30
31
32
33
34
35
36
37
38
39
# File 'lib/Email/document.rb', line 29

def set_property(property_name, property_value, folder_name = '', storage_type = 'Aspose', storage_name = '')
  raise 'property_name not specified.' if property_name.empty?
  raise 'property_value not specified.' if property_value.empty?

  json_data = JSON.generate('Value'=>property_value)

  str_uri = "#{@base_uri}/properties/#{property_name}"
  str_uri = Aspose::Cloud::Common::Utils.append_storage(str_uri,folder_name,storage_name,storage_type)
  signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
  JSON.parse(RestClient.put(signed_str_uri, json_data, {:content_type=>:json, :accept=>'application/json'}))['EmailProperty']['Value']
end