docraptor 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,10 +8,12 @@ end
8
8
 
9
9
  $docraptor = DocRaptor::DocApi.new
10
10
 
11
+ output_file = "ruby-async.pdf"
12
+
11
13
  create_response = $docraptor.create_async_doc(
12
14
  test: true,
13
15
  document_content: "<html><body>Hello from Ruby</body></html>",
14
- name: "ruby-async.pdf",
16
+ name: output_file,
15
17
  document_type: "pdf",
16
18
  )
17
19
 
@@ -22,4 +24,11 @@ status_response = nil
22
24
  sleep 1
23
25
  end
24
26
 
25
- $docraptor.get_async_doc(status_response.download_id)
27
+ output_payload = $docraptor.get_async_doc(status_response.download_id)
28
+
29
+ File.write(output_file, output_payload)
30
+ output_type = `file -b #{output_file}`
31
+ File.delete output_file
32
+
33
+ raise "Output was not a PDF" unless output_type.start_with?("PDF")
34
+
@@ -0,0 +1,50 @@
1
+ require "bundler/setup"
2
+ Bundler.require
3
+ require 'open-uri'
4
+
5
+ api_key = File.read("#{__dir__}/../.docraptor_key").strip
6
+ unless api_key
7
+ raise "Please put a valid (paid plan) api key in the .docraptor_key file when testing this feature."
8
+ end
9
+
10
+ DocRaptor.configure do |dr|
11
+ dr.username = api_key
12
+ # dr.debugging = true
13
+ end
14
+
15
+ $docraptor = DocRaptor::DocApi.new
16
+
17
+ output_file = "expire-hosted-ruby-sync.pdf"
18
+
19
+ output_payload = $docraptor.create_hosted_async_doc(
20
+ test: true,
21
+ document_content: "<html><body>Hello from Ruby</body></html>",
22
+ name: output_file,
23
+ document_type: "pdf",
24
+ hosted_expires_at: (Time.now + 86400).strftime('%FT%T%:z'), # 1 day from now
25
+ )
26
+
27
+ status_response = nil
28
+ 30.times do
29
+ status_response = $docraptor.get_async_doc_status(output_payload.status_id)
30
+ break if status_response.status == "completed"
31
+ sleep 1
32
+ end
33
+
34
+ actual_document = open status_response.download_url
35
+ IO.copy_stream(actual_document, output_file)
36
+
37
+ output_type = `file -b #{output_file}`
38
+ File.delete output_file
39
+
40
+ raise "Output was not a PDF" unless output_type.start_with?("PDF")
41
+
42
+ $docraptor.expire(status_response.download_id)
43
+
44
+ begin
45
+ actual_document = open status_response.download_url
46
+ rescue OpenURI::HTTPError => http_error
47
+ exit 0
48
+ end
49
+
50
+ exit 1
@@ -0,0 +1,34 @@
1
+ require "bundler/setup"
2
+ Bundler.require
3
+ require "open-uri"
4
+
5
+ api_key = File.read("#{__dir__}/../.docraptor_key").strip
6
+ unless api_key
7
+ raise "Please put a valid (paid plan) api key in the .docraptor_key file when testing this feature."
8
+ end
9
+
10
+ DocRaptor.configure do |dr|
11
+ dr.username = api_key
12
+ # dr.debugging = true
13
+ end
14
+
15
+ $docraptor = DocRaptor::DocApi.new
16
+
17
+ output_file = "hosted-ruby-sync.pdf"
18
+
19
+ output_payload = $docraptor.create_hosted_async_doc(
20
+ test: true,
21
+ document_content: "<html><body>Hello from Ruby</body></html>",
22
+ name: output_file,
23
+ document_type: "pdf",
24
+ hosted_expires_at: (Time.now + 86400).strftime('%FT%T%:z'), # 1 day from now
25
+ )
26
+
27
+ status_response = nil
28
+ 30.times do
29
+ status_response = $docraptor.get_async_doc_status(output_payload.status_id)
30
+ break if status_response.status == "completed"
31
+ sleep 1
32
+ end
33
+
34
+
@@ -0,0 +1,33 @@
1
+ require "bundler/setup"
2
+ Bundler.require
3
+ require "open-uri"
4
+
5
+ api_key = File.read("#{__dir__}/../.docraptor_key").strip
6
+ unless api_key
7
+ raise "Please put a valid (paid plan) api key in the .docraptor_key file when testing this feature."
8
+ end
9
+
10
+ DocRaptor.configure do |dr|
11
+ dr.username = api_key
12
+ # dr.debugging = true
13
+ end
14
+
15
+ $docraptor = DocRaptor::DocApi.new
16
+
17
+ output_file = "hosted-ruby-sync.pdf"
18
+
19
+ output_payload = $docraptor.create_hosted_doc(
20
+ test: true,
21
+ document_content: "<html><body>Hello from Ruby</body></html>",
22
+ name: output_file,
23
+ document_type: "pdf",
24
+ hosted_expires_at: (Time.now + 86400).strftime('%FT%T%:z'), # 1 day from now
25
+ )
26
+
27
+ actual_document = open output_payload.download_url
28
+ IO.copy_stream(actual_document, output_file)
29
+
30
+ output_type = `file -b #{output_file}`
31
+ File.delete output_file
32
+
33
+ raise "Output was not a PDF" unless output_type.start_with?("PDF")
@@ -8,9 +8,17 @@ end
8
8
 
9
9
  $docraptor = DocRaptor::DocApi.new
10
10
 
11
- $docraptor.create_doc(
11
+ output_file = "ruby-sync.pdf"
12
+
13
+ output_payload = $docraptor.create_doc(
12
14
  test: true,
13
15
  document_content: "<html><body>Hello from Ruby</body></html>",
14
- name: "ruby-sync.pdf",
16
+ name: output_file,
15
17
  document_type: "pdf",
16
18
  )
19
+
20
+ File.write(output_file, output_payload)
21
+ output_type = `file -b #{output_file}`
22
+ File.delete output_file
23
+
24
+ raise "Output was not a PDF" unless output_type.start_with?("PDF")
@@ -8,9 +8,17 @@ end
8
8
 
9
9
  $docraptor = DocRaptor::DocApi.new
10
10
 
11
- $docraptor.create_doc(
11
+ output_file = "ruby-xlsx.xlsx"
12
+
13
+ output_payload = $docraptor.create_doc(
12
14
  test: true,
13
15
  document_content: "<html><body><table><tr><td>Hello from Ruby</td></tr></table></body></html>",
14
- name: "ruby-xlsx.xlsx",
16
+ name: output_file,
15
17
  document_type: "xlsx",
16
18
  )
19
+
20
+ File.write(output_file, output_payload)
21
+ output_type = `file -b #{output_file}`
22
+ File.delete output_file
23
+
24
+ raise "Output was not an XLSX (zip)" unless output_type.start_with?("Zip")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docraptor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Expected Behavior
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-21 00:00:00.000000000 Z
11
+ date: 2020-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -34,42 +34,42 @@ dependencies:
34
34
  name: json
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '2.1'
40
37
  - - ">="
41
38
  - !ruby/object:Gem::Version
42
39
  version: 2.1.0
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '2.1'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: '2.1'
50
47
  - - ">="
51
48
  - !ruby/object:Gem::Version
52
49
  version: 2.1.0
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '2.1'
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: rspec
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
- - - "~>"
58
- - !ruby/object:Gem::Version
59
- version: '3.6'
60
57
  - - ">="
61
58
  - !ruby/object:Gem::Version
62
59
  version: 3.6.0
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.6'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '3.6'
70
67
  - - ">="
71
68
  - !ruby/object:Gem::Version
72
69
  version: 3.6.0
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '3.6'
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: vcr
75
75
  requirement: !ruby/object:Gem::Requirement
@@ -250,6 +250,8 @@ files:
250
250
  - docraptor.gemspec
251
251
  - docraptor.yaml
252
252
  - examples/async.rb
253
+ - examples/hosted_async.rb
254
+ - examples/hosted_sync.rb
253
255
  - examples/sync.rb
254
256
  - lib/docraptor.rb
255
257
  - lib/docraptor/api/doc_api.rb
@@ -257,8 +259,8 @@ files:
257
259
  - lib/docraptor/api_error.rb
258
260
  - lib/docraptor/configuration.rb
259
261
  - lib/docraptor/models/async_doc.rb
260
- - lib/docraptor/models/async_doc_status.rb
261
262
  - lib/docraptor/models/doc.rb
263
+ - lib/docraptor/models/doc_status.rb
262
264
  - lib/docraptor/models/prince_options.rb
263
265
  - lib/docraptor/version.rb
264
266
  - script/clean
@@ -268,16 +270,14 @@ files:
268
270
  - script/swagger
269
271
  - script/test
270
272
  - script/update_from_upstream
271
- - spec/api/doc_api_spec.rb
272
273
  - spec/api_client_spec.rb
273
274
  - spec/configuration_spec.rb
274
- - spec/models/async_doc_spec.rb
275
- - spec/models/async_doc_status_spec.rb
276
- - spec/models/doc_spec.rb
277
- - spec/models/prince_options_spec.rb
278
275
  - spec/spec_helper.rb
279
276
  - swagger-config.json
280
277
  - test/async.rb
278
+ - test/expire_hosted.rb
279
+ - test/hosted_async.rb
280
+ - test/hosted_sync.rb
281
281
  - test/invalid_async.rb
282
282
  - test/invalid_sync.rb
283
283
  - test/sync.rb
@@ -286,7 +286,7 @@ homepage: https://github.com/docraptor/docraptor-ruby
286
286
  licenses:
287
287
  - MIT
288
288
  metadata: {}
289
- post_install_message:
289
+ post_install_message:
290
290
  rdoc_options: []
291
291
  require_paths:
292
292
  - lib
@@ -301,21 +301,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
301
301
  - !ruby/object:Gem::Version
302
302
  version: '0'
303
303
  requirements: []
304
- rubyforge_project:
305
- rubygems_version: 2.5.1
306
- signing_key:
304
+ rubygems_version: 3.0.3
305
+ signing_key:
307
306
  specification_version: 4
308
307
  summary: A wrapper for the DocRaptor HTML to PDF/XLS service.
309
308
  test_files:
310
- - spec/api/doc_api_spec.rb
311
309
  - spec/api_client_spec.rb
312
310
  - spec/configuration_spec.rb
313
- - spec/models/async_doc_spec.rb
314
- - spec/models/async_doc_status_spec.rb
315
- - spec/models/doc_spec.rb
316
- - spec/models/prince_options_spec.rb
317
311
  - spec/spec_helper.rb
318
312
  - test/async.rb
313
+ - test/expire_hosted.rb
314
+ - test/hosted_async.rb
315
+ - test/hosted_sync.rb
319
316
  - test/invalid_async.rb
320
317
  - test/invalid_sync.rb
321
318
  - test/sync.rb
@@ -1,83 +0,0 @@
1
- =begin
2
- #DocRaptor v1
3
-
4
- #No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
5
-
6
- OpenAPI spec version: 1.2.0
7
-
8
- Generated by: https://github.com/swagger-api/swagger-codegen.git
9
- Swagger Codegen version: 2.2.3
10
-
11
- =end
12
-
13
- require 'spec_helper'
14
- require 'json'
15
-
16
- # Unit tests for DocRaptor::DocApi
17
- # Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
18
- # Please update as you see appropriate
19
- describe 'DocApi' do
20
- before do
21
- # run before each test
22
- @instance = DocRaptor::DocApi.new
23
- end
24
-
25
- after do
26
- # run after each test
27
- end
28
-
29
- describe 'test an instance of DocApi' do
30
- it 'should create an instance of DocApi' do
31
- expect(@instance).to be_instance_of(DocRaptor::DocApi)
32
- end
33
- end
34
-
35
- # unit tests for create_async_doc
36
- #
37
- # Creates a document asynchronously. You must use a callback url or the the returned status id and the status api to find out when it completes. Then use the download api to get the document.
38
- # @param doc The document to be created.
39
- # @param [Hash] opts the optional parameters
40
- # @return [AsyncDoc]
41
- describe 'create_async_doc test' do
42
- it "should work" do
43
- # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
44
- end
45
- end
46
-
47
- # unit tests for create_doc
48
- #
49
- # Creates a document synchronously.
50
- # @param doc The document to be created.
51
- # @param [Hash] opts the optional parameters
52
- # @return [String]
53
- describe 'create_doc test' do
54
- it "should work" do
55
- # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
56
- end
57
- end
58
-
59
- # unit tests for get_async_doc
60
- #
61
- # Downloads a document.
62
- # @param id The download_id returned from status request or a callback.
63
- # @param [Hash] opts the optional parameters
64
- # @return [String]
65
- describe 'get_async_doc test' do
66
- it "should work" do
67
- # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
68
- end
69
- end
70
-
71
- # unit tests for get_async_doc_status
72
- #
73
- # Check on the status of an asynchronously created document.
74
- # @param id The status_id returned when creating an asynchronous document.
75
- # @param [Hash] opts the optional parameters
76
- # @return [AsyncDocStatus]
77
- describe 'get_async_doc_status test' do
78
- it "should work" do
79
- # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
80
- end
81
- end
82
-
83
- end
@@ -1,42 +0,0 @@
1
- =begin
2
- #DocRaptor v1
3
-
4
- #No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
5
-
6
- OpenAPI spec version: 1.2.0
7
-
8
- Generated by: https://github.com/swagger-api/swagger-codegen.git
9
- Swagger Codegen version: 2.2.3
10
-
11
- =end
12
-
13
- require 'spec_helper'
14
- require 'json'
15
- require 'date'
16
-
17
- # Unit tests for DocRaptor::AsyncDoc
18
- # Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
19
- # Please update as you see appropriate
20
- describe 'AsyncDoc' do
21
- before do
22
- # run before each test
23
- @instance = DocRaptor::AsyncDoc.new
24
- end
25
-
26
- after do
27
- # run after each test
28
- end
29
-
30
- describe 'test an instance of AsyncDoc' do
31
- it 'should create an instance of AsyncDoc' do
32
- expect(@instance).to be_instance_of(DocRaptor::AsyncDoc)
33
- end
34
- end
35
- describe 'test attribute "status_id"' do
36
- it 'should work' do
37
- # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
38
- end
39
- end
40
-
41
- end
42
-