aspose_html 1.0.0

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.
Files changed (95) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +12 -0
  3. data/Gemfile.lock +92 -0
  4. data/LICENSE +21 -0
  5. data/README.md +181 -0
  6. data/Rakefile +8 -0
  7. data/aspose_html.gemspec +58 -0
  8. data/docs/ConversionApi.md +837 -0
  9. data/docs/DocumentApi.md +386 -0
  10. data/docs/OcrApi.md +128 -0
  11. data/docs/SummarizationApi.md +111 -0
  12. data/docs/TranslationApi.md +126 -0
  13. data/docs/storage/DiscUsage.md +9 -0
  14. data/docs/storage/DiscUsageResponse.md +10 -0
  15. data/docs/storage/FileApi.md +240 -0
  16. data/docs/storage/FileDetail.md +13 -0
  17. data/docs/storage/FileDetailsResponse.md +10 -0
  18. data/docs/storage/FileExist.md +9 -0
  19. data/docs/storage/FileExistResponse.md +10 -0
  20. data/docs/storage/FileVersion.md +15 -0
  21. data/docs/storage/FileVersionsResponse.md +10 -0
  22. data/docs/storage/FolderApi.md +229 -0
  23. data/docs/storage/MessageResponse.md +9 -0
  24. data/docs/storage/MoveFileResponse.md +9 -0
  25. data/docs/storage/MoveFolderResponse.md +9 -0
  26. data/docs/storage/RemoveFileResponse.md +9 -0
  27. data/docs/storage/RemoveFolderResponse.md +9 -0
  28. data/docs/storage/StorageApi.md +217 -0
  29. data/docs/storage/StorageExistResponse.md +10 -0
  30. data/lib/aspose_html.rb +68 -0
  31. data/lib/aspose_html/api/html_api.rb +1900 -0
  32. data/lib/aspose_html/api/storage_api.rb +774 -0
  33. data/lib/aspose_html/api_client.rb +386 -0
  34. data/lib/aspose_html/api_error.rb +54 -0
  35. data/lib/aspose_html/configuration.rb +175 -0
  36. data/lib/aspose_html/models/disc_usage.rb +223 -0
  37. data/lib/aspose_html/models/disc_usage_response.rb +260 -0
  38. data/lib/aspose_html/models/file_detail.rb +254 -0
  39. data/lib/aspose_html/models/file_details_response.rb +262 -0
  40. data/lib/aspose_html/models/file_exist.rb +223 -0
  41. data/lib/aspose_html/models/file_exist_response.rb +274 -0
  42. data/lib/aspose_html/models/file_version.rb +273 -0
  43. data/lib/aspose_html/models/file_versions_response.rb +262 -0
  44. data/lib/aspose_html/models/message_response.rb +251 -0
  45. data/lib/aspose_html/models/move_file_response.rb +251 -0
  46. data/lib/aspose_html/models/move_folder_response.rb +251 -0
  47. data/lib/aspose_html/models/remove_file_response.rb +251 -0
  48. data/lib/aspose_html/models/remove_folder_response.rb +251 -0
  49. data/lib/aspose_html/models/storage_exist_response.rb +260 -0
  50. data/lib/aspose_html/version.rb +31 -0
  51. data/spec/api/html_api_spec.rb +971 -0
  52. data/spec/api/model_spec.rb +622 -0
  53. data/spec/api/storage_api_spec.rb +596 -0
  54. data/spec/spec_helper.rb +169 -0
  55. data/testdata/test.txt +1 -0
  56. data/testdata/test1.html +19 -0
  57. data/testdata/test1.html.zip +0 -0
  58. data/testdata/test2.html +46 -0
  59. data/testdata/test2.html.zip +0 -0
  60. data/testdata/test3.html.zip +0 -0
  61. data/testdata/test4.html.zip +0 -0
  62. data/testdata/test_download.jpg +0 -0
  63. data/testdata/test_en.html +46 -0
  64. data/testdata/test_for_delete.html +46 -0
  65. data/testdata/test_for_move.html +46 -0
  66. data/testdata/test_get_doc.zip +0 -0
  67. data/testdata/test_ocr.jpg +0 -0
  68. data/testdata/test_ocr.png +0 -0
  69. data/testdata/test_put_create.html +19 -0
  70. data/testdata/test_put_create.jpg +0 -0
  71. data/testresult/Convert_html.bmp +0 -0
  72. data/testresult/Convert_html.pdf +0 -0
  73. data/testresult/Convert_html.xps +0 -0
  74. data/testresult/Convert_url.pdf +0 -0
  75. data/testresult/Convert_url.png +0 -0
  76. data/testresult/Convert_url.xps +0 -0
  77. data/testresult/Get_document.zip +0 -0
  78. data/testresult/Get_fragment_css_by_url.html +447 -0
  79. data/testresult/Get_fragment_doc.html +9 -0
  80. data/testresult/Get_fragment_doc_css.html +9 -0
  81. data/testresult/Get_fragment_xpath_by_url.html +38 -0
  82. data/testresult/Get_images_doc.zip +0 -0
  83. data/testresult/Get_images_from_url.zip +0 -0
  84. data/testresult/Keyword_by_doc.json +1 -0
  85. data/testresult/Keyword_by_url.json +1 -0
  86. data/testresult/Recognize_en_png.html +10 -0
  87. data/testresult/Translate_url_en_fr.zip +0 -0
  88. data/testresult/putTest.pdf +0 -0
  89. data/testresult/putTest.png +0 -0
  90. data/testresult/putTest.xps +0 -0
  91. data/testresult/putTestDoc.pdf +0 -0
  92. data/testresult/putTestDoc.tiff +0 -0
  93. data/testresult/putTestDoc.xps +0 -0
  94. data/testresult/test_download.jpg +0 -0
  95. metadata +320 -0
@@ -0,0 +1,31 @@
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ --------------------------------------------------------------------------------------------------------------------
4
+ <copyright company="Aspose" file="version.rb">
5
+ </copyright>
6
+ Copyright (c) 2018 Aspose.HTML for Cloud
7
+ <summary>
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
25
+ </summary>
26
+ --------------------------------------------------------------------------------------------------------------------
27
+ =end
28
+
29
+ module AsposeHtml
30
+ VERSION = "1.0.0"
31
+ end
@@ -0,0 +1,971 @@
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ --------------------------------------------------------------------------------------------------------------------
4
+ <copyright company="Aspose" file="html_api_spec.rb">
5
+ </copyright>
6
+ Copyright (c) 2018 Aspose.HTML for Cloud
7
+ <summary>
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
25
+ </summary>
26
+ --------------------------------------------------------------------------------------------------------------------
27
+ =end
28
+
29
+ require 'spec_helper'
30
+ require 'json'
31
+
32
+ describe 'Test html_api' do
33
+ before(:all) do
34
+ # run before all tests
35
+ @instance = AsposeHtml::HtmlApi.new CONFIG
36
+ end
37
+
38
+ describe 'test an instance of HtmlApi' do
39
+ it 'should create an instance of HtmlApi' do
40
+ expect(@instance).to be_instance_of(AsposeHtml::HtmlApi)
41
+ end
42
+ end
43
+
44
+ #################################################
45
+ # Conversion API
46
+ #################################################
47
+
48
+ # unit tests for get_convert_document_to_image
49
+ # Convert the HTML document from the storage by its name to the specified image format.
50
+ #
51
+ # @param name Document name.
52
+ # @param out_format Resulting image format.
53
+ # @param [Hash] opts the optional parameters
54
+ # @option opts [Integer] :width Resulting image width.
55
+ # @option opts [Integer] :height Resulting image height.
56
+ # @option opts [Integer] :left_margin Left resulting image margin.
57
+ # @option opts [Integer] :right_margin Right resulting image margin.
58
+ # @option opts [Integer] :top_margin Top resulting image margin.
59
+ # @option opts [Integer] :bottom_margin Bottom resulting image margin.
60
+ # @option opts [Integer] :x_resolution Horizontal resolution of resulting image.
61
+ # @option opts [Integer] :y_resolution Vertical resolution of resulting image.
62
+ # @option opts [String] :folder The source document folder.
63
+ # @option opts [String] :storage The source document storage.
64
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
65
+ describe 'get_convert_document_to_image test' do
66
+ it "Convert html to bmp" do
67
+ name = "test1.html"
68
+ out_format = "bmp"
69
+ opts = {
70
+ width: 800,
71
+ height: 1000,
72
+ left_margin: 30,
73
+ right_margin: 30,
74
+ top_margin: 50,
75
+ bottom_margin: 50,
76
+ x_resolution: 300,
77
+ y_resolution: 300,
78
+ folder: "HtmlTestDoc",
79
+ storage: nil
80
+ }
81
+
82
+ # Upload file to server
83
+ res = upload_file(name)
84
+ expect(res.code).to eql(200)
85
+
86
+ answer = @instance.get_convert_document_to_image(name, out_format, opts)
87
+
88
+ expect(answer).to be_an_instance_of Hash
89
+ expect(answer[:file]).to be_an_instance_of File
90
+ expect(answer[:status]).to eql(200)
91
+
92
+ # Save to test dir
93
+ save_to_test_dir(answer, "Convert_html.bmp")
94
+ end
95
+ end
96
+
97
+ # unit tests for get_convert_document_to_image_by_url
98
+ # Convert the HTML page from the web by its URL to the specified image format.
99
+ #
100
+ # @param source_url Source page URL.
101
+ # @param out_format Resulting image format.
102
+ # @param [Hash] opts the optional parameters
103
+ # @option opts [Integer] :width Resulting image width.
104
+ # @option opts [Integer] :height Resulting image height.
105
+ # @option opts [Integer] :left_margin Left resulting image margin.
106
+ # @option opts [Integer] :right_margin Right resulting image margin.
107
+ # @option opts [Integer] :top_margin Top resulting image margin.
108
+ # @option opts [Integer] :bottom_margin Bottom resulting image margin.
109
+ # @option opts [Integer] :x_resolution Horizontal resolution of resulting image.
110
+ # @option opts [Integer] :y_resolution Vertical resolution of resulting image.
111
+ # @option opts [String] :folder The document folder.
112
+ # @option opts [String] :storage The document storage.
113
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
114
+ describe 'get_convert_document_to_image_by_url test' do
115
+ it "Convert url to png" do
116
+ source_url = "https://stallman.org/articles/anonymous-payments-thru-phones.html"
117
+ out_format = "png"
118
+ opts = {
119
+ width: 800,
120
+ height: 1000,
121
+ left_margin: 30,
122
+ right_margin: 30,
123
+ top_margin: 50,
124
+ bottom_margin: 50,
125
+ x_resolution: 300,
126
+ y_resolution: 300,
127
+ folder: "HtmlTestDoc",
128
+ storage: nil
129
+ }
130
+
131
+ answer = @instance.get_convert_document_to_image_by_url(source_url, out_format, opts)
132
+
133
+ expect(answer).to be_an_instance_of Hash
134
+ expect(answer[:file]).to be_an_instance_of File
135
+ expect(answer[:status]).to eql(200)
136
+
137
+ # Save to test dir
138
+ save_to_test_dir(answer, "Convert_url.png")
139
+ end
140
+ end
141
+
142
+ # unit tests for get_convert_document_to_pdf
143
+ # Convert the HTML document from the storage by its name to PDF.
144
+ #
145
+ # @param name Document name.
146
+ # @param [Hash] opts the optional parameters
147
+ # @option opts [Integer] :width Resulting image width.
148
+ # @option opts [Integer] :height Resulting image height.
149
+ # @option opts [Integer] :left_margin Left resulting image margin.
150
+ # @option opts [Integer] :right_margin Right resulting image margin.
151
+ # @option opts [Integer] :top_margin Top resulting image margin.
152
+ # @option opts [Integer] :bottom_margin Bottom resulting image margin.
153
+ # @option opts [String] :folder The document folder.
154
+ # @option opts [String] :storage The document storage.
155
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
156
+ describe 'get_convert_document_to_pdf test' do
157
+ it "Convert doc to pdf" do
158
+ name = "test1.html"
159
+ opts = {
160
+ width: 800,
161
+ height: 1000,
162
+ left_margin: 30,
163
+ right_margin: 30,
164
+ top_margin: 50,
165
+ bottom_margin: 50,
166
+ folder: "HtmlTestDoc",
167
+ storage: nil
168
+ }
169
+
170
+ # Upload file to server
171
+ res = upload_file(name)
172
+ expect(res.code).to eql(200)
173
+
174
+ answer = @instance.get_convert_document_to_pdf(name, opts)
175
+
176
+ expect(answer).to be_an_instance_of Hash
177
+ expect(answer[:file]).to be_an_instance_of File
178
+ expect(answer[:status]).to eql(200)
179
+
180
+ # Save to test dir
181
+ save_to_test_dir(answer, "Convert_html.pdf")
182
+ end
183
+ end
184
+
185
+ # unit tests for get_convert_document_to_pdf_by_url
186
+ # Convert the HTML page from the web by its URL to PDF.
187
+ #
188
+ # @param source_url Source page URL.
189
+ # @param [Hash] opts the optional parameters
190
+ # @option opts [Integer] :width Resulting image width.
191
+ # @option opts [Integer] :height Resulting image height.
192
+ # @option opts [Integer] :left_margin Left resulting image margin.
193
+ # @option opts [Integer] :right_margin Right resulting image margin.
194
+ # @option opts [Integer] :top_margin Top resulting image margin.
195
+ # @option opts [Integer] :bottom_margin Bottom resulting image margin.
196
+ # @option opts [String] :folder The document folder.
197
+ # @option opts [String] :storage The document storage.
198
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
199
+ describe 'get_convert_document_to_pdf_by_url test' do
200
+ it "Convert url to pdf" do
201
+ source_url = "https://stallman.org/articles/anonymous-payments-thru-phones.html"
202
+ opts = {
203
+ width: 800,
204
+ height: 1000,
205
+ left_margin: 30,
206
+ right_margin: 30,
207
+ top_margin: 50,
208
+ bottom_margin: 50,
209
+ folder: "HtmlTestDoc",
210
+ storage: nil
211
+ }
212
+
213
+ answer = @instance.get_convert_document_to_pdf_by_url(source_url, opts)
214
+
215
+ expect(answer).to be_an_instance_of Hash
216
+ expect(answer[:file]).to be_an_instance_of File
217
+ expect(answer[:status]).to eql(200)
218
+
219
+ # Save to test dir
220
+ save_to_test_dir(answer, "Convert_url.pdf")
221
+ end
222
+ end
223
+
224
+ # unit tests for get_convert_document_to_xps
225
+ # Convert the HTML document from the storage by its name to XPS.
226
+ #
227
+ # @param name Document name.
228
+ # @param [Hash] opts the optional parameters
229
+ # @option opts [Integer] :width Resulting image width.
230
+ # @option opts [Integer] :height Resulting image height.
231
+ # @option opts [Integer] :left_margin Left resulting image margin.
232
+ # @option opts [Integer] :right_margin Right resulting image margin.
233
+ # @option opts [Integer] :top_margin Top resulting image margin.
234
+ # @option opts [Integer] :bottom_margin Bottom resulting image margin.
235
+ # @option opts [String] :folder The document folder.
236
+ # @option opts [String] :storage The document storage.
237
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
238
+ describe 'get_convert_document_to_xps test' do
239
+ it "Convert document to xps" do
240
+ name = "test1.html"
241
+ opts = {
242
+ width: 800,
243
+ height: 1000,
244
+ left_margin: 30,
245
+ right_margin: 30,
246
+ top_margin: 50,
247
+ bottom_margin: 50,
248
+ folder: "HtmlTestDoc",
249
+ storage: nil
250
+ }
251
+
252
+ # Upload file to server
253
+ res = upload_file(name)
254
+ expect(res.code).to eql(200)
255
+
256
+ answer = @instance.get_convert_document_to_xps(name, opts)
257
+
258
+ expect(answer).to be_an_instance_of Hash
259
+ expect(answer[:file]).to be_an_instance_of File
260
+ expect(answer[:status]).to eql(200)
261
+
262
+ # Save to test dir
263
+ save_to_test_dir(answer, "Convert_html.xps")
264
+ end
265
+ end
266
+
267
+ # unit tests for get_convert_document_to_xps_by_url
268
+ # Convert the HTML page from the web by its URL to XPS.
269
+ #
270
+ # @param source_url Source page URL.
271
+ # @param [Hash] opts the optional parameters
272
+ # @option opts [Integer] :width Resulting image width.
273
+ # @option opts [Integer] :height Resulting image height.
274
+ # @option opts [Integer] :left_margin Left resulting image margin.
275
+ # @option opts [Integer] :right_margin Right resulting image margin.
276
+ # @option opts [Integer] :top_margin Top resulting image margin.
277
+ # @option opts [Integer] :bottom_margin Bottom resulting image margin.
278
+ # @option opts [String] :folder The document folder.
279
+ # @option opts [String] :storage The document storage.
280
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
281
+ describe 'get_convert_document_to_xps_by_url test' do
282
+ it "Convert url to xps" do
283
+ source_url = "https://stallman.org/articles/anonymous-payments-thru-phones.html"
284
+ opts = {
285
+ width: 800,
286
+ height: 1000,
287
+ left_margin: 30,
288
+ right_margin: 30,
289
+ top_margin: 50,
290
+ bottom_margin: 50,
291
+ folder: "HtmlTestDoc",
292
+ storage: nil
293
+ }
294
+
295
+ answer = @instance.get_convert_document_to_xps_by_url(source_url, opts)
296
+
297
+ expect(answer).to be_an_instance_of Hash
298
+ expect(answer[:file]).to be_an_instance_of File
299
+ expect(answer[:status]).to eql(200)
300
+
301
+ # Save to test dir
302
+ save_to_test_dir(answer, "Convert_url.xps")
303
+ end
304
+ end
305
+
306
+ # unit tests for put_convert_document_in_request_to_image
307
+ # Converts the HTML document (in request content) to the specified image format and uploads resulting file to storage.
308
+ #
309
+ # @param out_path Full resulting filename (ex. /folder1/folder2/result.jpg)
310
+ # @param out_format
311
+ # @param file A file to be converted.
312
+ # @param [Hash] opts the optional parameters
313
+ # @option opts [Integer] :width Resulting document page width in points (1/96 inch).
314
+ # @option opts [Integer] :height Resulting document page height in points (1/96 inch).
315
+ # @option opts [Integer] :left_margin Left resulting document page margin in points (1/96 inch).
316
+ # @option opts [Integer] :right_margin Right resulting document page margin in points (1/96 inch).
317
+ # @option opts [Integer] :top_margin Top resulting document page margin in points (1/96 inch).
318
+ # @option opts [Integer] :bottom_margin Bottom resulting document page margin in points (1/96 inch).
319
+ # @option opts [Integer] :resolution Resolution of resulting image. Default is 96 dpi.
320
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
321
+ describe 'put_convert_document_in_request_to_image test' do
322
+ it "Upload and convert html to png" do
323
+ name = "putTest.png"
324
+ out_path = "HtmlTestDoc/putTest.png"
325
+ out_format = "png"
326
+ file = __dir__ + '/../../testdata/test1.html'
327
+ opts = {
328
+ width: 800,
329
+ height: 1000,
330
+ left_margin: 30,
331
+ right_margin: 30,
332
+ top_margin: 50,
333
+ bottom_margin: 50,
334
+ resolution: 300
335
+ }
336
+
337
+ answer = @instance.put_convert_document_in_request_to_image(out_path, out_format, file, opts)
338
+
339
+ expect(answer[:status]).to eql(200)
340
+
341
+ #Download converted file from storage
342
+ res = download_file(name)
343
+
344
+ expect(res[:code]).to eql(200)
345
+ expect(res[:status]).to eql("OK")
346
+ expect(res[:file]).to be_an_instance_of File
347
+
348
+ #Move to test folder
349
+ save_to_test_dir(res, name)
350
+
351
+ expect(answer[:status]).to eql(200)
352
+ end
353
+ end
354
+
355
+ # unit tests for put_convert_document_in_request_to_pdf
356
+ # Converts the HTML document (in request content) to PDF and uploads resulting file to storage.
357
+ #
358
+ # @param out_path Full resulting filename (ex. /folder1/folder2/result.pdf)
359
+ # @param file A file to be converted.
360
+ # @param [Hash] opts the optional parameters
361
+ # @option opts [Integer] :width Resulting document page width in points (1/96 inch).
362
+ # @option opts [Integer] :height Resulting document page height in points (1/96 inch).
363
+ # @option opts [Integer] :left_margin Left resulting document page margin in points (1/96 inch).
364
+ # @option opts [Integer] :right_margin Right resulting document page margin in points (1/96 inch).
365
+ # @option opts [Integer] :top_margin Top resulting document page margin in points (1/96 inch).
366
+ # @option opts [Integer] :bottom_margin Bottom resulting document page margin in points (1/96 inch).
367
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
368
+ describe 'put_convert_document_in_request_to_pdf test' do
369
+ it "Upload and convert html to pdf" do
370
+ name = "putTest.pdf"
371
+ out_path = "HtmlTestDoc/putTest.pdf"
372
+ file = __dir__ + '/../../testdata/test1.html'
373
+ opts = {
374
+ width: 800,
375
+ height: 1000,
376
+ left_margin: 30,
377
+ right_margin: 30,
378
+ top_margin: 50,
379
+ bottom_margin: 50
380
+ }
381
+
382
+ answer = @instance.put_convert_document_in_request_to_pdf(out_path, file, opts)
383
+
384
+ expect(answer[:status]).to eql(200)
385
+
386
+ #Download converted file from storage
387
+ res = download_file(name)
388
+
389
+ expect(res[:code]).to eql(200)
390
+ expect(res[:status]).to eql("OK")
391
+ expect(res[:file]).to be_an_instance_of File
392
+
393
+ #Move to test folder
394
+ save_to_test_dir(res, name)
395
+
396
+ expect(answer[:status]).to eql(200)
397
+ end
398
+ end
399
+
400
+ # unit tests for put_convert_document_in_request_to_xps
401
+ # Converts the HTML document (in request content) to XPS and uploads resulting file to storage.
402
+ #
403
+ # @param out_path Full resulting filename (ex. /folder1/folder2/result.xps)
404
+ # @param file A file to be converted.
405
+ # @param [Hash] opts the optional parameters
406
+ # @option opts [Integer] :width Resulting document page width in points (1/96 inch).
407
+ # @option opts [Integer] :height Resulting document page height in points (1/96 inch).
408
+ # @option opts [Integer] :left_margin Left resulting document page margin in points (1/96 inch).
409
+ # @option opts [Integer] :right_margin Right resulting document page margin in points (1/96 inch).
410
+ # @option opts [Integer] :top_margin Top resulting document page margin in points (1/96 inch).
411
+ # @option opts [Integer] :bottom_margin Bottom resulting document page margin in points (1/96 inch).
412
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
413
+ describe 'put_convert_document_in_request_to_xps test' do
414
+ it "Upload and convert html to xps" do
415
+ name = "putTest.xps"
416
+ out_path = "HtmlTestDoc/putTest.xps"
417
+ file = __dir__ + '/../../testdata/test1.html'
418
+ opts = {
419
+ width: 800,
420
+ height: 1000,
421
+ left_margin: 30,
422
+ right_margin: 30,
423
+ top_margin: 50,
424
+ bottom_margin: 50
425
+ }
426
+
427
+ answer = @instance.put_convert_document_in_request_to_xps(out_path, file, opts)
428
+
429
+ expect(answer[:status]).to eql(200)
430
+
431
+ #Download converted file from storage
432
+ res = download_file(name)
433
+
434
+ expect(res[:code]).to eql(200)
435
+ expect(res[:status]).to eql("OK")
436
+ expect(res[:file]).to be_an_instance_of File
437
+
438
+ #Move to test folder
439
+ save_to_test_dir(res, name)
440
+
441
+ expect(answer[:status]).to eql(200)
442
+ end
443
+ end
444
+
445
+ # unit tests for put_convert_document_to_image
446
+ # Converts the HTML document (located on storage) to the specified image format and uploads resulting file to storage.
447
+ #
448
+ # @param name Document name.
449
+ # @param out_path Full resulting filename (ex. /folder1/folder2/result.jpg)
450
+ # @param out_format
451
+ # @param [Hash] opts the optional parameters
452
+ # @option opts [Integer] :width Resulting document page width in points (1/96 inch).
453
+ # @option opts [Integer] :height Resulting document page height in points (1/96 inch).
454
+ # @option opts [Integer] :left_margin Left resulting document page margin in points (1/96 inch).
455
+ # @option opts [Integer] :right_margin Right resulting document page margin in points (1/96 inch).
456
+ # @option opts [Integer] :top_margin Top resulting document page margin in points (1/96 inch).
457
+ # @option opts [Integer] :bottom_margin Bottom resulting document page margin in points (1/96 inch).
458
+ # @option opts [Integer] :resolution Resolution of resulting image. Default is 96 dpi.
459
+ # @option opts [String] :folder The source document folder.
460
+ # @option opts [String] :storage The source and resulting document storage.
461
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
462
+ describe 'put_convert_document_to_image test' do
463
+ it "Convert html to tiff in storage" do
464
+
465
+ # Already in the storage
466
+ name = "test1.html"
467
+ result_name = "putTestDoc.tiff"
468
+ out_path = "HtmlTestDoc/putTestDoc.tiff"
469
+ out_format = "tiff"
470
+ opts = {
471
+ width: 800,
472
+ height: 1000,
473
+ left_margin: 30,
474
+ right_margin: 30,
475
+ top_margin: 50,
476
+ bottom_margin: 50,
477
+ resolution: 300,
478
+ folder: "HtmlTestDoc",
479
+ storage: nil
480
+ }
481
+
482
+ answer = @instance.put_convert_document_to_image(name, out_path, out_format, opts)
483
+
484
+ expect(answer[:status]).to eql(200)
485
+
486
+ #Download converted file from storage
487
+ res = download_file(result_name)
488
+
489
+ expect(res[:code]).to eql(200)
490
+ expect(res[:status]).to eql("OK")
491
+ expect(res[:file]).to be_an_instance_of File
492
+
493
+ #Move to test folder
494
+ save_to_test_dir(res, result_name)
495
+
496
+ expect(answer[:status]).to eql(200)
497
+ end
498
+ end
499
+
500
+ # unit tests for put_convert_document_to_pdf
501
+ # Converts the HTML document (located on storage) to PDF and uploads resulting file to storage.
502
+ #
503
+ # @param name Document name.
504
+ # @param out_path Full resulting filename (ex. /folder1/folder2/result.pdf)
505
+ # @param [Hash] opts the optional parameters
506
+ # @option opts [Integer] :width Resulting document page width in points (1/96 inch).
507
+ # @option opts [Integer] :height Resulting document page height in points (1/96 inch).
508
+ # @option opts [Integer] :left_margin Left resulting document page margin in points (1/96 inch).
509
+ # @option opts [Integer] :right_margin Right resulting document page margin in points (1/96 inch).
510
+ # @option opts [Integer] :top_margin Top resulting document page margin in points (1/96 inch).
511
+ # @option opts [Integer] :bottom_margin Bottom resulting document page margin in points (1/96 inch).
512
+ # @option opts [String] :folder The source document folder.
513
+ # @option opts [String] :storage The source and resulting document storage.
514
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
515
+ describe 'put_convert_document_to_pdf test' do
516
+ it "Convert html to pdf in storage" do
517
+
518
+ # Already in the storage
519
+ name = "test1.html"
520
+ result_name = "putTestDoc.pdf"
521
+ out_path = "HtmlTestDoc/putTestDoc.pdf"
522
+ opts = {
523
+ width: 800,
524
+ height: 1000,
525
+ left_margin: 30,
526
+ right_margin: 30,
527
+ top_margin: 50,
528
+ bottom_margin: 50,
529
+ folder: "HtmlTestDoc",
530
+ storage: nil
531
+ }
532
+
533
+ answer = @instance.put_convert_document_to_pdf(name, out_path, opts)
534
+
535
+ expect(answer[:status]).to eql(200)
536
+
537
+ #Download converted file from storage
538
+ res = download_file(result_name)
539
+
540
+ expect(res[:code]).to eql(200)
541
+ expect(res[:status]).to eql("OK")
542
+ expect(res[:file]).to be_an_instance_of File
543
+
544
+ #Move to test folder
545
+ save_to_test_dir(res, result_name)
546
+
547
+ expect(answer[:status]).to eql(200)
548
+ end
549
+ end
550
+
551
+ # unit tests for put_convert_document_to_xps
552
+ # Converts the HTML document (located on storage) to XPS and uploads resulting file to storage.
553
+ #
554
+ # @param name Document name.
555
+ # @param out_path Full resulting filename (ex. /folder1/folder2/result.xps)
556
+ # @param [Hash] opts the optional parameters
557
+ # @option opts [Integer] :width Resulting document page width in points (1/96 inch).
558
+ # @option opts [Integer] :height Resulting document page height in points (1/96 inch).
559
+ # @option opts [Integer] :left_margin Left resulting document page margin in points (1/96 inch).
560
+ # @option opts [Integer] :right_margin Right resulting document page margin in points (1/96 inch).
561
+ # @option opts [Integer] :top_margin Top resulting document page margin in points (1/96 inch).
562
+ # @option opts [Integer] :bottom_margin Bottom resulting document page margin in points (1/96 inch).
563
+ # @option opts [String] :folder The source document folder.
564
+ # @option opts [String] :storage The source and resulting document storage.
565
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
566
+ describe 'put_convert_document_to_xps test' do
567
+ it "Convert html to xps in storage" do
568
+
569
+ # Already in the storage
570
+ name = "test1.html"
571
+ result_name = "putTestDoc.xps"
572
+ out_path = "HtmlTestDoc/putTestDoc.xps"
573
+ opts = {
574
+ width: 800,
575
+ height: 1000,
576
+ left_margin: 30,
577
+ right_margin: 30,
578
+ top_margin: 50,
579
+ bottom_margin: 50,
580
+ folder: "HtmlTestDoc",
581
+ storage: nil
582
+ }
583
+
584
+ answer = @instance.put_convert_document_to_xps(name, out_path, opts)
585
+
586
+ expect(answer[:status]).to eql(200)
587
+
588
+ #Download converted file from storage
589
+ res = download_file(result_name)
590
+
591
+ expect(res[:code]).to eql(200)
592
+ expect(res[:status]).to eql("OK")
593
+ expect(res[:file]).to be_an_instance_of File
594
+
595
+ #Move to test folder
596
+ save_to_test_dir(res, result_name)
597
+
598
+ expect(answer[:status]).to eql(200)
599
+ end
600
+ end
601
+
602
+ #################################################
603
+ # Document API
604
+ #################################################
605
+
606
+ # unit tests for get_document
607
+ # Return the HTML document by the name from default or specified storage.
608
+ #
609
+ # @param name The document name.
610
+ # @param [Hash] opts the optional parameters
611
+ # @option opts [String] :storage The document folder
612
+ # @option opts [String] :folder The document folder.
613
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
614
+ describe 'get_document test' do
615
+ it "Get html document" do
616
+ file_name = "test_get_doc.zip"
617
+ opts = {folder: "HtmlTestDoc", storage: nil}
618
+
619
+ # Upload file to server
620
+ res = upload_file(file_name)
621
+ expect(res.code).to eql(200)
622
+
623
+ answer = @instance.get_document(file_name, opts)
624
+
625
+ expect(answer).to be_an_instance_of Hash
626
+ expect(answer[:file]).to be_an_instance_of File
627
+ expect(answer[:status]).to eql(200)
628
+
629
+ # Save to test dir
630
+ save_to_test_dir(answer, "Get_document.zip")
631
+ end
632
+ end
633
+
634
+ # unit tests for get_document_fragment_by_x_path
635
+ # Return list of HTML fragments matching the specified XPath query.
636
+ #
637
+ # @param name The document name.
638
+ # @param x_path XPath query string.
639
+ # @param out_format Output format. Possible values: &#39;plain&#39; and &#39;json&#39;.
640
+ # @param [Hash] opts the optional parameters
641
+ # @option opts [String] :storage The document storage.
642
+ # @option opts [String] :folder The document folder.
643
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
644
+ describe 'get_document_fragment_by_x_path test' do
645
+ it "Get fragment document" do
646
+ name = "test2.html.zip"
647
+ x_path = ".//p"
648
+ out_format = "plain"
649
+ opts = {folder: "HtmlTestDoc", storage: nil}
650
+
651
+ # Upload file to server
652
+ res = upload_file(name)
653
+ expect(res.code).to eql(200)
654
+
655
+ answer = @instance.get_document_fragment_by_x_path(name, x_path, out_format, opts)
656
+
657
+ expect(answer).to be_an_instance_of Hash
658
+ expect(answer[:file]).to be_an_instance_of File
659
+ expect(answer[:status]).to eql(200)
660
+
661
+ # Save to test dir
662
+ save_to_test_dir(answer, "Get_fragment_doc.html")
663
+ end
664
+ end
665
+
666
+ # unit tests for document_get_document_fragment_by_x_path_by_url
667
+ # Return list of HTML fragments matching the specified XPath query by the source page URL.
668
+ #
669
+ # @param source_url Source page URL.
670
+ # @param x_path XPath query string.
671
+ # @param out_format Output format. Possible values: &#39;plain&#39; and &#39;json&#39;.
672
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
673
+ describe 'get_document_fragment_by_x_path_by_url test' do
674
+ it "Get fragment document by url" do
675
+ source_url = "https://stallman.org/articles/anonymous-payments-thru-phones.html"
676
+ x_path = ".//p"
677
+ out_format = "plain"
678
+
679
+ answer = @instance.get_document_fragment_by_x_path_by_url(source_url, x_path, out_format)
680
+
681
+ expect(answer).to be_an_instance_of Hash
682
+ expect(answer[:file]).to be_an_instance_of File
683
+ expect(answer[:status]).to eql(200)
684
+
685
+ # Save to test dir
686
+ save_to_test_dir(answer, "Get_fragment_xpath_by_url.html")
687
+ end
688
+ end
689
+
690
+ # Return list of HTML fragments matching the specified CSS selector.
691
+ #
692
+ # @param name The document name.
693
+ # @param selector CSS selector string.
694
+ # @param out_format Output format. Possible values: &#39;plain&#39; and &#39;json&#39;.
695
+ # @param [Hash] opts the optional parameters
696
+ # @option opts [String] :folder The document folder.
697
+ # @option opts [String] :storage The document storage.
698
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
699
+ describe 'get_document_fragments_by_css_selector test' do
700
+ it "Get fragment document by css" do
701
+ name = "test2.html.zip"
702
+ selector = "div p"
703
+ out_format = "plain"
704
+ opts = {folder: "HtmlTestDoc", storage: nil}
705
+
706
+ # Upload file to server
707
+ res = upload_file(name)
708
+ expect(res.code).to eql(200)
709
+
710
+ answer = @instance.get_document_fragments_by_css_selector(name, selector, out_format, opts)
711
+
712
+ expect(answer).to be_an_instance_of Hash
713
+ expect(answer[:file]).to be_an_instance_of File
714
+ expect(answer[:status]).to eql(200)
715
+
716
+ # Save to test dir
717
+ save_to_test_dir(answer, "Get_fragment_doc_css.html")
718
+ end
719
+ end
720
+
721
+ # Return list of HTML fragments matching the specified CSS selector by the source page URL.
722
+ #
723
+ # @param source_url Source page URL.
724
+ # @param selector CSS selector string.
725
+ # @param out_format Output format. Possible values: &#39;plain&#39; and &#39;json&#39;.
726
+ # @param [Hash] opts the optional parameters
727
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
728
+ describe 'get_document_fragments_by_css_selector_by_url test' do
729
+ it "Get fragment document matching the specified CSS selector by url" do
730
+ source_url = "https://www.w3schools.com/cssref/css_selectors.asp"
731
+ selector = 'a[href$=".asp"]'
732
+ out_format = "plain"
733
+
734
+ answer = @instance.get_document_fragments_by_css_selector_by_url(source_url, selector, out_format)
735
+
736
+ expect(answer).to be_an_instance_of Hash
737
+ expect(answer[:file]).to be_an_instance_of File
738
+ expect(answer[:status]).to eql(200)
739
+
740
+ # Save to test dir
741
+ save_to_test_dir(answer, "Get_fragment_css_by_url.html")
742
+ end
743
+ end
744
+
745
+ # unit tests for get_document_images
746
+ # Return all HTML document images packaged as a ZIP archive.
747
+ #
748
+ # @param name The document name.
749
+ # @param [Hash] opts the optional parameters
750
+ # @option opts [String] :folder The document folder.
751
+ # @option opts [String] :storage The document storage.
752
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
753
+ describe 'get_document_images test' do
754
+ it "Get images from document" do
755
+ name = "test3.html.zip"
756
+ opts = {folder: "HtmlTestDoc", storage: nil}
757
+
758
+ # Upload file to server
759
+ res = upload_file(name)
760
+ expect(res.code).to eql(200)
761
+
762
+ answer = @instance.get_document_images(name, opts)
763
+
764
+ expect(answer).to be_an_instance_of Hash
765
+ expect(answer[:file]).to be_an_instance_of File
766
+ expect(answer[:status]).to eql(200)
767
+
768
+ # Save to test dir
769
+ save_to_test_dir(answer, "Get_images_doc.zip")
770
+ end
771
+ end
772
+
773
+ # unit tests for document_get_document_images_by_url
774
+ # Return all HTML page images packaged as a ZIP archive by the source page URL.
775
+ #
776
+ # @param source_url Source page URL.
777
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
778
+ describe 'get_document_images_by_url test' do
779
+ it "Get images from url" do
780
+
781
+ source_url = "https://www.google.com/"
782
+ answer = @instance.get_document_images_by_url(source_url)
783
+
784
+ expect(answer).to be_an_instance_of Hash
785
+ expect(answer[:file]).to be_an_instance_of File
786
+ expect(answer[:status]).to eql(200)
787
+
788
+ # Save to test dir
789
+ save_to_test_dir(answer, "Get_images_from_url.zip")
790
+ end
791
+ end
792
+
793
+ #################################################
794
+ # OCR API
795
+ #################################################
796
+
797
+ # unit tests for get_recognize_and_import_to_html
798
+ # Recognize text from the image file in the storage and import it to HTML format.
799
+ #
800
+ # @param name The image file name.
801
+ # @param [Hash] opts the optional parameters
802
+ # @option opts [String] :ocr_engine_lang OCR engine language - language
803
+ # @option opts [String] :folder The source image folder.
804
+ # @option opts [String] :storage The source image storage.
805
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
806
+ describe 'get_recognize_and_import_to_html test' do
807
+ it "Recognize png" do
808
+ file_name = "test_ocr.png"
809
+ opts = {ocr_engine_lang: "en", folder: "HtmlTestDoc", storage: nil}
810
+
811
+ # Upload file to server
812
+ res = upload_file(file_name)
813
+ expect(res.code).to eql(200)
814
+
815
+ answer = @instance.get_recognize_and_import_to_html(file_name, opts)
816
+
817
+ expect(answer).to be_an_instance_of Hash
818
+ expect(answer[:file]).to be_an_instance_of File
819
+ expect(answer[:status]).to eql(200)
820
+
821
+ # Save to test dir
822
+ save_to_test_dir(answer, "Recognize_en_png.html")
823
+ end
824
+ end
825
+
826
+ # unit tests for get_recognize_and_translate_to_html
827
+ # Recognize text from the image file in the storage, import it to HTML format and translate to specified language.
828
+ #
829
+ # @param name The image file name.
830
+ # @param src_lang Source language - also supposed as the OCR engine language.
831
+ # @param res_lang Result language.
832
+ # @param [Hash] opts the optional parameters
833
+ # @option opts [String] :folder The source image folder.
834
+ # @option opts [String] :storage The source image storage.
835
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
836
+ describe 'get_recognize_and_translate_to_html test' do
837
+ it "Recognize and translate jpg" do
838
+ file_name = "test_ocr.jpg"
839
+ src_lang = "en"
840
+ res_lang = "de"
841
+ opts = {folder: "HtmlTestDoc", storage: nil}
842
+
843
+ # Upload file to server
844
+ res = upload_file(file_name)
845
+ expect(res.code).to eql(200)
846
+
847
+ answer = @instance.get_recognize_and_translate_to_html(file_name, src_lang, res_lang, opts)
848
+
849
+ expect(answer).to be_an_instance_of Hash
850
+ expect(answer[:file]).to be_an_instance_of File
851
+ expect(answer[:status]).to eql(200)
852
+
853
+ # Save to test dir
854
+ save_to_test_dir(answer, "Recognize_en_de_jpg.html")
855
+ end
856
+ end
857
+
858
+ #################################################
859
+ # Translation API
860
+ #################################################
861
+
862
+ # unit tests for get_translate_document
863
+ # Translate the HTML document specified by the name from default or specified storage.
864
+ #
865
+ # @param name Document name.
866
+ # @param src_lang Source language.
867
+ # @param res_lang Result language.
868
+ # @param [Hash] opts the optional parameters
869
+ # @option opts [String] :storage The source document storage.
870
+ # @option opts [String] :folder The source document folder.
871
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
872
+ describe 'get_translate_document test' do
873
+ it "Translate document" do
874
+ file_name = "test_en.html"
875
+ src_lang = "en"
876
+ res_lang = "de"
877
+ opts = {storage: nil, folder: "HtmlTestDoc"}
878
+
879
+ # Upload file to server
880
+ res = upload_file(file_name)
881
+ expect(res.code).to eql(200)
882
+
883
+ answer = @instance.get_translate_document(file_name, src_lang, res_lang, opts)
884
+
885
+ expect(answer).to be_an_instance_of Hash
886
+ expect(answer[:file]).to be_an_instance_of File
887
+ expect(answer[:status]).to eql(200)
888
+
889
+ # Save to test dir
890
+ save_to_test_dir(answer, "Translate_doc_en_de.html")
891
+ end
892
+ end
893
+
894
+ # unit tests for get_translate_document_by_url
895
+ # Translate the HTML document from Web specified by its URL.
896
+ #
897
+ # @param source_url Source document URL.
898
+ # @param src_lang Source language.
899
+ # @param res_lang Result language.
900
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
901
+ describe 'get_translate_document_by_url test' do
902
+ it "Translate url" do
903
+
904
+ source_url = "https://www.le.ac.uk/oerresources/bdra/html/page_01.htm"
905
+ src_lang = "en"
906
+ res_lang = "fr"
907
+
908
+ answer = @instance.get_translate_document_by_url(source_url, src_lang,res_lang)
909
+
910
+ expect(answer).to be_an_instance_of Hash
911
+ expect(answer[:file]).to be_an_instance_of File
912
+ expect(answer[:status]).to eql(200)
913
+
914
+ # Save to test dir
915
+ save_to_test_dir(answer, "Translate_url_en_fr.zip")
916
+ end
917
+ end
918
+
919
+ #################################################
920
+ # Summarization API
921
+ #################################################
922
+
923
+ # unit tests for get_detect_html_keywords
924
+ # Get the HTML document keywords using the keyword detection service.
925
+ #
926
+ # @param name Document name.
927
+ # @param [Hash] opts the optional parameters
928
+ # @option opts [String] :folder Document folder.
929
+ # @option opts [String] :storage Document storage.
930
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
931
+ describe 'get_detect_html_keywords test' do
932
+ it "Keyword by html document" do
933
+ name = "test_en.html"
934
+ opts = {storage: nil, folder: "HtmlTestDoc"}
935
+
936
+ # Upload file to server
937
+ res = upload_file(name)
938
+ expect(res.code).to eql(200)
939
+
940
+ answer = @instance.get_detect_html_keywords(name, opts)
941
+
942
+ expect(answer).to be_an_instance_of Hash
943
+ expect(answer[:file]).to be_an_instance_of File
944
+ expect(answer[:status]).to eql(200)
945
+
946
+ # Save to test dir
947
+ save_to_test_dir(answer, "Keyword_by_doc.json")
948
+ end
949
+ end
950
+
951
+ # unit tests for get_detect_html_keywords_by_url
952
+ # Get the keywords from HTML document from Web specified by its URL using the keyword detection service
953
+ #
954
+ # @param source_url Source document URL.
955
+ # @return [Hash] {file: data, status: _status_code, headers: _headers}
956
+ describe 'get_detect_html_keywords_by_url test' do
957
+ it "Keyword by url" do
958
+ source_url = "https://www.le.ac.uk/oerresources/bdra/html/page_01.htm"
959
+
960
+ answer = @instance.get_detect_html_keywords_by_url(source_url)
961
+
962
+ expect(answer).to be_an_instance_of Hash
963
+ expect(answer[:file]).to be_an_instance_of File
964
+ expect(answer[:status]).to eql(200)
965
+
966
+ # Save to test dir
967
+ save_to_test_dir(answer, "Keyword_by_url.json")
968
+ end
969
+ end
970
+
971
+ end