asposecloudsdk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,79 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+ module Aspose
4
+ module Cloud
5
+
6
+ module Words
7
+ class Converter
8
+ def initialize filename
9
+ @filename = filename
10
+ end
11
+
12
+ def convert save_format, storage_name='', folder=''
13
+
14
+ begin
15
+
16
+ if(@filename == '')
17
+ raise('Filename cannot be empty.')
18
+ end
19
+
20
+ if(storage_name.empty? == true)
21
+ str_uri = $product_uri + '/words/' + @filename + '?format=' + save_format
22
+ else
23
+ str_uri = $product_uri + '/words/' + @filename + '?format=' + save_format + '&storage='+storage_name+'&folder='+folder
24
+ end
25
+ signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
26
+
27
+ response_stream = RestClient.get(signed_str_uri,{:accept=>'application/json'})
28
+
29
+ valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)
30
+
31
+ if valid_output == ''
32
+ output_path = $out_put_location + Aspose::Cloud::Common::Utils.get_filename(@filename) + '.' + save_format
33
+ Aspose::Cloud::Common::Utils.save_file(response_stream,output_path)
34
+ return ''
35
+ else
36
+ return valid_output
37
+ end
38
+
39
+ rescue Exception=>e
40
+ print e
41
+ end
42
+
43
+ end
44
+ def convert_local_file input_path,output_path,output_format
45
+ begin
46
+ if input_path==''
47
+ raise 'Input File Name not specified'
48
+ end
49
+ if output_path == ''
50
+ raise 'Please Specify Output Path'
51
+ end
52
+ if output_format == ''
53
+ raise 'Please Specify Output Format'
54
+ end
55
+ str_uri =$product_uri + '/words/convert?format=' + output_format
56
+ signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
57
+ response_stream = Aspose::Cloud::Common::Utils.upload_file_binary(input_path, signed_uri)
58
+ v_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)
59
+ if v_output == ''
60
+ if output_format == 'html'
61
+ save_format = 'zip'
62
+ else
63
+ save_format = output_format
64
+ end
65
+ output_file = $out_put_location + Aspose::Cloud::Common::Utils.get_filename(input_path) + '.' + save_format
66
+ Aspose::Cloud::Common::Utils.save_file(response_stream, output_file)
67
+ return output_file
68
+ else
69
+ return v_output
70
+ end
71
+ rescue Exception => e
72
+ print e
73
+ end
74
+ end
75
+ end
76
+ end
77
+
78
+ end
79
+ end
@@ -0,0 +1,295 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+ module Aspose
4
+ module Cloud
5
+
6
+ module Words
7
+ class Document
8
+ def initialize(filename)
9
+ @filename = filename
10
+ end
11
+
12
+ =begin
13
+ Appends a list of documents to this one.
14
+ @param string append_docs
15
+ @param import_format_modes
16
+ @param source_folder
17
+ =end
18
+
19
+ def append_document append_docs, import_format_modes, source_folder
20
+ begin
21
+
22
+ if @filename == ''
23
+ raise 'Base file not specified.'
24
+ end
25
+
26
+ if append_docs.length != import_format_modes.length
27
+ raise 'Please specify complete documents and import format modes.'
28
+ end
29
+
30
+ str_uri = $product_uri + '/words/' + @filename + '/appendDocument'
31
+ signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
32
+
33
+ post_hash = Hash['DocumentEntries',append_docs];
34
+ json_data = post_hash.to_json
35
+
36
+ response_stream = RestClient.post(signed_str_uri,json_data,{:accept=>'application/json'})
37
+
38
+ valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)
39
+
40
+ if valid_output == ''
41
+ folder = Aspose::Cloud::AsposeStorage::Folder.new
42
+ if source_folder == ''
43
+ output_stream = folder.get_file(@filename)
44
+ else
45
+ output_stream = folder.get_file( source_folder + '/' + @filename)
46
+ end
47
+ output_path = $out_put_location + @filename
48
+ Aspose::Cloud::Common::Utils.save_file(output_stream,output_path)
49
+ return ''
50
+ else
51
+ return valid_output
52
+ end
53
+
54
+
55
+ rescue Exception=>e
56
+ print e
57
+ end
58
+ end
59
+
60
+ =begin
61
+ Get Resource Properties information like document source format, IsEncrypted, IsSigned and document properties
62
+ =end
63
+
64
+ def get_document_info
65
+
66
+ begin
67
+
68
+ if @filename == ''
69
+ raise 'Base file not specified.'
70
+ end
71
+
72
+ str_uri = $product_uri + '/words/' + @filename
73
+ signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
74
+
75
+ response_stream = RestClient.get(signed_str_uri,{:accept=>'application/json'})
76
+
77
+ stream_hash = JSON.parse(response_stream)
78
+
79
+ if(stream_hash['Code'] == 200)
80
+ return stream_hash['Document']
81
+ else
82
+ return false
83
+ end
84
+
85
+ rescue Exception=>e
86
+ print e
87
+ end
88
+
89
+ end
90
+
91
+ =begin
92
+ Get Resource Properties information like document source format, IsEncrypted, IsSigned and document properties
93
+ @param string property_name
94
+ =end
95
+
96
+ def get_property property_name
97
+
98
+ begin
99
+
100
+ if @filename == ''
101
+ raise 'Base file not specified.'
102
+ end
103
+
104
+ if property_name == ''
105
+ raise 'Property name not specified.'
106
+ end
107
+
108
+ str_uri = $product_uri + '/words/' + @filename + '/documentProperties/' + property_name
109
+ signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
110
+
111
+ response_stream = RestClient.get(signed_str_uri,{:accept=>'application/json'})
112
+
113
+ stream_hash = JSON.parse(response_stream)
114
+
115
+ if(stream_hash['Code'] == 200)
116
+ return stream_hash['DocumentProperty']
117
+ else
118
+ return false
119
+ end
120
+
121
+ rescue Exception=>e
122
+ print e
123
+ end
124
+
125
+ end
126
+
127
+ =begin
128
+ Set document property
129
+ @param string property_name
130
+ @param string property_value
131
+ =end
132
+
133
+ def set_property property_name, property_value
134
+
135
+ begin
136
+
137
+ if @filename == ''
138
+ raise 'Base file not specified.'
139
+ end
140
+
141
+ if property_name == ''
142
+ raise 'Property name not specified.'
143
+ end
144
+
145
+ if property_value == ''
146
+ raise 'Property value not specified.'
147
+ end
148
+
149
+ post_hash = { 'Value' => property_value}
150
+ json_data = post_hash.to_json
151
+
152
+ str_uri = $product_uri + '/words/' + @filename + '/documentProperties/' + property_name
153
+ signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
154
+
155
+ response_stream = RestClient.put(signed_str_uri,json_data,{:accept=>'application/json'})
156
+
157
+ stream_hash = JSON.parse(response_stream)
158
+
159
+ if(stream_hash['Code'] == 200)
160
+ return stream_hash['DocumentProperty']
161
+ else
162
+ return false
163
+ end
164
+
165
+ rescue Exception=>e
166
+ print e
167
+ end
168
+
169
+ end
170
+
171
+ =begin
172
+ Delete a document property
173
+ @param string property_name
174
+ =end
175
+
176
+ def delete_property property_name
177
+
178
+ begin
179
+
180
+ if @filename == ''
181
+ raise 'Base file not specified.'
182
+ end
183
+
184
+ if property_name == ''
185
+ raise 'Property name not specified.'
186
+ end
187
+
188
+ str_uri = $product_uri + '/words/' + @filename + '/documentProperties/' + property_name
189
+ signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
190
+
191
+ response_stream = RestClient.delete(signed_str_uri,{:accept=>'application/json'})
192
+
193
+ stream_hash = JSON.parse(response_stream)
194
+
195
+ if(stream_hash['Code'] == 200)
196
+ return true
197
+ else
198
+ return false
199
+ end
200
+
201
+ rescue Exception=>e
202
+ print e
203
+ end
204
+
205
+ end
206
+
207
+ =begin
208
+ Get Document's properties
209
+ =end
210
+
211
+ def get_properties
212
+
213
+ begin
214
+
215
+ if @filename == ''
216
+ raise 'Base file not specified.'
217
+ end
218
+
219
+ str_uri = $product_uri + '/words/' + @filename + '/documentProperties'
220
+ signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
221
+
222
+ response_stream = RestClient.get(signed_str_uri,{:accept=>'application/json'})
223
+
224
+ stream_hash = JSON.parse(response_stream)
225
+
226
+ if(stream_hash['Code'] == 200)
227
+ return stream_hash['DocumentProperties']['List']
228
+ else
229
+ return false
230
+ end
231
+
232
+ rescue Exception=>e
233
+ print e
234
+ end
235
+
236
+ end
237
+
238
+ =begin
239
+ Convert Word to different file format without using storage
240
+ @param string inputFile
241
+ @param string outputFilename
242
+ @param string outputFormat
243
+ =end
244
+
245
+ def convert_local_file input_file,output_filename,output_format
246
+ begin
247
+
248
+ if input_file == ''
249
+ raise('input file not specified')
250
+ end
251
+
252
+ if output_filename == ''
253
+ raise('output file not specified')
254
+ end
255
+
256
+ if output_format == ''
257
+ raise('output format not specified')
258
+ end
259
+
260
+ str_uri = $product_uri + '/words/convert?format=' + output_format
261
+ str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
262
+
263
+ response_stream = Aspose::Cloud::Common::Utils.upload_file_binary(input_file, str_signed_uri)
264
+
265
+ valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)
266
+
267
+ if valid_output == ''
268
+
269
+ if output_format == 'html'
270
+ saveformat = 'zip'
271
+ else
272
+ saveformat = output_format
273
+ end
274
+
275
+ if output_filename == ''
276
+ output_filename = Utils::get_filename(input_file) + '.' + saveformat
277
+ end
278
+
279
+ output_path = $out_put_location + output_filename
280
+ Aspose::Cloud::Common::Utils.save_file(response_stream,output_path)
281
+ return ''
282
+ else
283
+ return valid_output
284
+ end
285
+
286
+ rescue Exception=>e
287
+ print e
288
+ end
289
+ end
290
+
291
+ end
292
+ end
293
+
294
+ end
295
+ end
@@ -0,0 +1,318 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+ module Aspose
4
+ module Cloud
5
+ module Words
6
+ class Extractor
7
+ def initialize filename
8
+ @filename = filename
9
+ end
10
+
11
+ =begin
12
+ Gets Text items list from document
13
+ =end
14
+
15
+ def get_text
16
+
17
+ begin
18
+
19
+ if @filename == ''
20
+ raise 'Base file not specified.'
21
+ end
22
+
23
+ str_uri = $product_uri + '/words/' + @filename + '/textItems'
24
+ signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
25
+
26
+ response_stream = RestClient.get(signed_str_uri,{:accept=>'application/json'})
27
+
28
+ stream_hash = JSON.parse(response_stream)
29
+
30
+ if(stream_hash['Code'] == 200)
31
+ return stream_hash['TextItems']['List']
32
+ else
33
+ return false
34
+ end
35
+
36
+ rescue Exception=>e
37
+ print e
38
+ end
39
+
40
+ end
41
+
42
+ =begin
43
+ Get the OLE drawing object from document
44
+ @param number index
45
+ @param string ole_format
46
+ =end
47
+
48
+ def get_ole_data index, ole_format
49
+
50
+ begin
51
+
52
+ if @filename == ''
53
+ raise 'Base file not specified.'
54
+ end
55
+
56
+ if index == ''
57
+ raise 'Index not specified.'
58
+ end
59
+
60
+ if ole_format == ''
61
+ raise 'OLE Format not specified.'
62
+ end
63
+
64
+ str_uri = $product_uri + '/words/' + @filename + '/drawingObjects/' + index.to_s + '/oleData'
65
+ signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
66
+ response_stream = RestClient.get(signed_str_uri,{:accept=>'application/json'})
67
+
68
+ valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)
69
+
70
+ if valid_output == ''
71
+
72
+ output_path = $out_put_location + Aspose::Cloud::Common::Utils.get_filename(@filename) + '_' + index.to_s + '.' + ole_format
73
+ Aspose::Cloud::Common::Utils.save_file(response_stream,output_path)
74
+ return output_path
75
+ else
76
+ return valid_output
77
+ end
78
+
79
+ rescue Exception=>e
80
+ print e
81
+ end
82
+
83
+ end
84
+
85
+ =begin
86
+ Get the Image drawing object from document
87
+ @param number index
88
+ @param string render_format
89
+ =end
90
+
91
+ def get_image_data index, render_format
92
+
93
+ begin
94
+
95
+ if @filename == ''
96
+ raise 'Base file not specified.'
97
+ end
98
+
99
+ if index == ''
100
+ raise 'Index not specified.'
101
+ end
102
+
103
+ if render_format == ''
104
+ raise 'Render Format not specified.'
105
+ end
106
+
107
+ str_uri = $product_uri + '/words/' + @filename + '/drawingObjects/' + index.to_s + '/imagedata'
108
+ signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
109
+
110
+ response_stream = RestClient.get(signed_str_uri,{:accept=>'application/json'})
111
+
112
+ valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)
113
+
114
+ if valid_output == ''
115
+
116
+ output_path = $out_put_location + Aspose::Cloud::Common::Utils.get_filename(@filename) + '_' + index.to_s + '.' + render_format
117
+ Aspose::Cloud::Common::Utils.save_file(response_stream,output_path)
118
+ return output_path
119
+ else
120
+ return valid_output
121
+ end
122
+
123
+ rescue Exception=>e
124
+ print e
125
+ end
126
+
127
+ end
128
+
129
+ =begin
130
+ Convert drawing object to image
131
+ @param number index
132
+ @param string render_format
133
+ =end
134
+
135
+ def convert_drawing_object index, render_format
136
+
137
+ begin
138
+
139
+ if @filename == ''
140
+ raise 'Base file not specified.'
141
+ end
142
+
143
+ if index == ''
144
+ raise 'Index not specified.'
145
+ end
146
+
147
+ if render_format == ''
148
+ raise 'Render Format not specified.'
149
+ end
150
+
151
+ str_uri = $product_uri + '/words/' + @filename + '/drawingObjects/' + index.to_s + '/imagedata'
152
+ signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
153
+
154
+ response_stream = RestClient.get(signed_str_uri,{:accept=>'application/json'})
155
+
156
+ valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)
157
+
158
+ if valid_output == ''
159
+
160
+ output_path = $out_put_location + Aspose::Cloud::Common::Utils.get_filename(@filename) + '_' + index.to_s + '.' + render_format
161
+ Aspose::Cloud::Common::Utils.save_file(response_stream,output_path)
162
+ return output_path
163
+ else
164
+ return valid_output
165
+ end
166
+
167
+ rescue Exception=>e
168
+ print e
169
+ end
170
+
171
+ end
172
+
173
+ =begin
174
+ Get the List of drawing object from document
175
+ =end
176
+
177
+ def get_drawing_object_list
178
+
179
+ begin
180
+
181
+ if @filename == ''
182
+ raise 'Base file not specified.'
183
+ end
184
+
185
+ str_uri = $product_uri + '/words/' + @filename + '/drawingObjects'
186
+ signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
187
+
188
+ response_stream = RestClient.get(signed_str_uri,{:accept=>'application/json'})
189
+
190
+ stream_hash = JSON.parse(response_stream)
191
+
192
+ if(stream_hash['Code'] == 200)
193
+ return stream_hash['DrawingObjects']['List']
194
+ else
195
+ return false
196
+ end
197
+
198
+ rescue Exception=>e
199
+ print e
200
+ end
201
+
202
+ end
203
+
204
+ =begin
205
+ Get the drawing object from document
206
+ @param string object_uri
207
+ @param string output_path
208
+ =end
209
+
210
+ def get_drawing_object object_uri, output_path
211
+
212
+ begin
213
+
214
+ if @filename == ''
215
+ raise 'Base file not specified.'
216
+ end
217
+
218
+ if object_uri == ''
219
+ raise 'Object URI not specified.'
220
+ end
221
+
222
+ if output_path == ''
223
+ raise 'Output path not specified.'
224
+ end
225
+
226
+ url_arr = object_uri.split('/')
227
+ object_index = url_arr.at(-1)
228
+
229
+ str_uri = object_uri
230
+ signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
231
+
232
+ response_stream = RestClient.get(signed_str_uri,{:accept=>'application/json'})
233
+
234
+ stream_hash = JSON.parse(response_stream)
235
+
236
+ if(stream_hash['Code'] == 200)
237
+
238
+ if stream_hash['DrawingObject']['ImageDataLink'] != ''
239
+ str_uri = str_uri + '/imageData'
240
+ output_path = output_path + '\\DrawingObject_' + object_index.to_s + '.jpeg'
241
+ elsif stream_hash['DrawingObject']['OLEDataLink'] != ''
242
+ str_uri = str_uri + '/oleData'
243
+ output_path = output_path + '\\DrawingObject_' + object_index.to_s + '.xlsx'
244
+ else
245
+ str_uri = str_uri + '?format=jpeg'
246
+ output_path = output_path + '\\DrawingObject_' + object_index.to_s + '.jpeg'
247
+ end
248
+
249
+ signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
250
+
251
+ valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)
252
+
253
+ if valid_output == ''
254
+
255
+ # output_path = $out_put_location + Aspose::Cloud::Common::Utils.get_filename(@filename) + '_' + index.to_s + '.' + render_format
256
+ Aspose::Cloud::Common::Utils.save_file(response_stream,output_path)
257
+ return output_path
258
+ else
259
+ return valid_output
260
+ end
261
+
262
+ else
263
+ return false
264
+ end
265
+
266
+ rescue Exception=>e
267
+ print e
268
+ end
269
+
270
+ end
271
+
272
+ =begin
273
+ Get the List of drawing object from document
274
+ @param string output_path
275
+ =end
276
+
277
+ def get_drawing_objects output_path
278
+
279
+ begin
280
+
281
+ if @filename == ''
282
+ raise 'Base file not specified.'
283
+ end
284
+
285
+ if output_path == ''
286
+ raise 'Output path not specified.'
287
+ end
288
+
289
+ str_uri = $product_uri + '/words/' + @filename + '/drawingObjects'
290
+ signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
291
+
292
+ response_stream = RestClient.get(signed_str_uri,{:accept=>'application/json'})
293
+
294
+ stream_hash = JSON.parse(response_stream)
295
+
296
+ if(stream_hash['Code'] == 200)
297
+
298
+ stream_hash['DrawingObjects']['List'].each { |object|
299
+
300
+ self.get_drawing_object(object['link']['Href'], output_path)
301
+
302
+ }
303
+
304
+ else
305
+ return false
306
+ end
307
+
308
+ rescue Exception=>e
309
+ print e
310
+ end
311
+
312
+ end
313
+
314
+ end
315
+ end
316
+
317
+ end
318
+ end