aspose_html_cloud 19.6.0 → 22.9.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.
@@ -3,7 +3,7 @@
3
3
  --------------------------------------------------------------------------------------------------------------------
4
4
  <copyright company="Aspose" file="html_api_spec.rb">
5
5
  </copyright>
6
- Copyright (c) 2019 Aspose.HTML for Cloud
6
+ Copyright (c) 2022 Aspose.HTML for Cloud
7
7
  <summary>
8
8
  Permission is hereby granted, free of charge, to any person obtaining a copy
9
9
  of this software and associated documentation files (the "Software"), to deal
@@ -29,2402 +29,386 @@
29
29
  require 'spec_helper'
30
30
  require 'json'
31
31
 
32
- describe 'Test html_api' do
32
+ describe 'Test html_api_V4' do
33
33
  before(:all) do
34
34
  # run before all tests
35
- @instance = AsposeHtml::HtmlApi.new CONFIG
35
+ @html_api = AsposeHtml::HtmlApi.new CONFIG
36
+ @storage_api = AsposeHtml::StorageApi.new CONFIG
36
37
  end
37
38
 
38
39
  describe 'test an instance of HtmlApi' do
39
40
  it 'should create an instance of HtmlApi' do
40
- expect(@instance).to be_instance_of(AsposeHtml::HtmlApi)
41
+ expect(@html_api).to be_instance_of(AsposeHtml::HtmlApi)
41
42
  end
42
- end
43
-
44
- #################################################
45
- # Conversion API
46
- #################################################
47
-
48
- # unit tests for get_convert_document_to_image from html format
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 (jpeg, png, bmp, tiff, gif).
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] :resolution Resolution of resulting image.
61
- # @option opts [String] :folder The source document folder.
62
- # @option opts [String] :storage The source document storage.
63
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
64
- describe 'get_convert_html_to_image test' do
65
- name = "test1.html"
66
- opts = {
67
- width: 800,
68
- height: 1000,
69
- left_margin: 30,
70
- right_margin: 30,
71
- top_margin: 50,
72
- bottom_margin: 50,
73
- resolution: 300,
74
- folder: "HtmlTestDoc",
75
- storage: nil
76
- }
77
-
78
- # Upload file to server
79
- upload_file_helper(name)
80
-
81
- it "Convert html to jpeg" do
82
- out_format = "jpeg"
83
- answer = @instance.get_convert_document_to_image(name, out_format, opts)
84
-
85
- expect(answer).to be_an_instance_of Hash
86
- expect(answer[:file]).to be_an_instance_of File
87
- expect(answer[:status]).to eql(200)
88
-
89
- # Save to test dir
90
- save_to_test_dir(answer[:file], "Convert_get_html.jpeg")
91
- end
92
-
93
- it "Convert html to png" do
94
- out_format = "png"
95
- answer = @instance.get_convert_document_to_image(name, out_format, opts)
96
-
97
- expect(answer).to be_an_instance_of Hash
98
- expect(answer[:file]).to be_an_instance_of File
99
- expect(answer[:status]).to eql(200)
100
-
101
- # Save to test dir
102
- save_to_test_dir(answer[:file], "Convert_get_html.png")
103
- end
104
-
105
- it "Convert html to bmp" do
106
- out_format = "bmp"
107
- answer = @instance.get_convert_document_to_image(name, out_format, opts)
108
-
109
- expect(answer).to be_an_instance_of Hash
110
- expect(answer[:file]).to be_an_instance_of File
111
- expect(answer[:status]).to eql(200)
112
-
113
- # Save to test dir
114
- save_to_test_dir(answer[:file], "Convert_get_html.bmp")
115
- end
116
-
117
- it "Convert html to tiff" do
118
- out_format = "tiff"
119
- answer = @instance.get_convert_document_to_image(name, out_format, opts)
120
-
121
- expect(answer).to be_an_instance_of Hash
122
- expect(answer[:file]).to be_an_instance_of File
123
- expect(answer[:status]).to eql(200)
124
-
125
- # Save to test dir
126
- save_to_test_dir(answer[:file], "Convert_get_html.tiff")
127
- end
128
-
129
- it "Convert html to gif" do
130
- out_format = "gif"
131
- answer = @instance.get_convert_document_to_image(name, 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[:file], "Convert_get_html.gif")
139
- end
140
- end
141
-
142
- # unit tests for get_convert_document_to_image from epub format
143
- # Convert the EPUB document from the storage by its name to the specified image format.
144
- #
145
- # @param name Document name.
146
- # @param out_format Resulting image format (jpeg, png, bmp, tiff, gif).
147
- # @param [Hash] opts the optional parameters
148
- # @option opts [Integer] :width Resulting image width.
149
- # @option opts [Integer] :height Resulting image height.
150
- # @option opts [Integer] :left_margin Left resulting image margin.
151
- # @option opts [Integer] :right_margin Right resulting image margin.
152
- # @option opts [Integer] :top_margin Top resulting image margin.
153
- # @option opts [Integer] :bottom_margin Bottom resulting image margin.
154
- # @option opts [Integer] :resolution Resolution of resulting image.
155
- # @option opts [String] :folder The source document folder.
156
- # @option opts [String] :storage The source document storage.
157
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
158
- describe 'get_convert_epub_to_image test' do
159
- name = "georgia.epub"
160
- opts = {
161
- width: 800,
162
- height: 1000,
163
- left_margin: 30,
164
- right_margin: 30,
165
- top_margin: 50,
166
- bottom_margin: 50,
167
- resolution: 300,
168
- folder: "HtmlTestDoc",
169
- storage: nil
170
- }
171
- # Upload file to server
172
- upload_file_helper(name)
173
-
174
- it "Convert epub to jpeg" do
175
- out_format = "jpeg"
176
- answer = @instance.get_convert_document_to_image(name, out_format, opts)
177
-
178
- expect(answer).to be_an_instance_of Hash
179
- expect(answer[:file]).to be_an_instance_of File
180
- expect(answer[:status]).to eql(200)
181
-
182
- # Save to test dir
183
- save_to_test_dir(answer[:file], "Convert_get_epub_jpeg.zip")
184
- end
185
-
186
- it "Convert epub to png" do
187
- out_format = "png"
188
- answer = @instance.get_convert_document_to_image(name, out_format, opts)
189
-
190
- expect(answer).to be_an_instance_of Hash
191
- expect(answer[:file]).to be_an_instance_of File
192
- expect(answer[:status]).to eql(200)
193
-
194
- # Save to test dir
195
- save_to_test_dir(answer[:file], "Convert_get_epub_png.zip")
196
- end
197
-
198
- it "Convert epub to bmp" do
199
- out_format = "bmp"
200
- answer = @instance.get_convert_document_to_image(name, out_format, opts)
201
-
202
- expect(answer).to be_an_instance_of Hash
203
- expect(answer[:file]).to be_an_instance_of File
204
- expect(answer[:status]).to eql(200)
205
43
 
206
- # Save to test dir
207
- save_to_test_dir(answer[:file], "Convert_get_epub_bmp.zip")
208
- end
209
-
210
- it "Convert epub to tiff" do
211
- out_format = "tiff"
212
- answer = @instance.get_convert_document_to_image(name, out_format, opts)
213
-
214
- expect(answer).to be_an_instance_of Hash
215
- expect(answer[:file]).to be_an_instance_of File
216
- expect(answer[:status]).to eql(200)
217
-
218
- # Save to test dir
219
- save_to_test_dir(answer[:file], "Convert_get_epub_tiff.zip")
220
- end
221
-
222
- it "Convert epub to gif" do
223
- out_format = "gif"
224
- answer = @instance.get_convert_document_to_image(name, out_format, opts)
225
-
226
- expect(answer).to be_an_instance_of Hash
227
- expect(answer[:file]).to be_an_instance_of File
228
- expect(answer[:status]).to eql(200)
229
-
230
- # Save to test dir
231
- save_to_test_dir(answer[:file], "Convert_get_epub_gif.zip")
44
+ it 'should create an instance of StorageApi' do
45
+ expect(@storage_api).to be_instance_of(AsposeHtml::StorageApi)
232
46
  end
233
47
  end
234
48
 
235
- # unit tests for get_convert_document_to_image from svg format
236
- # Convert the SVG document from the storage by its name to the specified image format.
237
- #
238
- # @param name Document name.
239
- # @param out_format Resulting image format (jpeg, png, bmp, tiff, gif).
240
- # @param [Hash] opts the optional parameters
241
- # @option opts [Integer] :width Resulting image width.
242
- # @option opts [Integer] :height Resulting image height.
243
- # @option opts [Integer] :left_margin Left resulting image margin.
244
- # @option opts [Integer] :right_margin Right resulting image margin.
245
- # @option opts [Integer] :top_margin Top resulting image margin.
246
- # @option opts [Integer] :bottom_margin Bottom resulting image margin.
247
- # @option opts [Integer] :resolution Resolution of resulting image.
248
- # @option opts [String] :folder The source document folder.
249
- # @option opts [String] :storage The source document storage.
250
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
251
- describe 'get_convert_svg_to_image test' do
252
- name = "Map-World.svg"
253
- opts = {
254
- width: 800,
255
- height: 1000,
256
- left_margin: 30,
257
- right_margin: 30,
258
- top_margin: 50,
259
- bottom_margin: 50,
260
- resolution: 300,
261
- folder: "HtmlTestDoc",
262
- storage: nil
263
- }
264
-
265
- # Upload file to server
266
- upload_file_helper(name)
49
+ describe 'convert html local to local' do
267
50
 
268
- it "Convert svg to jpeg" do
269
- out_format = "jpeg"
270
- answer = @instance.get_convert_document_to_image(name, out_format, opts)
51
+ src = File.realpath(__dir__ + '/../../testdata') + '/test1.html'
52
+ dst_dir = File.realpath(__dir__ + '/../../testresult') + '/'
271
53
 
272
- expect(answer).to be_an_instance_of Hash
273
- expect(answer[:file]).to be_an_instance_of File
274
- expect(answer[:status]).to eql(200)
54
+ describe 'convert local to local html to doc' do
275
55
 
276
- # Save to test dir
277
- save_to_test_dir(answer[:file], "Convert_get_svg.jpeg")
278
- end
279
-
280
- it "Convert svg to png" do
281
- out_format = "png"
282
- answer = @instance.get_convert_document_to_image(name, out_format, opts)
56
+ %w[pdf xps docx md mhtml mht].each { |ext|
57
+ it "Convert html to " + ext do
283
58
 
284
- expect(answer).to be_an_instance_of Hash
285
- expect(answer[:file]).to be_an_instance_of File
286
- expect(answer[:status]).to eql(200)
59
+ dst = dst_dir + 'locToLocDoc.' + ext
60
+ answer = @html_api.convert_local_to_local(src, dst)
287
61
 
288
- # Save to test dir
289
- save_to_test_dir(answer[:file], "Convert_get_svg.png")
62
+ expect(answer.code).to eql(200)
63
+ expect(answer.status).to eql('completed')
64
+ expect(File.exist?(answer.file)).to be_truthy
65
+ end
66
+ }
290
67
  end
291
68
 
292
- it "Convert svg to bmp" do
293
- out_format = "bmp"
294
- answer = @instance.get_convert_document_to_image(name, out_format, opts)
69
+ describe 'convert local to local html to image' do
295
70
 
296
- expect(answer).to be_an_instance_of Hash
297
- expect(answer[:file]).to be_an_instance_of File
298
- expect(answer[:status]).to eql(200)
71
+ %w[jpeg jpg bmp png tiff tif gif].each { |ext|
72
+ it "Convert html to " + ext do
299
73
 
300
- # Save to test dir
301
- save_to_test_dir(answer[:file], "Convert_get_svg.bmp")
302
- end
74
+ dst = dst_dir + 'locToLocImg.' + ext
75
+ answer = @html_api.convert_local_to_local(src, dst)
303
76
 
304
- it "Convert svg to tiff" do
305
- out_format = "tiff"
306
- answer = @instance.get_convert_document_to_image(name, out_format, opts)
307
-
308
- expect(answer).to be_an_instance_of Hash
309
- expect(answer[:file]).to be_an_instance_of File
310
- expect(answer[:status]).to eql(200)
311
-
312
- # Save to test dir
313
- save_to_test_dir(answer[:file], "Convert_get_svg.tiff")
77
+ expect(answer.code).to eql(200)
78
+ expect(answer.status).to eql('completed')
79
+ expect(File.exist?(answer.file)).to be_truthy
80
+ end
81
+ }
314
82
  end
315
83
 
316
- it "Convert svg to gif" do
317
- out_format = "gif"
318
- answer = @instance.get_convert_document_to_image(name, out_format, opts)
84
+ describe 'convert local to local html to image with options' do
319
85
 
320
- expect(answer).to be_an_instance_of Hash
321
- expect(answer[:file]).to be_an_instance_of File
322
- expect(answer[:status]).to eql(200)
323
-
324
- # Save to test dir
325
- save_to_test_dir(answer[:file], "Convert_get_svg.gif")
326
- end
327
- end
328
-
329
- # unit tests for get_convert_document_to_image_by_url
330
- # Convert the HTML page from the web by its URL to the specified image format.
331
- #
332
- # @param source_url Source page URL.
333
- # @param out_format Resulting image format.
334
- # @param [Hash] opts the optional parameters
335
- # @option opts [Integer] :width Resulting image width.
336
- # @option opts [Integer] :height Resulting image height.
337
- # @option opts [Integer] :left_margin Left resulting image margin.
338
- # @option opts [Integer] :right_margin Right resulting image margin.
339
- # @option opts [Integer] :top_margin Top resulting image margin.
340
- # @option opts [Integer] :bottom_margin Bottom resulting image margin.
341
- # @option opts [Integer] :resolution Resolution of resulting image.
342
- # @option opts [String] :folder The document folder.
343
- # @option opts [String] :storage The document storage.
344
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
345
- describe 'get_convert_html_to_image_by_url test' do
346
- source_url = "https://stallman.org/articles/anonymous-payments-thru-phones.html"
347
- opts = {
86
+ opts = {
348
87
  width: 800,
349
88
  height: 1000,
350
89
  left_margin: 30,
351
90
  right_margin: 30,
352
91
  top_margin: 50,
353
- bottom_margin: 50,
354
- resolution: 300,
355
- folder: "HtmlTestDoc",
356
- storage: nil
357
- }
358
-
359
- it "Convert url to jpeg" do
360
- out_format = "jpeg"
361
- answer = @instance.get_convert_document_to_image_by_url(source_url, out_format, opts)
362
-
363
- expect(answer).to be_an_instance_of Hash
364
- expect(answer[:file]).to be_an_instance_of File
365
- expect(answer[:status]).to eql(200)
366
-
367
- # Save to test dir
368
- save_to_test_dir(answer[:file], "Convert_get_url.jpeg")
369
- end
370
-
371
- it "Convert url to png" do
372
- out_format = "png"
373
- answer = @instance.get_convert_document_to_image_by_url(source_url, out_format, opts)
374
-
375
- expect(answer).to be_an_instance_of Hash
376
- expect(answer[:file]).to be_an_instance_of File
377
- expect(answer[:status]).to eql(200)
378
-
379
- # Save to test dir
380
- save_to_test_dir(answer[:file], "Convert_get_url.png")
381
- end
382
-
383
- it "Convert url to bmp" do
384
- out_format = "bmp"
385
- answer = @instance.get_convert_document_to_image_by_url(source_url, out_format, opts)
386
-
387
- expect(answer).to be_an_instance_of Hash
388
- expect(answer[:file]).to be_an_instance_of File
389
- expect(answer[:status]).to eql(200)
390
-
391
- # Save to test dir
392
- save_to_test_dir(answer[:file], "Convert_get_url.bmp")
393
- end
394
-
395
- it "Convert url to tiff" do
396
- out_format = "tiff"
397
- answer = @instance.get_convert_document_to_image_by_url(source_url, out_format, opts)
398
-
399
- expect(answer).to be_an_instance_of Hash
400
- expect(answer[:file]).to be_an_instance_of File
401
- expect(answer[:status]).to eql(200)
402
-
403
- # Save to test dir
404
- save_to_test_dir(answer[:file], "Convert_get_url.tiff")
405
- end
406
-
407
- it "Convert url to gif" do
408
- out_format = "gif"
409
- answer = @instance.get_convert_document_to_image_by_url(source_url, out_format, opts)
410
-
411
- expect(answer).to be_an_instance_of Hash
412
- expect(answer[:file]).to be_an_instance_of File
413
- expect(answer[:status]).to eql(200)
414
-
415
- # Save to test dir
416
- save_to_test_dir(answer[:file], "Convert_get_url.gif")
417
- end
418
- end
419
-
420
- # unit tests for get_convert_document_to_pdf from html format
421
- # Convert the HTML document from the storage by its name to PDF.
422
- #
423
- # @param name Document name.
424
- # @param [Hash] opts the optional parameters
425
- # @option opts [Integer] :width Resulting image width.
426
- # @option opts [Integer] :height Resulting image height.
427
- # @option opts [Integer] :left_margin Left resulting image margin.
428
- # @option opts [Integer] :right_margin Right resulting image margin.
429
- # @option opts [Integer] :top_margin Top resulting image margin.
430
- # @option opts [Integer] :bottom_margin Bottom resulting image margin.
431
- # @option opts [String] :folder The document folder.
432
- # @option opts [String] :storage The document storage.
433
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
434
- describe 'get_convert_html_to_pdf test' do
435
- it "Convert html to pdf" do
436
- name = "test1.html"
437
- opts = {
438
- width: 800,
439
- height: 1000,
440
- left_margin: 30,
441
- right_margin: 30,
442
- top_margin: 50,
443
- bottom_margin: 50,
444
- folder: "HtmlTestDoc",
445
- storage: nil
92
+ bottom_margin: 50
446
93
  }
447
94
 
448
- # Upload file to server
449
- res = upload_file_helper(name)
450
- expect(res.uploaded.length).to eql(1)
451
- expect(res.errors.length).to eql(0)
95
+ %w[jpeg jpg bmp png tiff tif gif].each { |ext|
96
+ it "Convert html to " + ext do
452
97
 
453
- answer = @instance.get_convert_document_to_pdf(name, opts)
454
-
455
- expect(answer).to be_an_instance_of Hash
456
- expect(answer[:file]).to be_an_instance_of File
457
- expect(answer[:status]).to eql(200)
458
-
459
- # Save to test dir
460
- save_to_test_dir(answer[:file], "Convert_get_html.pdf")
461
- end
462
- end
98
+ dst = dst_dir + 'locToLocImgOpt.' + ext
99
+ answer = @html_api.convert_local_to_local(src, dst, opts)
463
100
 
464
- # unit tests for get_convert_document_to_pdf from epub format
465
- # Convert the EPUB document from the storage by its name to PDF.
466
- #
467
- # @param name Document name.
468
- # @param [Hash] opts the optional parameters
469
- # @option opts [Integer] :width Resulting image width.
470
- # @option opts [Integer] :height Resulting image height.
471
- # @option opts [Integer] :left_margin Left resulting image margin.
472
- # @option opts [Integer] :right_margin Right resulting image margin.
473
- # @option opts [Integer] :top_margin Top resulting image margin.
474
- # @option opts [Integer] :bottom_margin Bottom resulting image margin.
475
- # @option opts [String] :folder The document folder.
476
- # @option opts [String] :storage The document storage.
477
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
478
- describe 'get_convert_epub_to_pdf test' do
479
- it "Convert epub to pdf" do
480
- name = "georgia.epub"
481
- opts = {
482
- width: 800,
483
- height: 1000,
484
- left_margin: 30,
485
- right_margin: 30,
486
- top_margin: 50,
487
- bottom_margin: 50,
488
- folder: "HtmlTestDoc",
489
- storage: nil
101
+ expect(answer.code).to eql(200)
102
+ expect(answer.status).to eql('completed')
103
+ expect(File.exist?(answer.file)).to be_truthy
104
+ end
490
105
  }
491
-
492
- # Upload file to server
493
- res = upload_file_helper(name)
494
- expect(res.uploaded.length).to eql(1)
495
- expect(res.errors.length).to eql(0)
496
-
497
- answer = @instance.get_convert_document_to_pdf(name, opts)
498
-
499
- expect(answer).to be_an_instance_of Hash
500
- expect(answer[:file]).to be_an_instance_of File
501
- expect(answer[:status]).to eql(200)
502
-
503
- # Save to test dir
504
- save_to_test_dir(answer[:file], "Convert_get_epub.pdf")
505
106
  end
506
107
  end
507
108
 
508
- # unit tests for get_convert_document_to_pdf from svg format
509
- # Convert the SVG document from the storage by its name to PDF.
510
- #
511
- # @param name Document name.
512
- # @param [Hash] opts the optional parameters
513
- # @option opts [Integer] :width Resulting image width.
514
- # @option opts [Integer] :height Resulting image height.
515
- # @option opts [Integer] :left_margin Left resulting image margin.
516
- # @option opts [Integer] :right_margin Right resulting image margin.
517
- # @option opts [Integer] :top_margin Top resulting image margin.
518
- # @option opts [Integer] :bottom_margin Bottom resulting image margin.
519
- # @option opts [String] :folder The document folder.
520
- # @option opts [String] :storage The document storage.
521
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
522
- describe 'get_convert_svg_to_pdf test' do
523
- it "Convert svg to pdf" do
524
- name = "Map-World.svg"
525
- opts = {
526
- width: 800,
527
- height: 1000,
528
- left_margin: 30,
529
- right_margin: 30,
530
- top_margin: 50,
531
- bottom_margin: 50,
532
- folder: "HtmlTestDoc",
533
- storage: nil
534
- }
535
-
536
- # Upload file to server
537
- res = upload_file_helper(name)
538
- expect(res.uploaded.length).to eql(1)
539
- expect(res.errors.length).to eql(0)
109
+ describe 'convert html local to storage' do
110
+ src = File.realpath(__dir__ + '/../../testdata') + '/test1.html'
111
+ dst_dir = 'RubyTests'
540
112
 
541
- answer = @instance.get_convert_document_to_pdf(name, opts)
113
+ describe 'convert local to storage html to doc' do
542
114
 
543
- expect(answer).to be_an_instance_of Hash
544
- expect(answer[:file]).to be_an_instance_of File
545
- expect(answer[:status]).to eql(200)
115
+ %w[pdf xps docx md mhtml mht].each { |ext|
116
+ it "Convert html to " + ext do
546
117
 
547
- # Save to test dir
548
- save_to_test_dir(answer[:file], "Convert_get_svg.pdf")
549
- end
550
- end
118
+ dst = dst_dir + '/locToStorDoc.' + ext
119
+ answer = @html_api.convert_local_to_storage(src, dst, nil)
551
120
 
552
- # unit tests for get_convert_document_to_pdf_by_url
553
- # Convert the HTML page from the web by its URL to PDF.
554
- #
555
- # @param source_url Source page URL.
556
- # @param [Hash] opts the optional parameters
557
- # @option opts [Integer] :width Resulting image width.
558
- # @option opts [Integer] :height Resulting image height.
559
- # @option opts [Integer] :left_margin Left resulting image margin.
560
- # @option opts [Integer] :right_margin Right resulting image margin.
561
- # @option opts [Integer] :top_margin Top resulting image margin.
562
- # @option opts [Integer] :bottom_margin Bottom resulting image margin.
563
- # @option opts [String] :folder The document folder.
564
- # @option opts [String] :storage The document storage.
565
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
566
- describe 'get_convert_html_to_pdf_by_url test' do
567
- it "Convert url to pdf" do
568
- source_url = "https://stallman.org/articles/anonymous-payments-thru-phones.html"
569
- opts = {
570
- width: 800,
571
- height: 1000,
572
- left_margin: 30,
573
- right_margin: 30,
574
- top_margin: 50,
575
- bottom_margin: 50,
576
- folder: "HtmlTestDoc",
577
- storage: nil
121
+ expect(answer.code).to eql(200)
122
+ expect(answer.status).to eql('completed')
123
+ expect(@storage_api.object_exists(answer.file)).to be_truthy
124
+ end
578
125
  }
579
-
580
- answer = @instance.get_convert_document_to_pdf_by_url(source_url, opts)
581
-
582
- expect(answer).to be_an_instance_of Hash
583
- expect(answer[:file]).to be_an_instance_of File
584
- expect(answer[:status]).to eql(200)
585
-
586
- # Save to test dir
587
- save_to_test_dir(answer[:file], "Convert_get_url.pdf")
588
126
  end
589
- end
590
127
 
591
- # unit tests for get_convert_document_to_xps from html format
592
- # Convert the HTML document from the storage by its name to XPS.
593
- #
594
- # @param name Document name.
595
- # @param [Hash] opts the optional parameters
596
- # @option opts [Integer] :width Resulting image width.
597
- # @option opts [Integer] :height Resulting image height.
598
- # @option opts [Integer] :left_margin Left resulting image margin.
599
- # @option opts [Integer] :right_margin Right resulting image margin.
600
- # @option opts [Integer] :top_margin Top resulting image margin.
601
- # @option opts [Integer] :bottom_margin Bottom resulting image margin.
602
- # @option opts [String] :folder The document folder.
603
- # @option opts [String] :storage The document storage.
604
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
605
- describe 'get_convert_html_to_xps test' do
606
- it "Convert html to xps" do
607
- name = "test1.html"
608
- opts = {
609
- width: 800,
610
- height: 1000,
611
- left_margin: 30,
612
- right_margin: 30,
613
- top_margin: 50,
614
- bottom_margin: 50,
615
- folder: "HtmlTestDoc",
616
- storage: nil
617
- }
128
+ describe 'convert local to storage html to image' do
618
129
 
619
- # Upload file to server
620
- res = upload_file_helper(name)
621
- expect(res.uploaded.length).to eql(1)
622
- expect(res.errors.length).to eql(0)
130
+ %w[jpeg jpg bmp png tiff tif gif].each { |ext|
131
+ it "Convert html to " + ext do
623
132
 
624
- answer = @instance.get_convert_document_to_xps(name, opts)
133
+ dst = dst_dir + '/locToStorImg.' + ext
134
+ answer = @html_api.convert_local_to_storage(src, dst, nil)
625
135
 
626
- expect(answer).to be_an_instance_of Hash
627
- expect(answer[:file]).to be_an_instance_of File
628
- expect(answer[:status]).to eql(200)
629
-
630
- # Save to test dir
631
- save_to_test_dir(answer[:file], "Convert_get_html.xps")
632
- end
633
- end
634
-
635
- # unit tests for get_convert_document_to_xps from epub format
636
- # Convert the EPUB document from the storage by its name to XPS.
637
- #
638
- # @param name Document name.
639
- # @param [Hash] opts the optional parameters
640
- # @option opts [Integer] :width Resulting image width.
641
- # @option opts [Integer] :height Resulting image height.
642
- # @option opts [Integer] :left_margin Left resulting image margin.
643
- # @option opts [Integer] :right_margin Right resulting image margin.
644
- # @option opts [Integer] :top_margin Top resulting image margin.
645
- # @option opts [Integer] :bottom_margin Bottom resulting image margin.
646
- # @option opts [String] :folder The document folder.
647
- # @option opts [String] :storage The document storage.
648
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
649
- describe 'get_convert_epub_to_xps test' do
650
- it "Convert epnb to xps" do
651
- name = "georgia.epub"
652
- opts = {
653
- width: 800,
654
- height: 1000,
655
- left_margin: 30,
656
- right_margin: 30,
657
- top_margin: 50,
658
- bottom_margin: 50,
659
- folder: "HtmlTestDoc",
660
- storage: nil
136
+ expect(answer.code).to eql(200)
137
+ expect(answer.status).to eql('completed')
138
+ expect(@storage_api.object_exists(answer.file)).to be_truthy
139
+ end
661
140
  }
662
-
663
- # Upload file to server
664
- res = upload_file_helper(name)
665
- expect(res.uploaded.length).to eql(1)
666
- expect(res.errors.length).to eql(0)
667
-
668
- answer = @instance.get_convert_document_to_xps(name, opts)
669
-
670
- expect(answer).to be_an_instance_of Hash
671
- expect(answer[:file]).to be_an_instance_of File
672
- expect(answer[:status]).to eql(200)
673
-
674
- # Save to test dir
675
- save_to_test_dir(answer[:file], "Convert_get_epub.xps")
676
141
  end
677
- end
678
142
 
679
- # unit tests for get_convert_document_to_xps from svg format
680
- # Convert the SVG document from the storage by its name to XPS.
681
- #
682
- # @param name Document name.
683
- # @param [Hash] opts the optional parameters
684
- # @option opts [Integer] :width Resulting image width.
685
- # @option opts [Integer] :height Resulting image height.
686
- # @option opts [Integer] :left_margin Left resulting image margin.
687
- # @option opts [Integer] :right_margin Right resulting image margin.
688
- # @option opts [Integer] :top_margin Top resulting image margin.
689
- # @option opts [Integer] :bottom_margin Bottom resulting image margin.
690
- # @option opts [String] :folder The document folder.
691
- # @option opts [String] :storage The document storage.
692
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
693
- describe 'get_convert_svg_to_xps test' do
694
- it "Convert svg to xps" do
695
- name = "Map-World.svg"
696
- opts = {
697
- width: 800,
698
- height: 1000,
699
- left_margin: 30,
700
- right_margin: 30,
701
- top_margin: 50,
702
- bottom_margin: 50,
703
- folder: "HtmlTestDoc",
704
- storage: nil
705
- }
706
-
707
- # Upload file to server
708
- res = upload_file_helper(name)
709
- expect(res.uploaded.length).to eql(1)
710
- expect(res.errors.length).to eql(0)
711
-
712
- answer = @instance.get_convert_document_to_xps(name, opts)
713
-
714
- expect(answer).to be_an_instance_of Hash
715
- expect(answer[:file]).to be_an_instance_of File
716
- expect(answer[:status]).to eql(200)
717
-
718
- # Save to test dir
719
- save_to_test_dir(answer[:file], "Convert_get_svg.xps")
720
- end
721
- end
143
+ describe 'convert local to storage html to image with options' do
722
144
 
723
- # unit tests for get_convert_document_to_xps_by_url
724
- # Convert the HTML page from the web by its URL to XPS.
725
- #
726
- # @param source_url Source page URL.
727
- # @param [Hash] opts the optional parameters
728
- # @option opts [Integer] :width Resulting image width.
729
- # @option opts [Integer] :height Resulting image height.
730
- # @option opts [Integer] :left_margin Left resulting image margin.
731
- # @option opts [Integer] :right_margin Right resulting image margin.
732
- # @option opts [Integer] :top_margin Top resulting image margin.
733
- # @option opts [Integer] :bottom_margin Bottom resulting image margin.
734
- # @option opts [String] :folder The document folder.
735
- # @option opts [String] :storage The document storage.
736
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
737
- describe 'get_convert_document_to_xps_by_url test' do
738
- it "Convert url to xps" do
739
- source_url = "https://stallman.org/articles/anonymous-payments-thru-phones.html"
740
145
  opts = {
741
- width: 800,
742
- height: 1000,
743
- left_margin: 30,
744
- right_margin: 30,
745
- top_margin: 50,
746
- bottom_margin: 50,
747
- folder: "HtmlTestDoc",
748
- storage: nil
749
- }
750
-
751
- answer = @instance.get_convert_document_to_xps_by_url(source_url, opts)
752
-
753
- expect(answer).to be_an_instance_of Hash
754
- expect(answer[:file]).to be_an_instance_of File
755
- expect(answer[:status]).to eql(200)
756
-
757
- # Save to test dir
758
- save_to_test_dir(answer[:file], "Convert_html_url.xps")
759
- end
760
- end
761
-
762
- # unit tests for post_convert_document_in_request_to_image from html format
763
- # Converts the HTML document (in request content) to the specified image format and uploads resulting file to storage.
764
- #
765
- # @param out_path Full resulting filename (ex. /folder1/folder2/result.jpg)
766
- # @param out_format (jpeg, png, bmp, tiff, gif).
767
- # @param file A file to be converted (html, epub, svg).
768
- # @param [Hash] opts the optional parameters
769
- # @option opts [Integer] :width Resulting document page width in points (1/96 inch).
770
- # @option opts [Integer] :height Resulting document page height in points (1/96 inch).
771
- # @option opts [Integer] :left_margin Left resulting document page margin in points (1/96 inch).
772
- # @option opts [Integer] :right_margin Right resulting document page margin in points (1/96 inch).
773
- # @option opts [Integer] :top_margin Top resulting document page margin in points (1/96 inch).
774
- # @option opts [Integer] :bottom_margin Bottom resulting document page margin in points (1/96 inch).
775
- # @option opts [Integer] :resolution Resolution of resulting image. Default is 96 dpi.
776
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
777
- describe 'post_convert_html_in_request_to_image test' do
778
- file = File.realpath(__dir__ + '/../../testdata/test1.html')
779
- opts = {
780
146
  width: 800,
781
147
  height: 1000,
782
148
  left_margin: 30,
783
149
  right_margin: 30,
784
150
  top_margin: 50,
785
- bottom_margin: 50,
786
- resolution: 300
787
- }
788
-
789
- it "Upload and convert html to jpeg" do
790
- name = "postHtmlToJpegInReq.jpeg"
791
- out_path = "HtmlTestDoc/" + name
792
- out_format = "jpeg"
793
-
794
- answer = @instance.post_convert_document_in_request_to_image(out_path, out_format, file, opts)
795
-
796
- expect(answer[:status]).to eql(200)
797
-
798
- #Download converted file from storage
799
- res = download_file_helper(name)
800
- expect(res).to be_an_instance_of File
801
-
802
- #Move to test folder
803
- save_to_test_dir(res, name)
804
- end
805
-
806
- it "Upload and convert html to png" do
807
- name = "postHtmlToPngInReq.png"
808
- out_path = "HtmlTestDoc/" + name
809
- out_format = "png"
810
-
811
- answer = @instance.post_convert_document_in_request_to_image(out_path, out_format, file, opts)
812
-
813
- expect(answer[:status]).to eql(200)
814
-
815
- #Download converted file from storage
816
- res = download_file_helper(name)
817
- expect(res).to be_an_instance_of File
818
-
819
- #Move to test folder
820
- save_to_test_dir(res, name)
821
- end
822
-
823
- it "Upload and convert html to bmp" do
824
- name = "postHtmlToBmpInReq.bmp"
825
- out_path = "HtmlTestDoc/" + name
826
- out_format = "bmp"
827
-
828
- answer = @instance.post_convert_document_in_request_to_image(out_path, out_format, file, opts)
829
-
830
- expect(answer[:status]).to eql(200)
831
-
832
- #Download converted file from storage
833
- res = download_file_helper(name)
834
- expect(res).to be_an_instance_of File
835
-
836
- #Move to test folder
837
- save_to_test_dir(res, name)
838
- end
839
-
840
- it "Upload and convert html to tiff" do
841
- name = "postHtmlToTiffInReq.tiff"
842
- out_path = "HtmlTestDoc/" + name
843
- out_format = "tiff"
844
-
845
- answer = @instance.post_convert_document_in_request_to_image(out_path, out_format, file, opts)
846
-
847
- expect(answer[:status]).to eql(200)
848
-
849
- #Download converted file from storage
850
- res = download_file_helper(name)
851
- expect(res).to be_an_instance_of File
852
-
853
- #Move to test folder
854
- save_to_test_dir(res, name)
855
- end
856
-
857
- it "Upload and convert html to gif" do
858
- name = "postHtmlToGifInReq.gif"
859
- out_path = "HtmlTestDoc/" + name
860
- out_format = "gif"
861
-
862
- answer = @instance.post_convert_document_in_request_to_image(out_path, out_format, file, opts)
151
+ bottom_margin: 50
152
+ }
863
153
 
864
- expect(answer[:status]).to eql(200)
154
+ %w[jpeg jpg bmp png tiff tif gif].each { |ext|
155
+ it "Convert html to " + ext do
865
156
 
866
- #Download converted file from storage
867
- res = download_file_helper(name)
868
- expect(res).to be_an_instance_of File
157
+ dst = dst_dir + '/locToStorImgOpt.' + ext
158
+ answer = @html_api.convert_local_to_storage(src, dst, nil, opts)
869
159
 
870
- #Move to test folder
871
- save_to_test_dir(res, name)
160
+ expect(answer.code).to eql(200)
161
+ expect(answer.status).to eql('completed')
162
+ expect(@storage_api.object_exists(answer.file)).to be_truthy
163
+ end
164
+ }
872
165
  end
873
166
  end
874
167
 
875
- # unit tests for post_convert_document_in_request_to_image from epub format
876
- # Converts the EPUB document (in request content) to the specified image format and uploads resulting file to storage.
877
- #
878
- # @param out_path Full resulting filename (ex. /folder1/folder2/result.jpg)
879
- # @param out_format (jpeg, png, bmp, tiff, gif).
880
- # @param file A file to be converted (html, epub, svg).
881
- # @param [Hash] opts the optional parameters
882
- # @option opts [Integer] :width Resulting document page width in points (1/96 inch).
883
- # @option opts [Integer] :height Resulting document page height in points (1/96 inch).
884
- # @option opts [Integer] :left_margin Left resulting document page margin in points (1/96 inch).
885
- # @option opts [Integer] :right_margin Right resulting document page margin in points (1/96 inch).
886
- # @option opts [Integer] :top_margin Top resulting document page margin in points (1/96 inch).
887
- # @option opts [Integer] :bottom_margin Bottom resulting document page margin in points (1/96 inch).
888
- # @option opts [Integer] :resolution Resolution of resulting image. Default is 96 dpi.
889
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
890
- describe 'post_convert_epub_in_request_to_image test' do
891
- file = File.realpath(__dir__ + '/../../testdata/georgia.epub')
892
- opts = {
893
- width: 800,
894
- height: 1000,
895
- left_margin: 30,
896
- right_margin: 30,
897
- top_margin: 50,
898
- bottom_margin: 50,
899
- resolution: 300
900
- }
168
+ describe 'convert html storage to local' do
169
+ src = 'RubyTests/test1.html'
170
+ dst_dir = File.realpath(__dir__ + '/../../testresult') + '/'
901
171
 
902
- it "Upload and convert epub to jpeg" do
903
- name = "postEpubToJpegInReq.zip"
904
- out_path = "HtmlTestDoc/" + name
905
- out_format = "jpeg"
906
- answer = @instance.post_convert_document_in_request_to_image(out_path, out_format, file, opts)
172
+ uploaded_file = File.realpath(__dir__ + '/../../testdata') + '/test1.html'
907
173
 
908
- expect(answer[:status]).to eql(200)
174
+ describe 'convert storage to local html to doc' do
909
175
 
910
- #Download converted file from storage
911
- res = download_file_helper(name)
912
- expect(res).to be_an_instance_of File
176
+ %w[pdf xps docx md mhtml mht].each { |ext|
177
+ it "Convert html to " + ext do
178
+ res = @storage_api.upload_file("RubyTests", uploaded_file)
179
+ expect(res.uploaded.length).to eql(1)
180
+ expect(res.errors.length).to eql(0)
913
181
 
914
- #Move to test folder
915
- save_to_test_dir(res, name)
916
- end
182
+ dst = dst_dir + 'storToLocDoc.' + ext
183
+ answer = @html_api.convert_storage_to_local(src, dst, nil)
917
184
 
918
- it "Upload and convert epub to png" do
919
- name = "postEpubToPngInReq.zip"
920
- out_path = "HtmlTestDoc/" + name
921
- out_format = "png"
922
- answer = @instance.post_convert_document_in_request_to_image(out_path, out_format, file, opts)
923
-
924
- expect(answer[:status]).to eql(200)
925
-
926
- #Download converted file from storage
927
- res = download_file_helper(name)
928
- expect(res).to be_an_instance_of File
929
-
930
- #Move to test folder
931
- save_to_test_dir(res, name)
932
- end
933
-
934
- it "Upload and convert epub to bmp" do
935
- name = "postEpubToBmpInReq.zip"
936
- out_path = "HtmlTestDoc/" + name
937
- out_format = "bmp"
938
- answer = @instance.post_convert_document_in_request_to_image(out_path, out_format, file, opts)
939
-
940
- expect(answer[:status]).to eql(200)
941
-
942
- #Download converted file from storage
943
- res = download_file_helper(name)
944
- expect(res).to be_an_instance_of File
945
-
946
- #Move to test folder
947
- save_to_test_dir(res, name)
185
+ expect(answer.code).to eql(200)
186
+ expect(answer.status).to eql('completed')
187
+ expect(File.exist?(answer.file)).to be_truthy
188
+ end
189
+ }
948
190
  end
949
191
 
950
- it "Upload and convert epub to tiff" do
951
- name = "postEpubToTiffInReq.zip"
952
- out_path = "HtmlTestDoc/" + name
953
- out_format = "tiff"
954
- answer = @instance.post_convert_document_in_request_to_image(out_path, out_format, file, opts)
192
+ describe 'convert storage to local html to image' do
955
193
 
956
- expect(answer[:status]).to eql(200)
194
+ %w[jpeg jpg bmp png tiff tif gif].each { |ext|
195
+ it "Convert html to " + ext do
957
196
 
958
- #Download converted file from storage
959
- res = download_file_helper(name)
960
- expect(res).to be_an_instance_of File
197
+ dst = dst_dir + 'storToLocImg.' + ext
198
+ answer = @html_api.convert_storage_to_local(src, dst, nil)
961
199
 
962
- #Move to test folder
963
- save_to_test_dir(res, name)
200
+ expect(answer.code).to eql(200)
201
+ expect(answer.status).to eql('completed')
202
+ expect(File.exist?(answer.file)).to be_truthy
203
+ end
204
+ }
964
205
  end
965
206
 
966
- it "Upload and convert epub to gif" do
967
- name = "postEpubToGifInReq.zip"
968
- out_path = "HtmlTestDoc/" + name
969
- out_format = "gif"
970
- answer = @instance.post_convert_document_in_request_to_image(out_path, out_format, file, opts)
971
-
972
- expect(answer[:status]).to eql(200)
973
-
974
- #Download converted file from storage
975
- res = download_file_helper(name)
976
- expect(res).to be_an_instance_of File
977
-
978
- #Move to test folder
979
- save_to_test_dir(res, name)
980
- end
981
- end
207
+ describe 'convert storage to local html to image with options' do
982
208
 
983
- # unit tests for post_convert_document_in_request_to_image from svg format
984
- # Converts the SVG document (in request content) to the specified image format and uploads resulting file to storage.
985
- #
986
- # @param out_path Full resulting filename (ex. /folder1/folder2/result.jpg)
987
- # @param out_format (jpeg, png, bmp, tiff, gif).
988
- # @param file A file to be converted (html, epub, svg).
989
- # @param [Hash] opts the optional parameters
990
- # @option opts [Integer] :width Resulting document page width in points (1/96 inch).
991
- # @option opts [Integer] :height Resulting document page height in points (1/96 inch).
992
- # @option opts [Integer] :left_margin Left resulting document page margin in points (1/96 inch).
993
- # @option opts [Integer] :right_margin Right resulting document page margin in points (1/96 inch).
994
- # @option opts [Integer] :top_margin Top resulting document page margin in points (1/96 inch).
995
- # @option opts [Integer] :bottom_margin Bottom resulting document page margin in points (1/96 inch).
996
- # @option opts [Integer] :resolution Resolution of resulting image. Default is 96 dpi.
997
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
998
- describe 'post_convert_svg_in_request_to_image test' do
999
- file = File.realpath(__dir__ + '/../../testdata/Map-World.svg')
1000
- opts = {
209
+ opts = {
1001
210
  width: 800,
1002
211
  height: 1000,
1003
212
  left_margin: 30,
1004
213
  right_margin: 30,
1005
214
  top_margin: 50,
1006
- bottom_margin: 50,
1007
- resolution: 300
1008
- }
1009
-
1010
- it "Upload and convert svg to jpeg" do
1011
- name = "postSvgToJpegInReq.jpeg"
1012
- out_path = "HtmlTestDoc/" + name
1013
- out_format = "jpeg"
1014
-
1015
- answer = @instance.post_convert_document_in_request_to_image(out_path, out_format, file, opts)
1016
-
1017
- expect(answer[:status]).to eql(200)
1018
-
1019
- #Download converted file from storage
1020
- res = download_file_helper(name)
1021
- expect(res).to be_an_instance_of File
1022
-
1023
- #Move to test folder
1024
- save_to_test_dir(res, name)
1025
- end
1026
-
1027
- it "Upload and convert svg to png" do
1028
- name = "postSvgToPngInReq.png"
1029
- out_path = "HtmlTestDoc/" + name
1030
- out_format = "png"
1031
-
1032
- answer = @instance.post_convert_document_in_request_to_image(out_path, out_format, file, opts)
1033
-
1034
- expect(answer[:status]).to eql(200)
1035
-
1036
- #Download converted file from storage
1037
- res = download_file_helper(name)
1038
- expect(res).to be_an_instance_of File
1039
-
1040
- #Move to test folder
1041
- save_to_test_dir(res, name)
1042
- end
1043
-
1044
- it "Upload and convert svg to bmp" do
1045
- name = "postSvgToBmpInReq.bmp"
1046
- out_path = "HtmlTestDoc/" + name
1047
- out_format = "bmp"
1048
-
1049
- answer = @instance.post_convert_document_in_request_to_image(out_path, out_format, file, opts)
1050
-
1051
- expect(answer[:status]).to eql(200)
1052
-
1053
- #Download converted file from storage
1054
- res = download_file_helper(name)
1055
- expect(res).to be_an_instance_of File
1056
-
1057
- #Move to test folder
1058
- save_to_test_dir(res, name)
1059
- end
1060
-
1061
- it "Upload and convert svg to tiff" do
1062
- name = "postSvgToTiffInReq.tiff"
1063
- out_path = "HtmlTestDoc/" + name
1064
- out_format = "tiff"
1065
-
1066
- answer = @instance.post_convert_document_in_request_to_image(out_path, out_format, file, opts)
1067
-
1068
- expect(answer[:status]).to eql(200)
1069
-
1070
- #Download converted file from storage
1071
- res = download_file_helper(name)
1072
- expect(res).to be_an_instance_of File
1073
-
1074
- #Move to test folder
1075
- save_to_test_dir(res, name)
1076
- end
1077
-
1078
- it "Upload and convert svg to gif" do
1079
- name = "postSvgToGifInReq.gif"
1080
- out_path = "HtmlTestDoc/" + name
1081
- out_format = "gif"
1082
-
1083
- answer = @instance.post_convert_document_in_request_to_image(out_path, out_format, file, opts)
1084
-
1085
- expect(answer[:status]).to eql(200)
1086
-
1087
- #Download converted file from storage
1088
- res = download_file_helper(name)
1089
- expect(res).to be_an_instance_of File
1090
-
1091
- #Move to test folder
1092
- save_to_test_dir(res, name)
1093
- end
1094
- end
1095
-
1096
- # unit tests for post_convert_document_in_request_to_pdf from html format
1097
- # Converts the HTML document (in request content) to PDF and uploads resulting file to storage.
1098
- #
1099
- # @param out_path Full resulting filename (ex. /folder1/folder2/result.pdf)
1100
- # @param file A file to be converted.
1101
- # @param [Hash] opts the optional parameters
1102
- # @option opts [Integer] :width Resulting document page width in points (1/96 inch).
1103
- # @option opts [Integer] :height Resulting document page height in points (1/96 inch).
1104
- # @option opts [Integer] :left_margin Left resulting document page margin in points (1/96 inch).
1105
- # @option opts [Integer] :right_margin Right resulting document page margin in points (1/96 inch).
1106
- # @option opts [Integer] :top_margin Top resulting document page margin in points (1/96 inch).
1107
- # @option opts [Integer] :bottom_margin Bottom resulting document page margin in points (1/96 inch).
1108
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
1109
- describe 'post_convert_html_in_request_to_pdf test' do
1110
- it "Upload and convert html to pdf" do
1111
- name = "postHtmlToPdfInReq.pdf"
1112
- out_path = "HtmlTestDoc/" + name
1113
- file = File.realpath(__dir__ + '/../../testdata/test1.html')
1114
- opts = {
1115
- width: 800,
1116
- height: 1000,
1117
- left_margin: 30,
1118
- right_margin: 30,
1119
- top_margin: 50,
1120
- bottom_margin: 50
215
+ bottom_margin: 50
1121
216
  }
1122
217
 
1123
- answer = @instance.post_convert_document_in_request_to_pdf(out_path, file, opts)
218
+ %w[jpeg jpg bmp png tiff tif gif].each { |ext|
219
+ it "Convert html to " + ext do
1124
220
 
1125
- expect(answer[:status]).to eql(200)
221
+ dst = dst_dir + 'storToLocImgOpt.' + ext
222
+ answer = @html_api.convert_storage_to_local(src, dst, nil, opts)
1126
223
 
1127
- #Download converted file from storage
1128
- res = download_file_helper(name)
1129
- expect(res).to be_an_instance_of File
1130
-
1131
- #Move to test folder
1132
- save_to_test_dir(res, name)
1133
- end
1134
- end
1135
-
1136
- # unit tests for post_convert_document_in_request_to_pdf from epub format
1137
- # Converts the EPUB document (in request content) to PDF and uploads resulting file to storage.
1138
- #
1139
- # @param out_path Full resulting filename (ex. /folder1/folder2/result.pdf)
1140
- # @param file A file to be converted.
1141
- # @param [Hash] opts the optional parameters
1142
- # @option opts [Integer] :width Resulting document page width in points (1/96 inch).
1143
- # @option opts [Integer] :height Resulting document page height in points (1/96 inch).
1144
- # @option opts [Integer] :left_margin Left resulting document page margin in points (1/96 inch).
1145
- # @option opts [Integer] :right_margin Right resulting document page margin in points (1/96 inch).
1146
- # @option opts [Integer] :top_margin Top resulting document page margin in points (1/96 inch).
1147
- # @option opts [Integer] :bottom_margin Bottom resulting document page margin in points (1/96 inch).
1148
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
1149
- describe 'post_convert_epub_in_request_to_pdf test' do
1150
- it "Upload and convert epub to pdf" do
1151
- name = "postEpubToPdfInReq.pdf"
1152
- out_path = "HtmlTestDoc/" + name
1153
- file = File.realpath(__dir__ + '/../../testdata/georgia.epub')
1154
- opts = {
1155
- width: 800,
1156
- height: 1000,
1157
- left_margin: 30,
1158
- right_margin: 30,
1159
- top_margin: 50,
1160
- bottom_margin: 50
224
+ expect(answer.code).to eql(200)
225
+ expect(answer.status).to eql('completed')
226
+ expect(File.exist?(answer.file)).to be_truthy
227
+ end
1161
228
  }
1162
-
1163
- answer = @instance.post_convert_document_in_request_to_pdf(out_path, file, opts)
1164
-
1165
- expect(answer[:status]).to eql(200)
1166
-
1167
- #Download converted file from storage
1168
- res = download_file_helper(name)
1169
- expect(res).to be_an_instance_of File
1170
-
1171
- #Move to test folder
1172
- save_to_test_dir(res, name)
1173
229
  end
1174
230
  end
1175
231
 
1176
- # unit tests for post_convert_document_in_request_to_pdf from svg format
1177
- # Converts the SVG document (in request content) to PDF and uploads resulting file to storage.
1178
- #
1179
- # @param out_path Full resulting filename (ex. /folder1/folder2/result.pdf)
1180
- # @param file A file to be converted.
1181
- # @param [Hash] opts the optional parameters
1182
- # @option opts [Integer] :width Resulting document page width in points (1/96 inch).
1183
- # @option opts [Integer] :height Resulting document page height in points (1/96 inch).
1184
- # @option opts [Integer] :left_margin Left resulting document page margin in points (1/96 inch).
1185
- # @option opts [Integer] :right_margin Right resulting document page margin in points (1/96 inch).
1186
- # @option opts [Integer] :top_margin Top resulting document page margin in points (1/96 inch).
1187
- # @option opts [Integer] :bottom_margin Bottom resulting document page margin in points (1/96 inch).
1188
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
1189
- describe 'post_convert_svg_in_request_to_pdf test' do
1190
- it "Upload and convert svg to pdf" do
1191
- name = "postSvgToPdfInReq.pdf"
1192
- out_path = "HtmlTestDoc/" + name
1193
- file = File.realpath(__dir__ + '/../../testdata/Map-World.svg')
1194
- opts = {
1195
- width: 800,
1196
- height: 1000,
1197
- left_margin: 30,
1198
- right_margin: 30,
1199
- top_margin: 50,
1200
- bottom_margin: 50
1201
- }
232
+ describe 'convert html storage to storage' do
233
+ src = 'RubyTests/test1.html'
234
+ dst_dir = '/'
1202
235
 
1203
- answer = @instance.post_convert_document_in_request_to_pdf(out_path, file, opts)
236
+ uploaded_file = File.realpath(__dir__ + '/../../testdata') + '/test1.html'
1204
237
 
1205
- expect(answer[:status]).to eql(200)
238
+ describe 'convert storage to storage html to doc' do
1206
239
 
1207
- #Download converted file from storage
1208
- res = download_file_helper(name)
1209
- expect(res).to be_an_instance_of File
240
+ %w[pdf xps docx md mhtml mht].each { |ext|
241
+ it "Convert html to " + ext do
242
+ res = @storage_api.upload_file("RubyTests", uploaded_file)
243
+ expect(res.uploaded.length).to eql(1)
244
+ expect(res.errors.length).to eql(0)
1210
245
 
1211
- #Move to test folder
1212
- save_to_test_dir(res, name)
1213
- end
1214
- end
246
+ dst = dst_dir + 'storToStorDoc.' + ext
247
+ answer = @html_api.convert_storage_to_storage(src, dst, nil)
1215
248
 
1216
- # unit tests for post_convert_document_in_request_to_xps from html format
1217
- # Converts the HTML document (in request content) to XPS and uploads resulting file to storage.
1218
- #
1219
- # @param out_path Full resulting filename (ex. /folder1/folder2/result.xps)
1220
- # @param file A file to be converted.
1221
- # @param [Hash] opts the optional parameters
1222
- # @option opts [Integer] :width Resulting document page width in points (1/96 inch).
1223
- # @option opts [Integer] :height Resulting document page height in points (1/96 inch).
1224
- # @option opts [Integer] :left_margin Left resulting document page margin in points (1/96 inch).
1225
- # @option opts [Integer] :right_margin Right resulting document page margin in points (1/96 inch).
1226
- # @option opts [Integer] :top_margin Top resulting document page margin in points (1/96 inch).
1227
- # @option opts [Integer] :bottom_margin Bottom resulting document page margin in points (1/96 inch).
1228
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
1229
- describe 'post_convert_html_in_request_to_xps test' do
1230
- it "Upload and convert html to xps" do
1231
- name = "postHtmlToXpsInReq.xps"
1232
- out_path = "HtmlTestDoc/" + name
1233
- file = File.realpath(__dir__ + '/../../testdata/test1.html')
1234
- opts = {
1235
- width: 800,
1236
- height: 1000,
1237
- left_margin: 30,
1238
- right_margin: 30,
1239
- top_margin: 50,
1240
- bottom_margin: 50
249
+ expect(answer.code).to eql(200)
250
+ expect(answer.status).to eql('completed')
251
+ expect(@storage_api.object_exists(answer.file)).to be_truthy
252
+ end
1241
253
  }
1242
-
1243
- answer = @instance.post_convert_document_in_request_to_xps(out_path, file, opts)
1244
-
1245
- expect(answer[:status]).to eql(200)
1246
-
1247
- #Download converted file from storage
1248
- res = download_file_helper(name)
1249
- expect(res).to be_an_instance_of File
1250
-
1251
- #Move to test folder
1252
- save_to_test_dir(res, name)
1253
254
  end
1254
- end
1255
-
1256
- # unit tests for post_convert_document_in_request_to_xps from epub format
1257
- # Converts the EPUB document (in request content) to XPS and uploads resulting file to storage.
1258
- #
1259
- # @param out_path Full resulting filename (ex. /folder1/folder2/result.xps)
1260
- # @param file A file to be converted.
1261
- # @param [Hash] opts the optional parameters
1262
- # @option opts [Integer] :width Resulting document page width in points (1/96 inch).
1263
- # @option opts [Integer] :height Resulting document page height in points (1/96 inch).
1264
- # @option opts [Integer] :left_margin Left resulting document page margin in points (1/96 inch).
1265
- # @option opts [Integer] :right_margin Right resulting document page margin in points (1/96 inch).
1266
- # @option opts [Integer] :top_margin Top resulting document page margin in points (1/96 inch).
1267
- # @option opts [Integer] :bottom_margin Bottom resulting document page margin in points (1/96 inch).
1268
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
1269
- describe 'post_convert_epub_in_request_to_xps test' do
1270
- it "Upload and convert epub to xps" do
1271
- name = "postEpubToXpsInReq.xps"
1272
- out_path = "HtmlTestDoc/" + name
1273
- file = File.realpath(__dir__ + '/../../testdata/georgia.epub')
1274
- opts = {
1275
- width: 800,
1276
- height: 1000,
1277
- left_margin: 30,
1278
- right_margin: 30,
1279
- top_margin: 50,
1280
- bottom_margin: 50
1281
- }
1282
255
 
1283
- answer = @instance.post_convert_document_in_request_to_xps(out_path, file, opts)
256
+ describe 'convert storage to storage html to image' do
1284
257
 
1285
- expect(answer[:status]).to eql(200)
258
+ %w[jpeg jpg bmp png tiff tif gif].each { |ext|
259
+ it "Convert html to " + ext do
1286
260
 
1287
- #Download converted file from storage
1288
- res = download_file_helper(name)
1289
- expect(res).to be_an_instance_of File
261
+ dst = dst_dir + 'storToStorImg.' + ext
262
+ answer = @html_api.convert_storage_to_storage(src, dst, nil)
1290
263
 
1291
- #Move to test folder
1292
- save_to_test_dir(res, name)
1293
- end
1294
- end
1295
-
1296
- # unit tests for post_convert_document_in_request_to_xps from svg format
1297
- # Converts the SVG document (in request content) to XPS and uploads resulting file to storage.
1298
- #
1299
- # @param out_path Full resulting filename (ex. /folder1/folder2/result.xps)
1300
- # @param file A file to be converted.
1301
- # @param [Hash] opts the optional parameters
1302
- # @option opts [Integer] :width Resulting document page width in points (1/96 inch).
1303
- # @option opts [Integer] :height Resulting document page height in points (1/96 inch).
1304
- # @option opts [Integer] :left_margin Left resulting document page margin in points (1/96 inch).
1305
- # @option opts [Integer] :right_margin Right resulting document page margin in points (1/96 inch).
1306
- # @option opts [Integer] :top_margin Top resulting document page margin in points (1/96 inch).
1307
- # @option opts [Integer] :bottom_margin Bottom resulting document page margin in points (1/96 inch).
1308
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
1309
- describe 'post_convert_svg_in_request_to_xps test' do
1310
- it "Upload and convert svg to xps" do
1311
- name = "postSvgToXpsInReq.xps"
1312
- out_path = "HtmlTestDoc/" + name
1313
- file = File.realpath(__dir__ + '/../../testdata/Map-World.svg')
1314
- opts = {
1315
- width: 800,
1316
- height: 1000,
1317
- left_margin: 30,
1318
- right_margin: 30,
1319
- top_margin: 50,
1320
- bottom_margin: 50
264
+ expect(answer.code).to eql(200)
265
+ expect(answer.status).to eql('completed')
266
+ expect(@storage_api.object_exists(answer.file)).to be_truthy
267
+ end
1321
268
  }
1322
-
1323
- answer = @instance.post_convert_document_in_request_to_xps(out_path, file, opts)
1324
-
1325
- expect(answer[:status]).to eql(200)
1326
-
1327
- #Download converted file from storage
1328
- res = download_file_helper(name)
1329
- expect(res).to be_an_instance_of File
1330
-
1331
- #Move to test folder
1332
- save_to_test_dir(res, name)
1333
- end
1334
- end
1335
-
1336
- # unit tests for put_convert_document_to_image from html format
1337
- # Converts the HTML document (located on storage) to the specified image format and uploads resulting file to storage.
1338
- #
1339
- # @param name Document name.
1340
- # @param out_path Full resulting filename (ex. /folder1/folder2/result.jpg)
1341
- # @param out_format (jpeg, png, bmp, tiff, gif)
1342
- # @param [Hash] opts the optional parameters
1343
- # @option opts [Integer] :width Resulting document page width in points (1/96 inch).
1344
- # @option opts [Integer] :height Resulting document page height in points (1/96 inch).
1345
- # @option opts [Integer] :left_margin Left resulting document page margin in points (1/96 inch).
1346
- # @option opts [Integer] :right_margin Right resulting document page margin in points (1/96 inch).
1347
- # @option opts [Integer] :top_margin Top resulting document page margin in points (1/96 inch).
1348
- # @option opts [Integer] :bottom_margin Bottom resulting document page margin in points (1/96 inch).
1349
- # @option opts [Integer] :resolution Resolution of resulting image. Default is 96 dpi.
1350
- # @option opts [String] :folder The source document folder.
1351
- # @option opts [String] :storage The source and resulting document storage.
1352
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
1353
- describe 'put_convert_html_to_image test' do
1354
- # Already in the storage
1355
- name = "test1.html"
1356
- opts = {
1357
- width: 800,
1358
- height: 1000,
1359
- left_margin: 30,
1360
- right_margin: 30,
1361
- top_margin: 50,
1362
- bottom_margin: 50,
1363
- resolution: 300,
1364
- folder: "HtmlTestDoc",
1365
- storage: nil
1366
- }
1367
-
1368
- it "Convert html to jpeg in storage" do
1369
- result_name = "putHtmlToJpeg.jpeg"
1370
- out_path = "HtmlTestDoc/" + result_name
1371
- out_format = "jpeg"
1372
-
1373
- answer = @instance.put_convert_document_to_image(name, out_path, out_format, opts)
1374
-
1375
- expect(answer[:status]).to eql(200)
1376
-
1377
- #Download converted file from storage
1378
- res = download_file_helper(result_name)
1379
- expect(res).to be_an_instance_of File
1380
-
1381
- #Move to test folder
1382
- save_to_test_dir(res, result_name)
1383
- end
1384
-
1385
- it "Convert html to png in storage" do
1386
- result_name = "putHtmlToPng.png"
1387
- out_path = "HtmlTestDoc/" + result_name
1388
- out_format = "png"
1389
-
1390
- answer = @instance.put_convert_document_to_image(name, out_path, out_format, opts)
1391
-
1392
- expect(answer[:status]).to eql(200)
1393
-
1394
- #Download converted file from storage
1395
- res = download_file_helper(result_name)
1396
- expect(res).to be_an_instance_of File
1397
-
1398
- #Move to test folder
1399
- save_to_test_dir(res, result_name)
1400
- end
1401
-
1402
- it "Convert html to bmp in storage" do
1403
- result_name = "putHtmlToBmp.bmp"
1404
- out_path = "HtmlTestDoc/" + result_name
1405
- out_format = "bmp"
1406
-
1407
- answer = @instance.put_convert_document_to_image(name, out_path, out_format, opts)
1408
-
1409
- expect(answer[:status]).to eql(200)
1410
-
1411
- #Download converted file from storage
1412
- res = download_file_helper(result_name)
1413
- expect(res).to be_an_instance_of File
1414
-
1415
- #Move to test folder
1416
- save_to_test_dir(res, result_name)
1417
269
  end
1418
270
 
1419
- it "Convert html to tiff in storage" do
1420
- result_name = "putHtmlToTiff.tiff"
1421
- out_path = "HtmlTestDoc/" + result_name
1422
- out_format = "tiff"
1423
-
1424
- answer = @instance.put_convert_document_to_image(name, out_path, out_format, opts)
1425
-
1426
- expect(answer[:status]).to eql(200)
1427
-
1428
- #Download converted file from storage
1429
- res = download_file_helper(result_name)
1430
- expect(res).to be_an_instance_of File
1431
-
1432
- #Move to test folder
1433
- save_to_test_dir(res, result_name)
1434
- end
1435
-
1436
- it "Convert html to gif in storage" do
1437
- result_name = "putHtmlToGif.gif"
1438
- out_path = "HtmlTestDoc/" + result_name
1439
- out_format = "gif"
1440
-
1441
- answer = @instance.put_convert_document_to_image(name, out_path, out_format, opts)
271
+ describe 'convert storage to storage html to image with options' do
1442
272
 
1443
- expect(answer[:status]).to eql(200)
1444
-
1445
- #Download converted file from storage
1446
- res = download_file_helper(result_name)
1447
- expect(res).to be_an_instance_of File
1448
-
1449
- #Move to test folder
1450
- save_to_test_dir(res, result_name)
1451
- end
1452
- end
1453
-
1454
- # unit tests for put_convert_document_to_image from epub format
1455
- # Converts the EPUB document (located on storage) to the specified image format and uploads resulting file to storage.
1456
- #
1457
- # @param name Document name.
1458
- # @param out_path Full resulting filename (ex. /folder1/folder2/result.jpg)
1459
- # @param out_format (jpeg, png, bmp, tiff, gif)
1460
- # @param [Hash] opts the optional parameters
1461
- # @option opts [Integer] :width Resulting document page width in points (1/96 inch).
1462
- # @option opts [Integer] :height Resulting document page height in points (1/96 inch).
1463
- # @option opts [Integer] :left_margin Left resulting document page margin in points (1/96 inch).
1464
- # @option opts [Integer] :right_margin Right resulting document page margin in points (1/96 inch).
1465
- # @option opts [Integer] :top_margin Top resulting document page margin in points (1/96 inch).
1466
- # @option opts [Integer] :bottom_margin Bottom resulting document page margin in points (1/96 inch).
1467
- # @option opts [Integer] :resolution Resolution of resulting image. Default is 96 dpi.
1468
- # @option opts [String] :folder The source document folder.
1469
- # @option opts [String] :storage The source and resulting document storage.
1470
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
1471
- describe 'put_convert_epub_to_image test' do
1472
-
1473
- # Already in the storage
1474
- name = "georgia.epub"
1475
- opts = {
273
+ opts = {
1476
274
  width: 800,
1477
275
  height: 1000,
1478
276
  left_margin: 30,
1479
277
  right_margin: 30,
1480
278
  top_margin: 50,
1481
- bottom_margin: 50,
1482
- resolution: 300,
1483
- folder: "HtmlTestDoc",
1484
- storage: nil
1485
- }
1486
-
1487
- it "Convert epub to jpeg in storage" do
1488
-
1489
- result_name = "putEpubToJpeg.zip"
1490
- out_path = "HtmlTestDoc/" + result_name
1491
- out_format = "jpeg"
1492
-
1493
- answer = @instance.put_convert_document_to_image(name, out_path, out_format, opts)
279
+ bottom_margin: 50
280
+ }
1494
281
 
1495
- expect(answer[:status]).to eql(200)
282
+ %w[jpeg jpg bmp png tiff tif gif].each { |ext|
283
+ it "Convert html to " + ext do
1496
284
 
1497
- #Download converted file from storage
1498
- res = download_file_helper(result_name)
1499
- expect(res).to be_an_instance_of File
285
+ dst = dst_dir + 'storToStorImgOpt.' + ext
286
+ answer = @html_api.convert_storage_to_storage(src, dst, nil, opts)
1500
287
 
1501
- #Move to test folder
1502
- save_to_test_dir(res, result_name)
288
+ expect(answer.code).to eql(200)
289
+ expect(answer.status).to eql('completed')
290
+ expect(@storage_api.object_exists(answer.file)).to be_truthy
291
+ end
292
+ }
1503
293
  end
294
+ end
1504
295
 
1505
- it "Convert epub to png in storage" do
1506
- result_name = "putEpubToPng.zip"
1507
- out_path = "HtmlTestDoc/" + result_name
1508
- out_format = "png"
1509
-
1510
- answer = @instance.put_convert_document_to_image(name, out_path, out_format, opts)
1511
-
1512
- expect(answer[:status]).to eql(200)
1513
-
1514
- #Download converted file from storage
1515
- res = download_file_helper(result_name)
1516
- expect(res).to be_an_instance_of File
1517
-
1518
- #Move to test folder
1519
- save_to_test_dir(res, result_name)
1520
- end
296
+ describe 'convert url to local' do
1521
297
 
1522
- it "Convert epub to bmp in storage" do
1523
- result_name = "putEpubToBmp.zip"
1524
- out_path = "HtmlTestDoc/" + result_name
1525
- out_format = "bmp"
298
+ src = 'https://stallman.org/articles/anonymous-payments-thru-phones.html'
299
+ dst_dir = File.realpath(__dir__ + '/../../testresult') + '/'
1526
300
 
1527
- answer = @instance.put_convert_document_to_image(name, out_path, out_format, opts)
301
+ describe 'convert url to local doc' do
1528
302
 
1529
- expect(answer[:status]).to eql(200)
303
+ %w[pdf xps docx md mhtml mht].each { |ext|
304
+ it "Convert url to " + ext do
1530
305
 
1531
- #Download converted file from storage
1532
- res = download_file_helper(result_name)
1533
- expect(res).to be_an_instance_of File
306
+ dst = dst_dir + 'urlLocDoc.' + ext
307
+ answer = @html_api.convert_url_to_local(src, dst)
1534
308
 
1535
- #Move to test folder
1536
- save_to_test_dir(res, result_name)
309
+ expect(answer.code).to eql(200)
310
+ expect(answer.status).to eql('completed')
311
+ expect(File.exist?(answer.file)).to be_truthy
312
+ end
313
+ }
1537
314
  end
1538
315
 
1539
- it "Convert epub to tiff in storage" do
1540
- result_name = "putEpubToTiff.zip"
1541
- out_path = "HtmlTestDoc/" + result_name
1542
- out_format = "tiff"
316
+ describe 'convert url to local image' do
1543
317
 
1544
- answer = @instance.put_convert_document_to_image(name, out_path, out_format, opts)
318
+ %w[jpeg jpg bmp png tiff tif gif].each { |ext|
319
+ it "Convert url to " + ext do
1545
320
 
1546
- expect(answer[:status]).to eql(200)
321
+ dst = dst_dir + 'urlLocImg.' + ext
322
+ answer = @html_api.convert_url_to_local(src, dst)
1547
323
 
1548
- #Download converted file from storage
1549
- res = download_file_helper(result_name)
1550
- expect(res).to be_an_instance_of File
1551
-
1552
- #Move to test folder
1553
- save_to_test_dir(res, result_name)
324
+ expect(answer.code).to eql(200)
325
+ expect(answer.status).to eql('completed')
326
+ expect(File.exist?(answer.file)).to be_truthy
327
+ end
328
+ }
1554
329
  end
1555
330
 
1556
- it "Convert epub to gif in storage" do
1557
- result_name = "putEpubToGif.zip"
1558
- out_path = "HtmlTestDoc/" + result_name
1559
- out_format = "gif"
1560
-
1561
- answer = @instance.put_convert_document_to_image(name, out_path, out_format, opts)
331
+ describe 'convert url to local image with options' do
1562
332
 
1563
- expect(answer[:status]).to eql(200)
1564
-
1565
- #Download converted file from storage
1566
- res = download_file_helper(result_name)
1567
- expect(res).to be_an_instance_of File
1568
-
1569
- #Move to test folder
1570
- save_to_test_dir(res, result_name)
1571
- end
1572
- end
1573
-
1574
- # unit tests for put_convert_document_to_image from svg format
1575
- # Converts the SVG document (located on storage) to the specified image format and uploads resulting file to storage.
1576
- #
1577
- # @param name Document name.
1578
- # @param out_path Full resulting filename (ex. /folder1/folder2/result.jpg)
1579
- # @param out_format (jpeg, png, bmp, tiff, gif)
1580
- # @param [Hash] opts the optional parameters
1581
- # @option opts [Integer] :width Resulting document page width in points (1/96 inch).
1582
- # @option opts [Integer] :height Resulting document page height in points (1/96 inch).
1583
- # @option opts [Integer] :left_margin Left resulting document page margin in points (1/96 inch).
1584
- # @option opts [Integer] :right_margin Right resulting document page margin in points (1/96 inch).
1585
- # @option opts [Integer] :top_margin Top resulting document page margin in points (1/96 inch).
1586
- # @option opts [Integer] :bottom_margin Bottom resulting document page margin in points (1/96 inch).
1587
- # @option opts [Integer] :resolution Resolution of resulting image. Default is 96 dpi.
1588
- # @option opts [String] :folder The source document folder.
1589
- # @option opts [String] :storage The source and resulting document storage.
1590
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
1591
- describe 'put_convert_svg_to_image test' do
1592
- # Already in the storage
1593
- name = "Map-World.svg"
1594
- opts = {
333
+ opts = {
1595
334
  width: 800,
1596
335
  height: 1000,
1597
336
  left_margin: 30,
1598
337
  right_margin: 30,
1599
338
  top_margin: 50,
1600
- bottom_margin: 50,
1601
- resolution: 300,
1602
- folder: "HtmlTestDoc",
1603
- storage: nil
1604
- }
1605
-
1606
- it "Convert svg to jpeg in storage" do
1607
- result_name = "putSvgToJpeg.png"
1608
- out_path = "HtmlTestDoc/" + result_name
1609
- out_format = "jpeg"
1610
-
1611
- answer = @instance.put_convert_document_to_image(name, out_path, out_format, opts)
1612
-
1613
- expect(answer[:status]).to eql(200)
1614
-
1615
- #Download converted file from storage
1616
- res = download_file_helper(result_name)
1617
- expect(res).to be_an_instance_of File
1618
-
1619
- #Move to test folder
1620
- save_to_test_dir(res, result_name)
1621
- end
1622
-
1623
- it "Convert svg to png in storage" do
1624
- result_name = "putSvgToPng.png"
1625
- out_path = "HtmlTestDoc/" + result_name
1626
- out_format = "png"
1627
-
1628
- answer = @instance.put_convert_document_to_image(name, out_path, out_format, opts)
1629
-
1630
- expect(answer[:status]).to eql(200)
1631
-
1632
- #Download converted file from storage
1633
- res = download_file_helper(result_name)
1634
- expect(res).to be_an_instance_of File
1635
-
1636
- #Move to test folder
1637
- save_to_test_dir(res, result_name)
1638
- end
1639
-
1640
- it "Convert svg to bmp in storage" do
1641
- result_name = "putSvgToBmp.bmp"
1642
- out_path = "HtmlTestDoc/" + result_name
1643
- out_format = "bmp"
1644
-
1645
- answer = @instance.put_convert_document_to_image(name, out_path, out_format, opts)
1646
-
1647
- expect(answer[:status]).to eql(200)
1648
-
1649
- #Download converted file from storage
1650
- res = download_file_helper(result_name)
1651
- expect(res).to be_an_instance_of File
1652
-
1653
- #Move to test folder
1654
- save_to_test_dir(res, result_name)
1655
- end
1656
-
1657
- it "Convert svg to tiff in storage" do
1658
- result_name = "putSvgToTiff.tiff"
1659
- out_path = "HtmlTestDoc/" + result_name
1660
- out_format = "tiff"
1661
-
1662
- answer = @instance.put_convert_document_to_image(name, out_path, out_format, opts)
1663
-
1664
- expect(answer[:status]).to eql(200)
1665
-
1666
- #Download converted file from storage
1667
- res = download_file_helper(result_name)
1668
- expect(res).to be_an_instance_of File
1669
-
1670
- #Move to test folder
1671
- save_to_test_dir(res, result_name)
1672
- end
1673
-
1674
- it "Convert svg to gif in storage" do
1675
- result_name = "putSvgToGif.gif"
1676
- out_path = "HtmlTestDoc/" + result_name
1677
- out_format = "gif"
1678
-
1679
- answer = @instance.put_convert_document_to_image(name, out_path, out_format, opts)
1680
-
1681
- expect(answer[:status]).to eql(200)
1682
-
1683
- #Download converted file from storage
1684
- res = download_file_helper(result_name)
1685
- expect(res).to be_an_instance_of File
1686
-
1687
- #Move to test folder
1688
- save_to_test_dir(res, result_name)
1689
- end
1690
- end
1691
-
1692
- # unit tests for put_convert_document_to_pdf from html format
1693
- # Converts the HTML document (located on storage) to PDF and uploads resulting file to storage.
1694
- #
1695
- # @param name Document name.
1696
- # @param out_path Full resulting filename (ex. /folder1/folder2/result.pdf)
1697
- # @param [Hash] opts the optional parameters
1698
- # @option opts [Integer] :width Resulting document page width in points (1/96 inch).
1699
- # @option opts [Integer] :height Resulting document page height in points (1/96 inch).
1700
- # @option opts [Integer] :left_margin Left resulting document page margin in points (1/96 inch).
1701
- # @option opts [Integer] :right_margin Right resulting document page margin in points (1/96 inch).
1702
- # @option opts [Integer] :top_margin Top resulting document page margin in points (1/96 inch).
1703
- # @option opts [Integer] :bottom_margin Bottom resulting document page margin in points (1/96 inch).
1704
- # @option opts [String] :folder The source document folder.
1705
- # @option opts [String] :storage The source and resulting document storage.
1706
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
1707
- describe 'put_convert_html_to_pdf test' do
1708
- it "Convert html to pdf in storage" do
1709
-
1710
- # Already in the storage
1711
- name = "test1.html"
1712
- result_name = "putHtmlToPdf.pdf"
1713
- out_path = "HtmlTestDoc/" + result_name
1714
- opts = {
1715
- width: 800,
1716
- height: 1000,
1717
- left_margin: 30,
1718
- right_margin: 30,
1719
- top_margin: 50,
1720
- bottom_margin: 50,
1721
- folder: "HtmlTestDoc",
1722
- storage: nil
1723
- }
1724
-
1725
- answer = @instance.put_convert_document_to_pdf(name, out_path, opts)
1726
-
1727
- expect(answer[:status]).to eql(200)
1728
-
1729
- #Download converted file from storage
1730
- res = download_file_helper(result_name)
1731
- expect(res).to be_an_instance_of File
1732
-
1733
- #Move to test folder
1734
- save_to_test_dir(res, result_name)
1735
- end
1736
- end
1737
-
1738
- # unit tests for put_convert_document_to_pdf from epub format
1739
- # Converts the EPUB document (located on storage) to PDF and uploads resulting file to storage.
1740
- #
1741
- # @param name Document name.
1742
- # @param out_path Full resulting filename (ex. /folder1/folder2/result.pdf)
1743
- # @param [Hash] opts the optional parameters
1744
- # @option opts [Integer] :width Resulting document page width in points (1/96 inch).
1745
- # @option opts [Integer] :height Resulting document page height in points (1/96 inch).
1746
- # @option opts [Integer] :left_margin Left resulting document page margin in points (1/96 inch).
1747
- # @option opts [Integer] :right_margin Right resulting document page margin in points (1/96 inch).
1748
- # @option opts [Integer] :top_margin Top resulting document page margin in points (1/96 inch).
1749
- # @option opts [Integer] :bottom_margin Bottom resulting document page margin in points (1/96 inch).
1750
- # @option opts [String] :folder The source document folder.
1751
- # @option opts [String] :storage The source and resulting document storage.
1752
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
1753
- describe 'put_convert_epub_to_pdf test' do
1754
- it "Convert epub to pdf in storage" do
1755
-
1756
- # Already in the storage
1757
- name = "georgia.epub"
1758
- result_name = "putEpubToPdf.pdf"
1759
- out_path = "HtmlTestDoc/" + result_name
1760
- opts = {
1761
- width: 800,
1762
- height: 1000,
1763
- left_margin: 30,
1764
- right_margin: 30,
1765
- top_margin: 50,
1766
- bottom_margin: 50,
1767
- folder: "HtmlTestDoc",
1768
- storage: nil
339
+ bottom_margin: 50
1769
340
  }
1770
341
 
1771
- answer = @instance.put_convert_document_to_pdf(name, out_path, opts)
342
+ %w[jpeg jpg bmp png tiff tif gif].each { |ext|
343
+ it "Convert url to " + ext do
1772
344
 
1773
- expect(answer[:status]).to eql(200)
345
+ dst = dst_dir + 'urlLocImgOpt.' + ext
346
+ answer = @html_api.convert_url_to_local(src, dst, opts)
1774
347
 
1775
- #Download converted file from storage
1776
- res = download_file_helper(result_name)
1777
- expect(res).to be_an_instance_of File
1778
-
1779
- #Move to test folder
1780
- save_to_test_dir(res, result_name)
1781
- end
1782
- end
1783
-
1784
- # unit tests for put_convert_document_to_pdf from svg format
1785
- # Converts the SVG document (located on storage) to PDF and uploads resulting file to storage.
1786
- #
1787
- # @param name Document name.
1788
- # @param out_path Full resulting filename (ex. /folder1/folder2/result.pdf)
1789
- # @param [Hash] opts the optional parameters
1790
- # @option opts [Integer] :width Resulting document page width in points (1/96 inch).
1791
- # @option opts [Integer] :height Resulting document page height in points (1/96 inch).
1792
- # @option opts [Integer] :left_margin Left resulting document page margin in points (1/96 inch).
1793
- # @option opts [Integer] :right_margin Right resulting document page margin in points (1/96 inch).
1794
- # @option opts [Integer] :top_margin Top resulting document page margin in points (1/96 inch).
1795
- # @option opts [Integer] :bottom_margin Bottom resulting document page margin in points (1/96 inch).
1796
- # @option opts [String] :folder The source document folder.
1797
- # @option opts [String] :storage The source and resulting document storage.
1798
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
1799
- describe 'put_convert_svg_to_pdf test' do
1800
- it "Convert svg to pdf in storage" do
1801
-
1802
- # Already in the storage
1803
- name = "Map-World.svg"
1804
- result_name = "putSvgToPdf.pdf"
1805
- out_path = "HtmlTestDoc/" + result_name
1806
- opts = {
1807
- width: 800,
1808
- height: 1000,
1809
- left_margin: 30,
1810
- right_margin: 30,
1811
- top_margin: 50,
1812
- bottom_margin: 50,
1813
- folder: "HtmlTestDoc",
1814
- storage: nil
348
+ expect(answer.code).to eql(200)
349
+ expect(answer.status).to eql('completed')
350
+ expect(File.exist?(answer.file)).to be_truthy
351
+ end
1815
352
  }
1816
-
1817
- answer = @instance.put_convert_document_to_pdf(name, out_path, opts)
1818
-
1819
- expect(answer[:status]).to eql(200)
1820
-
1821
- #Download converted file from storage
1822
- res = download_file_helper(result_name)
1823
- expect(res).to be_an_instance_of File
1824
-
1825
- #Move to test folder
1826
- save_to_test_dir(res, result_name)
1827
353
  end
1828
354
  end
1829
355
 
1830
- # unit tests for put_convert_document_to_xps from html format
1831
- # Converts the HTML document (located on storage) to XPS and uploads resulting file to storage.
1832
- #
1833
- # @param name Document name.
1834
- # @param out_path Full resulting filename (ex. /folder1/folder2/result.xps)
1835
- # @param [Hash] opts the optional parameters
1836
- # @option opts [Integer] :width Resulting document page width in points (1/96 inch).
1837
- # @option opts [Integer] :height Resulting document page height in points (1/96 inch).
1838
- # @option opts [Integer] :left_margin Left resulting document page margin in points (1/96 inch).
1839
- # @option opts [Integer] :right_margin Right resulting document page margin in points (1/96 inch).
1840
- # @option opts [Integer] :top_margin Top resulting document page margin in points (1/96 inch).
1841
- # @option opts [Integer] :bottom_margin Bottom resulting document page margin in points (1/96 inch).
1842
- # @option opts [String] :folder The source document folder.
1843
- # @option opts [String] :storage The source and resulting document storage.
1844
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
1845
- describe 'put_convert_html_to_xps test' do
1846
- it "Convert html to xps in storage" do
1847
-
1848
- # Already in the storage
1849
- name = "test1.html"
1850
- result_name = "putHtmlToXps.xps"
1851
- out_path = "HtmlTestDoc/" + result_name
1852
- opts = {
1853
- width: 800,
1854
- height: 1000,
1855
- left_margin: 30,
1856
- right_margin: 30,
1857
- top_margin: 50,
1858
- bottom_margin: 50,
1859
- folder: "HtmlTestDoc",
1860
- storage: nil
1861
- }
356
+ describe 'convert url to storage' do
357
+ src = 'https://stallman.org/articles/anonymous-payments-thru-phones.html'
358
+ dst_dir = 'RubyTests'
1862
359
 
1863
- answer = @instance.put_convert_document_to_xps(name, out_path, opts)
360
+ describe 'convert url to storage doc' do
1864
361
 
1865
- expect(answer[:status]).to eql(200)
362
+ %w[pdf xps docx md mhtml mht].each { |ext|
363
+ it "Convert url to " + ext do
1866
364
 
1867
- #Download converted file from storage
1868
- res = download_file_helper(result_name)
1869
- expect(res).to be_an_instance_of File
1870
-
1871
- #Move to test folder
1872
- save_to_test_dir(res, result_name)
1873
- end
1874
- end
365
+ dst = dst_dir + '/urlStorDoc.' + ext
366
+ answer = @html_api.convert_url_to_storage(src, dst, nil)
1875
367
 
1876
- # unit tests for put_convert_document_to_xps from epub format
1877
- # Converts the EPUB document (located on storage) to XPS and uploads resulting file to storage.
1878
- #
1879
- # @param name Document name.
1880
- # @param out_path Full resulting filename (ex. /folder1/folder2/result.xps)
1881
- # @param [Hash] opts the optional parameters
1882
- # @option opts [Integer] :width Resulting document page width in points (1/96 inch).
1883
- # @option opts [Integer] :height Resulting document page height in points (1/96 inch).
1884
- # @option opts [Integer] :left_margin Left resulting document page margin in points (1/96 inch).
1885
- # @option opts [Integer] :right_margin Right resulting document page margin in points (1/96 inch).
1886
- # @option opts [Integer] :top_margin Top resulting document page margin in points (1/96 inch).
1887
- # @option opts [Integer] :bottom_margin Bottom resulting document page margin in points (1/96 inch).
1888
- # @option opts [String] :folder The source document folder.
1889
- # @option opts [String] :storage The source and resulting document storage.
1890
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
1891
- describe 'put_convert_epub_to_xps test' do
1892
- it "Convert epub to xps in storage" do
1893
-
1894
- # Already in the storage
1895
- name = "georgia.epub"
1896
- result_name = "putEpubToXps.xps"
1897
- out_path = "HtmlTestDoc/" + result_name
1898
- opts = {
1899
- width: 800,
1900
- height: 1000,
1901
- left_margin: 30,
1902
- right_margin: 30,
1903
- top_margin: 50,
1904
- bottom_margin: 50,
1905
- folder: "HtmlTestDoc",
1906
- storage: nil
368
+ expect(answer.code).to eql(200)
369
+ expect(answer.status).to eql('completed')
370
+ expect(@storage_api.object_exists(answer.file)).to be_truthy
371
+ end
1907
372
  }
1908
-
1909
- answer = @instance.put_convert_document_to_xps(name, out_path, opts)
1910
-
1911
- expect(answer[:status]).to eql(200)
1912
-
1913
- #Download converted file from storage
1914
- res = download_file_helper(result_name)
1915
- expect(res).to be_an_instance_of File
1916
-
1917
- #Move to test folder
1918
- save_to_test_dir(res, result_name)
1919
373
  end
1920
- end
1921
-
1922
- # unit tests for put_convert_document_to_xps from svg format
1923
- # Converts the SVG document (located on storage) to XPS and uploads resulting file to storage.
1924
- #
1925
- # @param name Document name.
1926
- # @param out_path Full resulting filename (ex. /folder1/folder2/result.xps)
1927
- # @param [Hash] opts the optional parameters
1928
- # @option opts [Integer] :width Resulting document page width in points (1/96 inch).
1929
- # @option opts [Integer] :height Resulting document page height in points (1/96 inch).
1930
- # @option opts [Integer] :left_margin Left resulting document page margin in points (1/96 inch).
1931
- # @option opts [Integer] :right_margin Right resulting document page margin in points (1/96 inch).
1932
- # @option opts [Integer] :top_margin Top resulting document page margin in points (1/96 inch).
1933
- # @option opts [Integer] :bottom_margin Bottom resulting document page margin in points (1/96 inch).
1934
- # @option opts [String] :folder The source document folder.
1935
- # @option opts [String] :storage The source and resulting document storage.
1936
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
1937
- describe 'put_convert_svg_to_xps test' do
1938
- it "Convert svg to xps in storage" do
1939
-
1940
- # Already in the storage
1941
- name = "Map-World.svg"
1942
- result_name = "putSvgToXps.xps"
1943
- out_path = "HtmlTestDoc/" + result_name
1944
- opts = {
1945
- width: 800,
1946
- height: 1000,
1947
- left_margin: 30,
1948
- right_margin: 30,
1949
- top_margin: 50,
1950
- bottom_margin: 50,
1951
- folder: "HtmlTestDoc",
1952
- storage: nil
1953
- }
1954
374
 
1955
- answer = @instance.put_convert_document_to_xps(name, out_path, opts)
375
+ describe 'convert url to storage image' do
1956
376
 
1957
- expect(answer[:status]).to eql(200)
377
+ %w[jpeg jpg bmp png tiff tif gif].each { |ext|
378
+ it "Convert url to " + ext do
1958
379
 
1959
- #Download converted file from storage
1960
- res = download_file_helper(result_name)
1961
- expect(res).to be_an_instance_of File
1962
-
1963
- #Move to test folder
1964
- save_to_test_dir(res, result_name)
1965
- end
1966
- end
1967
-
1968
- # unit tests for get_convert_document_to_mhtml_by_url
1969
- #
1970
- # Converts the HTML page from Web by its URL to MHTML returns resulting file in response content.
1971
- # @param source_url Source page URL.
1972
- # @param [Hash] opts the optional parameters
1973
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
1974
- describe 'get_convert_document_to_mhtml_by_url test' do
1975
- it "Convert url to mhtml" do
1976
- source_url = "https://www.yahoo.com"
1977
- opts = {}
1978
-
1979
- answer = @instance.get_convert_document_to_mhtml_by_url(source_url, opts)
1980
-
1981
- expect(answer).to be_an_instance_of Hash
1982
- expect(answer[:file]).to be_an_instance_of File
1983
- expect(answer[:status]).to eql(200)
1984
-
1985
- # Save to test dir
1986
- save_to_test_dir(answer[:file], "Convert_url.mht")
1987
- end
1988
- end
380
+ dst = dst_dir + '/urlStorImg.' + ext
381
+ answer = @html_api.convert_url_to_storage(src, dst, nil)
1989
382
 
1990
- # unit tests for get_convert_document_to_markdown
1991
- # Converts the HTML document (located on storage) to Markdown and returns resulting file in response content.
1992
- # @param name Document name.
1993
- # @param [Hash] opts the optional parameters
1994
- # @option opts [String] :use_git Use Git Markdown flavor to save ("true" or "false"). (default to "false")
1995
- # @option opts [String] :folder Source document folder.
1996
- # @option opts [String] :storage Source document storage.
1997
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
1998
- describe 'get_convert_document_to_markdown test' do
1999
- it "Convert html to markdown" do
2000
- name = "test_md.html"
2001
- opts = {
2002
- use_git: "true",
2003
- folder: "HtmlTestDoc",
2004
- storage: nil
383
+ expect(answer.code).to eql(200)
384
+ expect(answer.status).to eql('completed')
385
+ expect(@storage_api.object_exists(answer.file)).to be_truthy
386
+ end
2005
387
  }
2006
-
2007
- # Upload file to server
2008
- res = upload_file_helper(name)
2009
- expect(res.uploaded.length).to eql(1)
2010
- expect(res.errors.length).to eql(0)
2011
-
2012
- answer = @instance.get_convert_document_to_markdown(name, opts)
2013
-
2014
- expect(answer).to be_an_instance_of Hash
2015
- expect(answer[:file]).to be_an_instance_of File
2016
- expect(answer[:status]).to eql(200)
2017
-
2018
- # Save to test dir
2019
- save_to_test_dir(answer[:file], "get_convert_markdown.md")
2020
388
  end
2021
- end
2022
389
 
2023
- # unit tests for post_convert_document_in_request_to_markdown
2024
- # Converts the HTML document (in request content) to Markdown and uploads resulting file to storage by specified path.
2025
- # @param out_path Full resulting file path in the storage (ex. /folder1/folder2/result.md)
2026
- # @param file A file to be converted.
2027
- # @param [Hash] opts the optional parameters
2028
- # @option opts [String] :use_git Use Git Markdown flavor to save ("true" or "false"). (default to "false")
2029
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
2030
- describe 'post_convert_document_in_request_to_markdown test' do
2031
- it "Upload and convert html to markdown" do
2032
- name = "postConvertInReqRuby.md"
2033
- out_path = "HtmlTestDoc/" + name
2034
- file = File.realpath(__dir__ + '/../../testdata/test_md.html')
2035
- opts = { use_git: "false" }
2036
-
2037
- answer = @instance.post_convert_document_in_request_to_markdown(out_path, file, opts)
2038
-
2039
- expect(answer[:status]).to eql(200)
2040
-
2041
- #Download converted file from storage
2042
- res = download_file_helper(name)
2043
- expect(res).to be_an_instance_of File
2044
-
2045
- #Move to test folder
2046
- save_to_test_dir(res, name)
2047
- end
2048
- end
390
+ describe 'convert url to storage image with options' do
2049
391
 
2050
- # unit tests for put_convert_document_to_markdown
2051
- # Converts the HTML document (located on storage) to Markdown and uploads resulting file to storage by specified path.
2052
- # @param name Document name.
2053
- # @param out_path Full resulting file path in the storage (ex. /folder1/folder2/result.md)
2054
- # @param [Hash] opts the optional parameters
2055
- # @option opts [String] :use_git Use Git Markdown flavor to save ("true" or "false"). (default to "false")
2056
- # @option opts [String] :folder The source document folder.
2057
- # @option opts [String] :storage The source and resulting document storage.
2058
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
2059
- describe 'put_convert_document_to_markdown test' do
2060
- it "Convert html to markdown and save result in the storage" do
2061
-
2062
- # Already in the storage
2063
- name = "test_md.html"
2064
- result_name = "putConvertRuby.md"
2065
- out_path = "HtmlTestDoc/" + result_name
2066
392
  opts = {
2067
- use_git: "true",
2068
- folder: "HtmlTestDoc",
2069
- storage: nil
2070
- }
2071
-
2072
- answer = @instance.put_convert_document_to_markdown(name, out_path, opts)
2073
-
2074
- expect(answer[:status]).to eql(200)
2075
-
2076
- #Download converted file from storage
2077
- res = download_file_helper(result_name)
2078
- expect(res).to be_an_instance_of File
2079
-
2080
- #Move to test folder
2081
- save_to_test_dir(res, result_name)
2082
- end
2083
- end
2084
-
2085
- #################################################
2086
- # Import API
2087
- #################################################
2088
-
2089
- # unit tests for get_convert_markdown_to_html
2090
- # Converts the Markdown document (located on storage) to HTML and returns resulting file in response content.
2091
- # @param name Document name.
2092
- # @param [Hash] opts the optional parameters
2093
- # @option opts [String] :folder Source document folder.
2094
- # @option opts [String] :storage Source document storage.
2095
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
2096
- describe 'get_convert_markdown_to_html test' do
2097
- it "Convert markdown to html" do
2098
- name = "testpage1.md"
2099
- opts = {
2100
- folder: "HtmlTestDoc",
2101
- storage: nil
393
+ width: 800,
394
+ height: 1000,
395
+ left_margin: 30,
396
+ right_margin: 30,
397
+ top_margin: 50,
398
+ bottom_margin: 50
2102
399
  }
2103
400
 
2104
- # Upload file to server
2105
- res = upload_file_helper(name)
2106
- expect(res.uploaded.length).to eql(1)
2107
- expect(res.errors.length).to eql(0)
2108
-
2109
- answer = @instance.get_convert_markdown_to_html(name, opts)
2110
-
2111
- expect(answer).to be_an_instance_of Hash
2112
- expect(answer[:file]).to be_an_instance_of File
2113
- expect(answer[:status]).to eql(200)
2114
-
2115
- # Save to test dir
2116
- save_to_test_dir(answer[:file], "get_convert_md_html.html")
2117
- end
2118
- end
401
+ %w[jpeg jpg bmp png tiff tif gif].each { |ext|
402
+ it "Convert url to " + ext do
2119
403
 
2120
- # unit tests for post_convert_markdown_in_request_to_html
2121
- # Converts the Markdown document (in request content) to HTML and uploads resulting file to storage by specified path.
2122
- # @param out_path Full resulting file path in the storage (ex. /folder1/folder2/result.html)
2123
- # @param file A file to be converted.
2124
- # @param [Hash] opts the optional parameters
2125
- # @option opts [String] :storage Source document storage.
2126
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
2127
- describe 'post_convert_markdown_in_request_to_html test' do
2128
- it "Upload and convert markdown to html" do
2129
- name = "postMarkdownToHtmlInReqRuby.html"
2130
- out_path = "HtmlTestDoc/" + name
2131
- file = File.realpath(__dir__ + '/../../testdata/testpage1.md')
2132
- opts = { storage: nil }
2133
-
2134
- answer = @instance.post_convert_markdown_in_request_to_html(out_path, file, opts)
2135
-
2136
- expect(answer[:status]).to eql(200)
2137
-
2138
- #Download converted file from storage
2139
- res = download_file_helper(name)
2140
- expect(res).to be_an_instance_of File
2141
-
2142
- #Move to test folder
2143
- save_to_test_dir(res, name)
2144
- end
2145
- end
404
+ dst = dst_dir + '/urlStorImgOpt.' + ext
405
+ answer = @html_api.convert_url_to_storage(src, dst, nil, opts)
2146
406
 
2147
- # unit tests for put_convert_markdown_to_html
2148
- # Converts the Markdown document (located on storage) to HTML and uploads resulting file to storage by specified path.
2149
- # @param name Document name.
2150
- # @param out_path Full resulting file path in the storage (ex. /folder1/folder2/result.html)
2151
- # @param [Hash] opts the optional parameters
2152
- # @option opts [String] :folder The source document folder.
2153
- # @option opts [String] :storage The source and resulting document storage.
2154
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
2155
- describe 'put_convert_markdown_to_html test' do
2156
- it "Convert markdown to html and save result in the storage" do
2157
-
2158
- # Already in the storage
2159
- name = "testpage1.md"
2160
- result_name = "putConvertMarkdownToHtmlRuby.html"
2161
- out_path = "HtmlTestDoc/" + result_name
2162
- opts = {
2163
- folder: "HtmlTestDoc",
2164
- storage: nil
407
+ expect(answer.code).to eql(200)
408
+ expect(answer.status).to eql('completed')
409
+ expect(@storage_api.object_exists(answer.file)).to be_truthy
410
+ end
2165
411
  }
2166
-
2167
- answer = @instance.put_convert_markdown_to_html(name, out_path, opts)
2168
-
2169
- expect(answer[:status]).to eql(200)
2170
-
2171
- #Download converted file from storage
2172
- res = download_file_helper(result_name)
2173
- expect(res).to be_an_instance_of File
2174
-
2175
- #Move to test folder
2176
- save_to_test_dir(res, result_name)
2177
- end
2178
- end
2179
-
2180
- #################################################
2181
- # Document API
2182
- #################################################
2183
-
2184
- # unit tests for document_get_document_by_url
2185
- # Return all HTML page with linked resources packaged as a ZIP archive by the source page URL.
2186
- #
2187
- # @param source_url Source page URL.
2188
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
2189
- describe 'get_document_by_url test' do
2190
- it "Get document and all linked resources from url" do
2191
-
2192
- source_url = "https://lenta.ru/"
2193
- answer = @instance.get_document_by_url(source_url)
2194
-
2195
- expect(answer).to be_an_instance_of Hash
2196
- expect(answer[:file]).to be_an_instance_of File
2197
- expect(answer[:status]).to eql(200)
2198
-
2199
- # Save to test dir
2200
- save_to_test_dir(answer[:file], "Get_site_from_url.zip")
2201
- end
2202
- end
2203
-
2204
- # unit tests for get_document_fragment_by_x_path
2205
- # Return list of HTML fragments matching the specified XPath query.
2206
- #
2207
- # @param name The document name.
2208
- # @param x_path XPath query string.
2209
- # @param out_format Output format. Possible values: &#39;plain&#39; and &#39;json&#39;.
2210
- # @param [Hash] opts the optional parameters
2211
- # @option opts [String] :storage The document storage.
2212
- # @option opts [String] :folder The document folder.
2213
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
2214
- describe 'get_document_fragment_by_x_path test' do
2215
- it "Get fragment document" do
2216
- name = "test2.html.zip"
2217
- x_path = ".//p"
2218
- out_format = "plain"
2219
- opts = {folder: "HtmlTestDoc", storage: nil}
2220
-
2221
- # Upload file to server
2222
- res = upload_file_helper(name)
2223
- expect(res.uploaded.length).to eql(1)
2224
- expect(res.errors.length).to eql(0)
2225
-
2226
- answer = @instance.get_document_fragment_by_x_path(name, x_path, out_format, opts)
2227
-
2228
- expect(answer).to be_an_instance_of Hash
2229
- expect(answer[:file]).to be_an_instance_of File
2230
- expect(answer[:status]).to eql(200)
2231
-
2232
- # Save to test dir
2233
- save_to_test_dir(answer[:file], "Get_fragment_doc.html")
2234
- end
2235
- end
2236
-
2237
- # unit tests for document_get_document_fragment_by_x_path_by_url
2238
- # Return list of HTML fragments matching the specified XPath query by the source page URL.
2239
- #
2240
- # @param source_url Source page URL.
2241
- # @param x_path XPath query string.
2242
- # @param out_format Output format. Possible values: &#39;plain&#39; and &#39;json&#39;.
2243
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
2244
- describe 'get_document_fragment_by_x_path_by_url test' do
2245
- it "Get fragment document by url" do
2246
- source_url = "https://stallman.org/articles/anonymous-payments-thru-phones.html"
2247
- x_path = ".//p"
2248
- out_format = "plain"
2249
-
2250
- answer = @instance.get_document_fragment_by_x_path_by_url(source_url, x_path, out_format)
2251
-
2252
- expect(answer).to be_an_instance_of Hash
2253
- expect(answer[:file]).to be_an_instance_of File
2254
- expect(answer[:status]).to eql(200)
2255
-
2256
- # Save to test dir
2257
- save_to_test_dir(answer[:file], "Get_fragment_xpath_by_url.html")
2258
- end
2259
- end
2260
-
2261
- # Return list of HTML fragments matching the specified CSS selector.
2262
- #
2263
- # @param name The document name.
2264
- # @param selector CSS selector string.
2265
- # @param out_format Output format. Possible values: &#39;plain&#39; and &#39;json&#39;.
2266
- # @param [Hash] opts the optional parameters
2267
- # @option opts [String] :folder The document folder.
2268
- # @option opts [String] :storage The document storage.
2269
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
2270
- describe 'get_document_fragments_by_css_selector test' do
2271
- it "Get fragment document by css" do
2272
- name = "test2.html.zip"
2273
- selector = "div p"
2274
- out_format = "plain"
2275
- opts = {folder: "HtmlTestDoc", storage: nil}
2276
-
2277
- # Upload file to server
2278
- res = upload_file_helper(name)
2279
- expect(res.uploaded.length).to eql(1)
2280
- expect(res.errors.length).to eql(0)
2281
-
2282
- answer = @instance.get_document_fragments_by_css_selector(name, selector, out_format, opts)
2283
-
2284
- expect(answer).to be_an_instance_of Hash
2285
- expect(answer[:file]).to be_an_instance_of File
2286
- expect(answer[:status]).to eql(200)
2287
-
2288
- # Save to test dir
2289
- save_to_test_dir(answer[:file], "Get_fragment_doc_css.html")
2290
- end
2291
- end
2292
-
2293
- # Return list of HTML fragments matching the specified CSS selector by the source page URL.
2294
- #
2295
- # @param source_url Source page URL.
2296
- # @param selector CSS selector string.
2297
- # @param out_format Output format. Possible values: &#39;plain&#39; and &#39;json&#39;.
2298
- # @param [Hash] opts the optional parameters
2299
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
2300
- describe 'get_document_fragments_by_css_selector_by_url test' do
2301
- it "Get fragment document matching the specified CSS selector by url" do
2302
- source_url = "https://www.w3schools.com/cssref/css_selectors.asp"
2303
- selector = 'a[href$=".asp"]'
2304
- out_format = "plain"
2305
-
2306
- answer = @instance.get_document_fragments_by_css_selector_by_url(source_url, selector, out_format)
2307
-
2308
- expect(answer).to be_an_instance_of Hash
2309
- expect(answer[:file]).to be_an_instance_of File
2310
- expect(answer[:status]).to eql(200)
2311
-
2312
- # Save to test dir
2313
- save_to_test_dir(answer[:file], "Get_fragment_css_by_url.html")
2314
- end
2315
- end
2316
-
2317
- # unit tests for get_document_images
2318
- # Return all HTML document images packaged as a ZIP archive.
2319
- #
2320
- # @param name The document name.
2321
- # @param [Hash] opts the optional parameters
2322
- # @option opts [String] :folder The document folder.
2323
- # @option opts [String] :storage The document storage.
2324
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
2325
- describe 'get_document_images test' do
2326
- it "Get images from document" do
2327
- name = "test3.html.zip"
2328
- opts = {folder: "HtmlTestDoc", storage: nil}
2329
-
2330
- # Upload file to server
2331
- res = upload_file_helper(name)
2332
- expect(res.uploaded.length).to eql(1)
2333
- expect(res.errors.length).to eql(0)
2334
-
2335
- answer = @instance.get_document_images(name, opts)
2336
-
2337
- expect(answer).to be_an_instance_of Hash
2338
- expect(answer[:file]).to be_an_instance_of File
2339
- expect(answer[:status]).to eql(200)
2340
-
2341
- # Save to test dir
2342
- save_to_test_dir(answer[:file], "Get_images_doc.zip")
2343
- end
2344
- end
2345
-
2346
- # unit tests for document_get_document_images_by_url
2347
- # Return all HTML page images packaged as a ZIP archive by the source page URL.
2348
- #
2349
- # @param source_url Source page URL.
2350
- # @return [Hash] {file: data, status: _status_code, headers: _headers}
2351
- describe 'get_document_images_by_url test' do
2352
- it "Get images from url" do
2353
-
2354
- source_url = "https://www.google.com/"
2355
- answer = @instance.get_document_images_by_url(source_url)
2356
-
2357
- expect(answer).to be_an_instance_of Hash
2358
- expect(answer[:file]).to be_an_instance_of File
2359
- expect(answer[:status]).to eql(200)
2360
-
2361
- # Save to test dir
2362
- save_to_test_dir(answer[:file], "Get_images_from_url.zip")
2363
- end
2364
- end
2365
-
2366
- # unit tests for get_merge_html_template
2367
- # Populate HTML document template with data located as a file in the storage.
2368
- #
2369
- # @param template_name Template document name. Template document is HTML or zipped HTML.
2370
- # @param data_path Data source file path in the storage. Supported data format: XML
2371
- # @param [Hash] opts the optional parameters
2372
- # @option opts [String] :options Template merge options: reserved for further implementation.
2373
- # @option opts [String] :folder The template document folder.
2374
- # @option opts [String] :storage The template document and data source storage.
2375
- # @return [File]
2376
- describe 'get_merge_html_template test' do
2377
- it "Get merge template" do
2378
- template_name = "HtmlTemplate.html";
2379
- data_name = "XmlSourceData.xml";
2380
- folder = "HtmlTestDoc"
2381
- opts = {storage: nil, folder: folder}
2382
- data_path = folder + "/" + data_name
2383
- # Upload template file to server
2384
- res = upload_file_helper(template_name)
2385
- expect(res.uploaded.length).to eql(1)
2386
- expect(res.errors.length).to eql(0)
2387
-
2388
- # Upload data file to server
2389
- res = upload_file_helper(data_name)
2390
- expect(res.uploaded.length).to eql(1)
2391
- expect(res.errors.length).to eql(0)
2392
-
2393
- opts = {options:"", folder:"HtmlTestDoc", storage: nil}
2394
- answer = @instance.get_merge_html_template(template_name, data_path, opts)
2395
- save_to_test_dir(answer[:file], "GetTemplateMergeRuby.html")
2396
- end
2397
- end
2398
-
2399
- # unit tests for post_merge_html_template
2400
- # Populate HTML document template with data from the request body. Result document will be saved to storage.
2401
- #
2402
- # @param template_name Template document name. Template document is HTML or zipped HTML.
2403
- # @param out_path Result document path.
2404
- # @param file A data file to populate template.
2405
- # @param [Hash] opts the optional parameters
2406
- # @option opts [String] :options Template merge options: reserved for further implementation.
2407
- # @option opts [String] :folder The template document folder.
2408
- # @option opts [String] :storage The template document and data source storage.
2409
- # @return [File]
2410
- describe 'post_merge_html_template test' do
2411
- it "Post merge template" do
2412
- result_name = "PostTemplateMergeRuby.html"
2413
- template_name = "HtmlTemplate.html";
2414
- data_name = "XmlSourceData.xml";
2415
- folder = "HtmlTestDoc"
2416
- opts = {options:"", folder:"HtmlTestDoc", storage: nil}
2417
- out_path = folder + "/" + result_name
2418
- file = File.realpath(__dir__ + '/../../testdata/' + data_name)
2419
- answer = @instance.post_merge_html_template(template_name, out_path, file, opts)
2420
- expect(answer[:status]).to eql(200)
2421
-
2422
- #Download converted file from storage
2423
- res = download_file_helper(result_name)
2424
- expect(res).to be_an_instance_of File
2425
-
2426
- #Move to test folder
2427
- save_to_test_dir(res, result_name)
2428
412
  end
2429
413
  end
2430
414
  end