Class: Aspose::Cloud::Words::Document

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

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Document

Returns a new instance of Document.



22
23
24
25
26
# File 'lib/Words/document.rb', line 22

def initialize(filename)
  @filename = filename
  raise 'filename not specified.' if filename.empty?
  @base_uri = "#{Aspose::Cloud::Common::Product.product_uri}/words/#{@filename}"
end

Instance Method Details

#append_document(append_docs, import_format_modes, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object

Appends a list of documents to this one.

@param string append_docs
@param import_format_modes
@param source_folder


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/Words/document.rb', line 34

def append_document(append_docs, import_format_modes, folder_name = '', storage_type = 'Aspose', storage_name = '')
  raise 'append_docs not specified.' if append_docs.empty?
  raise 'import_format_modes not specified.' if import_format_modes.empty?

  docs = Array.new
  append_docs.to_enum.with_index(0).each { |item,i|
    docs.push({ :Href => folder_name.empty? ? item : "#{folder_name}/#{item}", :ImportFormatMode => import_format_modes[i] })
  }
  json_data = JSON.generate({:DocumentEntries => docs})

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

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

Delete a document property

@param string property_name


96
97
98
99
100
101
102
103
# File 'lib/Words/document.rb', line 96

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

  str_uri = "#{@base_uri}/documentProperties/#{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.delete(signed_str_uri, {:accept=>'application/json'}))['Code'] == 200 ? true : false
end

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

Get Resource Properties information like document source format, IsEncrypted, IsSigned and document properties



56
57
58
59
60
# File 'lib/Words/document.rb', line 56

def get_document_info(folder_name = '', storage_type = 'Aspose', storage_name = '')
  str_uri = Aspose::Cloud::Common::Utils.append_storage(@base_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'}))['Document']
end

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

Get Document’s properties



108
109
110
111
112
113
# File 'lib/Words/document.rb', line 108

def get_properties(folder_name = '', storage_type = 'Aspose', storage_name = '')
  str_uri = "#{@base_uri}/documentProperties"
  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'}))['DocumentProperties']['List']
end

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

Get Resource Properties information like document source format, IsEncrypted, IsSigned and document properties

@param string property_name


66
67
68
69
70
71
72
73
# File 'lib/Words/document.rb', line 66

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}/documentProperties/#{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'}))['DocumentProperty']
end

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

Set document property

@param string property_name
@param string property_value


80
81
82
83
84
85
86
87
88
89
90
# File 'lib/Words/document.rb', line 80

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}/documentProperties/#{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'}))['DocumentProperty']
end