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.



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

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

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

Accept All Tracking Changes in the Document



343
344
345
346
347
348
349
350
351
# File 'lib/Words/document.rb', line 343

def accept_tracking_changes(folder_name = '', storage_type = 'Aspose', storage_name = '')
  str_uri = "#{@base_uri}/revisions/acceptAll"
  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, {: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

#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 Name of the file.
@param import_format_modes Specify formatting modes.


85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/Words/document.rb', line 85

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_headers_footers(folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object

Remove all Headers and Footers



333
334
335
336
337
338
# File 'lib/Words/document.rb', line 333

def delete_headers_footers(folder_name = '', storage_type = 'Aspose', storage_name = '')
  str_uri = "#{@base_uri}/headersFooters"
  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

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

Delete a document property

@param string property_name Name of the property.


147
148
149
150
151
152
153
154
# File 'lib/Words/document.rb', line 147

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_bookmark(bookmark_name, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object

Get a Particular Bookmark from a Word

@param string bookmark_name Name of the bookmark.


289
290
291
292
293
294
295
296
# File 'lib/Words/document.rb', line 289

def get_bookmark(bookmark_name, folder_name = '', storage_type = 'Aspose', storage_name = '')
  raise 'Bookmark name not specified.' if bookmark_name.empty?

  str_uri = "#{@base_uri}/bookmarks/#{bookmark_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'}))['Bookmark']
end

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

Get all Bookmarks from a Word



278
279
280
281
282
283
# File 'lib/Words/document.rb', line 278

def get_bookmarks(folder_name = '', storage_type = 'Aspose', storage_name = '')
  str_uri = "#{@base_uri}/bookmarks"
  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'}))['Bookmarks']['BookmarkList']
end

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

Get Bookmarks Count from a Word



301
302
303
304
305
306
307
308
# File 'lib/Words/document.rb', line 301

def get_bookmarks_count(folder_name = '', storage_type = 'Aspose', storage_name = '')
  str_uri = "#{@base_uri}/bookmarks"
  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 = RestClient.get(signed_str_uri, {:accept=>'application/json'})
  json = JSON.parse(response)
  json['Code'] == 200 ? json['Bookmarks']['BookmarkList'].count : nil
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



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

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 a Particular Hyperlink from a Word

@param number hyperlink_index Index of the hyperlink.


254
255
256
257
258
259
260
261
# File 'lib/Words/document.rb', line 254

def get_hyperlink(hyperlink_index, folder_name = '', storage_type = 'Aspose', storage_name = '')
  raise 'Hyperlink index not provided.' if hyperlink_index.nil?

  str_uri = "#{@base_uri}/hyperlinks/#{hyperlink_index}"
  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'}))['Hyperlink']
end

Get all Hyperlinks from a Word



243
244
245
246
247
248
# File 'lib/Words/document.rb', line 243

def get_hyperlinks(folder_name = '', storage_type = 'Aspose', storage_name = '')
  str_uri = "#{@base_uri}/hyperlinks"
  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'}))['Hyperlinks']['HyperlinkList']
end

Get Hyperlinks Count from a Word



266
267
268
269
270
271
272
273
# File 'lib/Words/document.rb', line 266

def get_hyperlinks_count(folder_name = '', storage_type = 'Aspose', storage_name = '')
  str_uri = "#{@base_uri}/hyperlinks"
  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 = RestClient.get(signed_str_uri, {:accept=>'application/json'})
  json = JSON.parse(response)
  json['Code'] == 200 ? json['Hyperlinks']['HyperlinkList'].count : nil
end

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

Extract Page Setup Information from a Word Document

@param number section_index Index of the section.


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

def get_page_setup(section_index, folder_name = '', storage_type = 'Aspose', storage_name = '')
  raise 'section_index not specified.' if section_index.nil?

  str_uri = "#{@base_uri}/sections/#{section_index}/pageSetup"
  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'}))['PageSetup']
end

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

Get Document’s properties



159
160
161
162
163
164
# File 'lib/Words/document.rb', line 159

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 Name of the property.


117
118
119
120
121
122
123
124
# File 'lib/Words/document.rb', line 117

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

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

Get the Current Protection of the Word document



169
170
171
172
173
174
# File 'lib/Words/document.rb', line 169

def get_protection(folder_name = '', storage_type = 'Aspose', storage_name = '')
  str_uri = "#{@base_uri}/protection"
  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'}))['ProtectionData']['ProtectionType']
end

#insert_page_number(alignment, format, is_top = false, set_page_number_on_first_page = false, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object

Insert Page Number Field into the Document

@param string alignment Alignment of page number.
@param string format Specify format.
@param boolean is_top
@param boolean set_page_number_on_first_page


373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
# File 'lib/Words/document.rb', line 373

def insert_page_number(alignment, format, is_top = false, set_page_number_on_first_page = false, folder_name = '', storage_type = 'Aspose', storage_name = '')
  raise 'alignment not specified.' if alignment.empty?
  raise 'format not specified.' if format.empty?

  str_uri = "#{@base_uri}/insertPageNumbers"
  str_uri = Aspose::Cloud::Common::Utils.append_storage(str_uri,'',storage_name,storage_type)
  signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)

  data = Hash['Format' => format, 'Alignment' => alignment, 'IsTop' => is_top, 'SetPageNumberOnFirstPage' => set_page_number_on_first_page]
  json_data = JSON.generate(data)

  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

#protect_document(password, protection_type = 'AllowOnlyComments', folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object

Protect a Word Document

@param string password Document protection password.
@param string protection_type Document protection type.


181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/Words/document.rb', line 181

def protect_document(password, protection_type = 'AllowOnlyComments', folder_name = '', storage_type = 'Aspose', storage_name = '')
  raise 'password not specified.' if password.empty?

  str_uri = "#{@base_uri}/protection"
  str_uri = Aspose::Cloud::Common::Utils.append_storage(str_uri,'',storage_name,storage_type)
  signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)

  data = Hash['Password' => password, 'ProtectionType' => protection_type]
  json_data = JSON.generate(data)

  response_stream = RestClient.put(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

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

Reject All Tracking Changes in the Document



356
357
358
359
360
361
362
363
364
# File 'lib/Words/document.rb', line 356

def reject_tracking_changes(folder_name = '', storage_type = 'Aspose', storage_name = '')
  str_uri = "#{@base_uri}/revisions/rejectAll"
  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, {: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

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

Convert Word Documents to any Format with Additional Settings

@param xml options_xml Provide options in xml format.


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/Words/document.rb', line 15

def save_as(options_xml, folder_name = '', storage_type = 'Aspose', storage_name = '')
  raise 'options not specified.' if options_xml.empty?

  str_uri = "#{@base_uri}/saveAs"
  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, options_xml, {:content_type=>'application/xml', :accept=>'application/json'})
  valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)

  return valid_output unless valid_output.empty?

  json_response = JSON.parse(response_stream)
  Aspose::Cloud::Common::Utils.download_file(json_response['SaveResult']['DestDocument']['Href'],
                                             json_response['SaveResult']['DestDocument']['Href'],
                                             folder_name,storage_name,storage_type)
end

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

Set document property

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


131
132
133
134
135
136
137
138
139
140
141
# File 'lib/Words/document.rb', line 131

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

#split_document(from = '', to = '', save_format = 'pdf', folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object

Split pages to new format

@param number from The start page number for splitting.
@param number to The last page number for splitting.
@param string save_format Return file format.


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

def split_document(from='', to='', save_format='pdf', folder_name = '', storage_type = 'Aspose', storage_name = '')
  str_uri = "#{@base_uri}/split"
  qry = Hash.new
  qry[:from] = from
  qry[:to] = to
  qry[:format] = save_format

  str_uri = Aspose::Cloud::Common::Utils.build_uri(str_uri, qry)
  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.post(signed_str_uri, nil, {:content_type=>:json, :accept=>'application/json'}))['SplitResult']
end

#unprotect_document(password, protection_type, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object

Unprotect a Word Document

@param string password Document protection password.
@param string protection_type Document protection type.


201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/Words/document.rb', line 201

def unprotect_document(password, protection_type, folder_name = '', storage_type = 'Aspose', storage_name = '')
  raise 'password not specified.' if password.empty?
  raise 'protection_type not specified.' if protection_type.empty?

  str_uri = "#{@base_uri}/protection"
  str_uri = Aspose::Cloud::Common::Utils.append_storage(str_uri,'',storage_name,storage_type)
  signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)

  data = Hash['Password' => password, 'ProtectionType' => protection_type]
  json_data = JSON.generate(data)

  #response_stream = RestClient.put(signed_str_uri, json_data, {:content_type=>:json, :accept=>'application/json'})
  response_stream = Aspose::Cloud::Common::Utils.process_command(signed_str_uri,'DELETE','JSON',json_data)
  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

#update_bookmark(bookmark_name, bookmark_text, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object

Update Bookmark Text of a Word

@param string bookmark_name Name of the bookmark.
@param string bookmark_text New text of the bookmark.


315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/Words/document.rb', line 315

def update_bookmark(bookmark_name, bookmark_text, folder_name = '', storage_type = 'Aspose', storage_name = '')
  raise 'bookmark_name not specified.' if bookmark_name.empty?
  raise 'bookmark_text not specified.' if bookmark_text.empty?

  str_uri = "#{@base_uri}/bookmarks/#{bookmark_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_data = JSON.generate({ "Text" => "#{bookmark_text}" })          
  
  response = Aspose::Cloud::Common::Utils.process_command(signed_str_uri,'POST','JSON',json_data)
  json = JSON.parse(response)
  json['Code'] == 200 ? json['Bookmark'] : nil
end

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

Update All Fields in the World Document



392
393
394
395
396
397
398
399
# File 'lib/Words/document.rb', line 392

def update_fields(folder_name = '', storage_type = 'Aspose', storage_name = '')
  str_uri = "#{@base_uri}/updateFields"
  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 = RestClient.post(signed_str_uri, '', {:accept=>'application/json'})
  json = JSON.parse(response)
  json['Code'] == 200 ? true : false
end

#update_page_setup(section_index, options_xml, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object

Update Page Setup of a Section in a Word Document

@param number section_index Index of the section.
@param xml options_xml Options to update.


70
71
72
73
74
75
76
77
78
# File 'lib/Words/document.rb', line 70

def update_page_setup(section_index, options_xml, folder_name = '', storage_type = 'Aspose', storage_name = '')
  raise 'section_index not specified.' if section_index.nil?
  raise 'options_xml not specified.' if options_xml.empty?

  str_uri = "#{@base_uri}/sections/#{section_index}/pageSetup"
  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.post(signed_str_uri, options_xml, {:content_type=>'application/xml', :accept=>'application/json'}))['PageSetup']
end

#update_paragraph_run_font(para_id, run_index, font_name, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object

Update Font of a Run in a Word Document

@param number para_id ID of the paragraph.
@param number run_index Index of the paragraph run.
@param string font_name Name of the font.


407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'lib/Words/document.rb', line 407

def update_paragraph_run_font(para_id, run_index, font_name, folder_name = '', storage_type = 'Aspose', storage_name = '')
  raise 'para_id not specified.' if para_id.nil?
  raise 'run_index not specified.' if run_index.nil?
  raise 'font_name not specified.' if font_name.empty?

  str_uri = "#{@base_uri}/paragraphs/#{para_id}/runs/run_index/font"
  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)

  str_xml = "<Font><Name>#{font_name}</Name></Font>"

  response = RestClient.post(signed_str_uri, str_xml, {:accept=>'application/json'})
  json = JSON.parse(response)
  json['Code'] == 200 ? json['Font'] : false
end

#update_protection(old_password, new_password, protection_type = 'AllowOnlyComments', folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object

Modify Protection of the Word Document

@param string old_password Current document protection password.
@param string new_password New document protection password.
@param string protection_type Document protection type.


224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/Words/document.rb', line 224

def update_protection(old_password, new_password, protection_type = 'AllowOnlyComments', folder_name = '', storage_type = 'Aspose', storage_name = '')
  raise 'old_password not specified.' if old_password.empty?
  raise 'new_password not specified.' if new_password.empty?

  str_uri = "#{@base_uri}/protection"
  str_uri = Aspose::Cloud::Common::Utils.append_storage(str_uri,'',storage_name,storage_type)
  signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)

  data = Hash['Password' => old_password, 'NewPassword' => new_password, 'ProtectionType' => protection_type]
  json_data = JSON.generate(data)

  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