docraptor 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +5 -1
- data/.swagger-codegen/VERSION +1 -1
- data/.swagger-revision +1 -1
- data/.travis.yml +9 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +1 -1
- data/README.md +6 -13
- data/docraptor.gemspec +8 -7
- data/docraptor.yaml +124 -19
- data/examples/hosted_async.rb +75 -0
- data/examples/hosted_sync.rb +62 -0
- data/lib/docraptor/api/doc_api.rb +173 -36
- data/lib/docraptor/api_client.rb +17 -15
- data/lib/docraptor/api_error.rb +3 -3
- data/lib/docraptor/configuration.rb +6 -6
- data/lib/docraptor/models/async_doc.rb +11 -15
- data/lib/docraptor/models/doc.rb +63 -36
- data/lib/docraptor/models/{async_doc_status.rb → doc_status.rb} +12 -16
- data/lib/docraptor/models/prince_options.rb +29 -22
- data/lib/docraptor/version.rb +4 -4
- data/lib/docraptor.rb +4 -4
- data/script/fix_gemspec.rb +14 -5
- data/script/setup +25 -0
- data/script/swagger +6 -1
- data/script/test +38 -7
- data/spec/api_client_spec.rb +55 -38
- data/spec/configuration_spec.rb +12 -12
- data/spec/spec_helper.rb +4 -4
- data/swagger-config.json +1 -1
- data/test/async.rb +11 -2
- data/test/expire_hosted.rb +45 -0
- data/test/hosted_async.rb +29 -0
- data/test/hosted_sync.rb +28 -0
- data/test/sync.rb +10 -2
- data/test/xlsx.rb +10 -2
- metadata +38 -19
- data/spec/api/doc_api_spec.rb +0 -83
- data/spec/models/async_doc_spec.rb +0 -42
- data/spec/models/async_doc_status_spec.rb +0 -72
- data/spec/models/doc_spec.rb +0 -128
- data/spec/models/prince_options_spec.rb +0 -214
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: bfd3d5b8d3364bd02c04b712136686d4a714f6cd3ab3fced0c7efae7e9709ee0
|
|
4
|
+
data.tar.gz: 89d4fb74883b56c49a71eef45487534474a8f9fa0ae8fc065a592e6a1ae7340c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 964a77fd28bb343dd5410b01e5b6981f631fd5c0ed047225b2dc048b8070249d9d704bb7a4bd289d154b406e8b794a2ac71e7d031af047bb8c47a0500c86b29d
|
|
7
|
+
data.tar.gz: 90787b9656e2455038833d260caf62b7aa48ce833d3de5e1483c1a9893feed6e0deb5d4cb995ee565510c0c3bfabe7e851decdf5cae00fd0389dc07d8319ff90
|
data/.gitignore
CHANGED
|
@@ -29,6 +29,7 @@ Gemfile.lock
|
|
|
29
29
|
.ruby-version
|
|
30
30
|
.ruby-gemset
|
|
31
31
|
.rvmrc
|
|
32
|
+
.rubocop.yml
|
|
32
33
|
|
|
33
34
|
## Ignore dumb OSX files
|
|
34
35
|
.DS_Store
|
|
@@ -38,4 +39,7 @@ Thumbs.db
|
|
|
38
39
|
swagger-codegen
|
|
39
40
|
|
|
40
41
|
## Ignore dumb emacs files
|
|
41
|
-
*~
|
|
42
|
+
*~
|
|
43
|
+
|
|
44
|
+
## Ignore files that contain special keys
|
|
45
|
+
.docraptor_key
|
data/.swagger-codegen/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.
|
|
1
|
+
2.4.19
|
data/.swagger-revision
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
v2.
|
|
1
|
+
v2.4.19
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
### 2.0.0 [June 1, 2021]
|
|
2
|
+
* Add support for ruby 3.x (remove `URI.encode`)
|
|
3
|
+
* Remove support for rubies <2.3
|
|
4
|
+
|
|
5
|
+
### 1.4.0 [July 31, 2020]
|
|
6
|
+
* add support for hosted documents
|
|
7
|
+
* upgrade to latest swagger 2.4.14
|
|
8
|
+
|
|
9
|
+
### 1.3.0 [November 21, 2017]
|
|
10
|
+
* Added support for `prince_options[pdf_title]` and `ignore_console_messages` options
|
|
11
|
+
|
|
1
12
|
### 1.2.0 [August 22, 2017]
|
|
2
13
|
* No changes from beta1
|
|
3
14
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -18,9 +18,7 @@ bundle install
|
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
## Usage
|
|
22
|
-
|
|
23
|
-
See [examples](examples/) for runnable examples with file output, error handling, etc.
|
|
21
|
+
## Basic Usage
|
|
24
22
|
|
|
25
23
|
```ruby
|
|
26
24
|
DocRaptor.configure do |config|
|
|
@@ -44,20 +42,15 @@ response = $docraptor.create_doc(
|
|
|
44
42
|
)
|
|
45
43
|
```
|
|
46
44
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
We have guides for doing some of the common things:
|
|
50
|
-
|
|
51
|
-
* [Headers and Footers](https://docraptor.com/documentation/style#pdf-headers-footers) including page skipping
|
|
52
|
-
* [CSS Media Selector](https://docraptor.com/documentation/api#api_basic_pdf) to make the page look exactly as it does in your browser
|
|
53
|
-
* Protect content with [HTTP authentication](https://docraptor.com/documentation/api#api_http_user) or [proxies](https://docraptor.com/documentation/api#api_http_proxy) so only DocRaptor can access them
|
|
45
|
+
## Next Steps
|
|
54
46
|
|
|
47
|
+
- Optionally store and get a URL for your converted document with [document hosting](https://docraptor.com/document-hosting)
|
|
48
|
+
- View more [code examples](examples) with error handling, asynchronous creation, file saving, and document hosting.
|
|
49
|
+
- Perfect your document styling with our [style and formatting reference](https://docraptor.com/documentation/style), and [API reference](https://docraptor.com/documentation/api). Easily add headers and footers, page breaks, page numbers, table of contents, and much more!
|
|
55
50
|
|
|
56
51
|
## More Help
|
|
57
52
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
Stuck? We're experts at using DocRaptor so please [email us](mailto:support@docraptor.com) if you run into trouble.
|
|
53
|
+
Stuck? We're experts at turning HTML into PDFs so please [email us](mailto:support@docraptor.com) if you run into trouble.
|
|
61
54
|
|
|
62
55
|
|
|
63
56
|
## Development
|
data/docraptor.gemspec
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
=begin
|
|
4
|
-
#DocRaptor
|
|
4
|
+
#DocRaptor
|
|
5
5
|
|
|
6
6
|
#A native client library for the DocRaptor HTML to PDF/XLS service.
|
|
7
7
|
|
|
8
|
-
OpenAPI spec version: 1.
|
|
8
|
+
OpenAPI spec version: 1.4.0
|
|
9
9
|
|
|
10
10
|
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
|
11
|
-
Swagger Codegen version: 2.
|
|
11
|
+
Swagger Codegen version: 2.4.19
|
|
12
12
|
|
|
13
13
|
=end
|
|
14
14
|
|
|
@@ -24,11 +24,12 @@ Gem::Specification.new do |s|
|
|
|
24
24
|
s.homepage = "https://github.com/docraptor/docraptor-ruby"
|
|
25
25
|
s.summary = "A wrapper for the DocRaptor HTML to PDF/XLS service."
|
|
26
26
|
s.description = "A native client library for the DocRaptor HTML to PDF/XLS service."
|
|
27
|
-
s.license =
|
|
28
|
-
s.required_ruby_version = ">=
|
|
27
|
+
s.license = 'MIT'
|
|
28
|
+
s.required_ruby_version = ">= 2.3"
|
|
29
29
|
|
|
30
30
|
s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1'
|
|
31
31
|
s.add_runtime_dependency 'json', '~> 2.1', '>= 2.1.0'
|
|
32
|
+
s.add_runtime_dependency 'addressable', '~> 2.3', '>= 2.3.0'
|
|
32
33
|
|
|
33
34
|
s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0'
|
|
34
35
|
s.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.1'
|
|
@@ -44,7 +45,7 @@ Gem::Specification.new do |s|
|
|
|
44
45
|
# </added> : if the above lines are missing in the gemspec, then
|
|
45
46
|
# the matcher for autotest is probably broken
|
|
46
47
|
|
|
47
|
-
s.files = `git ls-files`.split("\n").uniq.sort.select{|f| !f.empty? }
|
|
48
|
+
s.files = `git ls-files`.split("\n").uniq.sort.select { |f| !f.empty? }
|
|
48
49
|
s.test_files = `git ls-files spec test`.split("\n")
|
|
49
50
|
s.executables = []
|
|
50
51
|
s.require_paths = ["lib"]
|
data/docraptor.yaml
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
swagger: '2.0'
|
|
2
2
|
|
|
3
|
-
info:
|
|
4
|
-
|
|
3
|
+
info: # https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#info-object
|
|
4
|
+
version: "1.4.0"
|
|
5
|
+
title: DocRaptor
|
|
5
6
|
description: "A native client library for the DocRaptor HTML to PDF/XLS service."
|
|
6
7
|
termsOfService: "https://docraptor.com/tos"
|
|
7
8
|
license:
|
|
@@ -54,14 +55,79 @@ paths:
|
|
|
54
55
|
description: Unprocessable Entity
|
|
55
56
|
500:
|
|
56
57
|
description: Server Error
|
|
58
|
+
|
|
59
|
+
/hosted_docs:
|
|
60
|
+
post:
|
|
61
|
+
operationId: createHostedDoc
|
|
62
|
+
tags: [Doc]
|
|
63
|
+
description: >
|
|
64
|
+
Creates a hosted document synchronously.
|
|
65
|
+
security:
|
|
66
|
+
- basicAuth: []
|
|
67
|
+
parameters:
|
|
68
|
+
- name: doc
|
|
69
|
+
in: body
|
|
70
|
+
description: The document to be created.
|
|
71
|
+
required: true
|
|
72
|
+
schema:
|
|
73
|
+
$ref: '#/definitions/Doc'
|
|
74
|
+
responses:
|
|
75
|
+
200:
|
|
76
|
+
description: Successful response
|
|
77
|
+
schema:
|
|
78
|
+
$ref: '#/definitions/DocStatus'
|
|
79
|
+
400:
|
|
80
|
+
description: Bad Request
|
|
81
|
+
401:
|
|
82
|
+
description: Unauthorized
|
|
83
|
+
403:
|
|
84
|
+
description: Forbidden
|
|
85
|
+
422:
|
|
86
|
+
description: Unprocessable Entity
|
|
87
|
+
500:
|
|
88
|
+
description: Server Error
|
|
89
|
+
|
|
57
90
|
/async_docs:
|
|
58
91
|
post:
|
|
59
92
|
operationId: createAsyncDoc
|
|
60
93
|
tags: [Doc]
|
|
61
94
|
description: >
|
|
62
95
|
Creates a document asynchronously.
|
|
63
|
-
You must use a callback url or the
|
|
64
|
-
Then use the download
|
|
96
|
+
You must use a callback url or the returned status id and the status API to find out when it completes.
|
|
97
|
+
Then use the download API to get the document.
|
|
98
|
+
security:
|
|
99
|
+
- basicAuth: []
|
|
100
|
+
parameters:
|
|
101
|
+
- name: doc
|
|
102
|
+
in: body
|
|
103
|
+
description: The document to be created.
|
|
104
|
+
required: true
|
|
105
|
+
schema:
|
|
106
|
+
$ref: '#/definitions/Doc'
|
|
107
|
+
responses:
|
|
108
|
+
200:
|
|
109
|
+
description: Successful response
|
|
110
|
+
schema:
|
|
111
|
+
$ref: '#/definitions/AsyncDoc'
|
|
112
|
+
400:
|
|
113
|
+
description: Bad Request
|
|
114
|
+
401:
|
|
115
|
+
description: Unauthorized
|
|
116
|
+
403:
|
|
117
|
+
description: Forbidden
|
|
118
|
+
422:
|
|
119
|
+
description: Unprocessable Entity
|
|
120
|
+
500:
|
|
121
|
+
description: Server Error
|
|
122
|
+
|
|
123
|
+
/hosted_async_docs:
|
|
124
|
+
post:
|
|
125
|
+
operationId: createHostedAsyncDoc
|
|
126
|
+
tags: [Doc]
|
|
127
|
+
description: >
|
|
128
|
+
Creates a hosted document asynchronously.
|
|
129
|
+
You must use a callback url or the returned status id and the status API to find out when it completes.
|
|
130
|
+
Then use the download API to get the document.
|
|
65
131
|
security:
|
|
66
132
|
- basicAuth: []
|
|
67
133
|
parameters:
|
|
@@ -100,13 +166,12 @@ paths:
|
|
|
100
166
|
in: path
|
|
101
167
|
description: The status_id returned when creating an asynchronous document.
|
|
102
168
|
required: true
|
|
103
|
-
|
|
104
|
-
$ref: '#/definitions/AsyncDocStatus'
|
|
169
|
+
type: string
|
|
105
170
|
responses:
|
|
106
171
|
200:
|
|
107
172
|
description: Successful response
|
|
108
173
|
schema:
|
|
109
|
-
$ref: '#/definitions/
|
|
174
|
+
$ref: '#/definitions/DocStatus'
|
|
110
175
|
401:
|
|
111
176
|
description: Unauthorized
|
|
112
177
|
403:
|
|
@@ -119,14 +184,15 @@ paths:
|
|
|
119
184
|
operationId: getAsyncDoc
|
|
120
185
|
tags: [Doc]
|
|
121
186
|
description: >
|
|
122
|
-
Downloads a document.
|
|
187
|
+
Downloads a finished document.
|
|
123
188
|
security:
|
|
124
189
|
- basicAuth: []
|
|
125
190
|
parameters:
|
|
126
191
|
- name: id
|
|
127
192
|
in: path
|
|
128
|
-
description: The download_id returned from status request or
|
|
193
|
+
description: The download_id returned from an async status request or callback.
|
|
129
194
|
required: true
|
|
195
|
+
type: string
|
|
130
196
|
responses:
|
|
131
197
|
200:
|
|
132
198
|
description: Successful response
|
|
@@ -140,6 +206,30 @@ paths:
|
|
|
140
206
|
500:
|
|
141
207
|
description: Server Error
|
|
142
208
|
|
|
209
|
+
/expire/{id}:
|
|
210
|
+
patch:
|
|
211
|
+
operationId: expire
|
|
212
|
+
tags: [Doc]
|
|
213
|
+
description: >
|
|
214
|
+
Expires a previously created hosted doc.
|
|
215
|
+
security:
|
|
216
|
+
- basicAuth: []
|
|
217
|
+
parameters:
|
|
218
|
+
- name: id
|
|
219
|
+
in: path
|
|
220
|
+
description: The download_id returned from status request or hosted document response.
|
|
221
|
+
required: true
|
|
222
|
+
type: string
|
|
223
|
+
responses:
|
|
224
|
+
200:
|
|
225
|
+
description: Successful response
|
|
226
|
+
401:
|
|
227
|
+
description: Unauthorized
|
|
228
|
+
403:
|
|
229
|
+
description: Forbidden
|
|
230
|
+
500:
|
|
231
|
+
description: Server Error
|
|
232
|
+
|
|
143
233
|
definitions:
|
|
144
234
|
Doc:
|
|
145
235
|
type: object
|
|
@@ -148,9 +238,6 @@ definitions:
|
|
|
148
238
|
- document_type
|
|
149
239
|
- document_content
|
|
150
240
|
properties:
|
|
151
|
-
pipeline:
|
|
152
|
-
type: string
|
|
153
|
-
description: Specify a specific verison of the DocRaptor Pipeline to use.
|
|
154
241
|
name:
|
|
155
242
|
type: string
|
|
156
243
|
description: A name for identifying your document.
|
|
@@ -175,17 +262,23 @@ definitions:
|
|
|
175
262
|
type: boolean
|
|
176
263
|
description: Enable test mode for this document. Test documents are not charged for but include a watermark.
|
|
177
264
|
default: true
|
|
265
|
+
pipeline:
|
|
266
|
+
type: string
|
|
267
|
+
description: Specify a specific verison of the DocRaptor Pipeline to use.
|
|
178
268
|
strict:
|
|
179
269
|
type: string
|
|
180
270
|
description: Force strict HTML validation.
|
|
181
|
-
default: none
|
|
182
271
|
enum:
|
|
183
272
|
- none
|
|
184
|
-
-
|
|
273
|
+
- html
|
|
185
274
|
ignore_resource_errors:
|
|
186
275
|
type: boolean
|
|
187
276
|
description: Failed loading of images/javascripts/stylesheets/etc. will not cause the rendering to stop.
|
|
188
277
|
default: true
|
|
278
|
+
ignore_console_messages:
|
|
279
|
+
type: boolean
|
|
280
|
+
description: Prevent console.log from stopping document rendering during JavaScript execution.
|
|
281
|
+
default: false
|
|
189
282
|
tag:
|
|
190
283
|
type: string
|
|
191
284
|
description: A field for storing a small amount of metadata with this document.
|
|
@@ -204,8 +297,14 @@ definitions:
|
|
|
204
297
|
type: string
|
|
205
298
|
description: >
|
|
206
299
|
A URL that will receive a POST request after successfully completing an asynchronous document.
|
|
207
|
-
The POST data will include download_url and download_id similar to status
|
|
300
|
+
The POST data will include download_url and download_id similar to status API responses.
|
|
208
301
|
WARNING: this only works on asynchronous documents.
|
|
302
|
+
hosted_download_limit:
|
|
303
|
+
type: integer
|
|
304
|
+
description: The number of times a hosted document can be downloaded. If no limit is specified, the document will be available for an unlimited number of downloads.
|
|
305
|
+
hosted_expires_at:
|
|
306
|
+
type: string
|
|
307
|
+
description: The date and time at which a hosted document will be removed and no longer available. Must be a properly formatted ISO 8601 datetime, like 1981-01-23T08:02:30-05:00.
|
|
209
308
|
prince_options:
|
|
210
309
|
$ref: '#/definitions/PrinceOptions'
|
|
211
310
|
|
|
@@ -300,7 +399,8 @@ definitions:
|
|
|
300
399
|
- auto
|
|
301
400
|
version:
|
|
302
401
|
type: string
|
|
303
|
-
|
|
402
|
+
deprecated: true
|
|
403
|
+
description: Deprecated, use the appropriate `pipeline` version. Specify a specific verison of PrinceXML to use.
|
|
304
404
|
# default: 10
|
|
305
405
|
# disabled because Java will try to make an enum as 7_1 which fails
|
|
306
406
|
# enum:
|
|
@@ -321,17 +421,22 @@ definitions:
|
|
|
321
421
|
# disabled because Java will try to make an enum with PDF/A-1b which fails
|
|
322
422
|
# enum:
|
|
323
423
|
# - PDF/A-1b
|
|
424
|
+
# - PDF/A-3b # (Pipeline 6+)
|
|
425
|
+
# - PDF/X-1a # (Pipeline 6+)
|
|
324
426
|
# - PDF/X-3:2003
|
|
325
427
|
# - PDF/X-4
|
|
428
|
+
pdf_title:
|
|
429
|
+
type: string
|
|
430
|
+
description: Specify the PDF title, part of the document's metadata.
|
|
326
431
|
|
|
327
432
|
AsyncDoc:
|
|
328
433
|
type: object
|
|
329
434
|
properties:
|
|
330
435
|
status_id:
|
|
331
436
|
type: string
|
|
332
|
-
description: The identifier used to get the status of the document using the status
|
|
437
|
+
description: The identifier used to get the status of the document using the status API.
|
|
333
438
|
|
|
334
|
-
|
|
439
|
+
DocStatus:
|
|
335
440
|
type: object
|
|
336
441
|
properties:
|
|
337
442
|
status:
|
|
@@ -342,7 +447,7 @@ definitions:
|
|
|
342
447
|
description: The URL where the document can be retrieved. This URL may only be used a few times.
|
|
343
448
|
download_id:
|
|
344
449
|
type: string
|
|
345
|
-
description: The identifier for downloading the document with the download
|
|
450
|
+
description: The identifier for downloading the document with the download API.
|
|
346
451
|
message:
|
|
347
452
|
type: string
|
|
348
453
|
description: Additional information.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# As a paid add-on, DocRaptor can provide long-term, publicly-accessible hosting for your documents.
|
|
2
|
+
# This allows you to provide a URL to your end users, third party tools like Zapier and Salesforce,
|
|
3
|
+
# or anyone else. We'll host the document on your behalf at a completely unbranded URL for as long
|
|
4
|
+
# as you want, or within the limits you specify.
|
|
5
|
+
#
|
|
6
|
+
# This example demonstrates creating a PDF using common options that DocRaptor will host for you.
|
|
7
|
+
# By default, hosted documents do not have limits on downloads or hosting time, though you may
|
|
8
|
+
# pass additional parameters to the document generation call to set your own limits. Learn more
|
|
9
|
+
# about the specific options in the hosted API documentation.
|
|
10
|
+
# https://docraptor.com/documentation/api#api_hosted
|
|
11
|
+
#
|
|
12
|
+
# The document is created asynchronously, which means DocRaptor will allow it to generate for up to
|
|
13
|
+
# 10 minutes. This is useful when creating many documents in parallel, or very large documents with
|
|
14
|
+
# lots of assets.
|
|
15
|
+
#
|
|
16
|
+
# DocRaptor supports many options for output customization, the full list is
|
|
17
|
+
# https://docraptor.com/documentation/api#api_general
|
|
18
|
+
#
|
|
19
|
+
# You can run this example with: ruby hosted_async.rb
|
|
20
|
+
|
|
21
|
+
require "bundler/setup"
|
|
22
|
+
Bundler.require
|
|
23
|
+
require "open-uri"
|
|
24
|
+
|
|
25
|
+
DocRaptor.configure do |dr|
|
|
26
|
+
dr.username = "YOUR_API_KEY_HERE"
|
|
27
|
+
# dr.debugging = true
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
$docraptor = DocRaptor::DocApi.new
|
|
31
|
+
|
|
32
|
+
begin
|
|
33
|
+
|
|
34
|
+
# https://docraptor.com/documentation/api#api_general
|
|
35
|
+
create_response = $docraptor.create_hosted_async_doc(
|
|
36
|
+
test: true, # test documents are free but watermarked
|
|
37
|
+
document_content: "<html><body>Hello World</body></html>", # supply content directly
|
|
38
|
+
# document_url: "http://docraptor.com/examples/invoice.html", # or use a url
|
|
39
|
+
name: "hosted-ruby-async.pdf", # helps you find a document later
|
|
40
|
+
document_type: "pdf", # pdf or xls or xlsx
|
|
41
|
+
# javascript: true, # enable JavaScript processing
|
|
42
|
+
# prince_options: {
|
|
43
|
+
# media: "screen", # use screen styles instead of print styles
|
|
44
|
+
# baseurl: "http://hello.com", # pretend URL when using document_content
|
|
45
|
+
# },
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
loop do
|
|
49
|
+
status_response = $docraptor.get_async_doc_status(create_response.status_id)
|
|
50
|
+
puts "doc status: #{status_response.status}"
|
|
51
|
+
case status_response.status
|
|
52
|
+
when "completed"
|
|
53
|
+
puts "The hosted PDF is now available for public download at #{status_response.download_url}"
|
|
54
|
+
File.open("/tmp/docraptor-ruby.pdf", "wb") do |file|
|
|
55
|
+
open(status_response.download_url) do |uri|
|
|
56
|
+
file.write(uri.read)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
puts "Wrote PDF to /tmp/docraptor-ruby.pdf"
|
|
60
|
+
break
|
|
61
|
+
when "failed"
|
|
62
|
+
puts "FAILED"
|
|
63
|
+
puts status_response
|
|
64
|
+
break
|
|
65
|
+
else
|
|
66
|
+
sleep 1
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
rescue DocRaptor::ApiError => error
|
|
71
|
+
puts "#{error.class}: #{error.message}"
|
|
72
|
+
puts error.code # HTTP response code
|
|
73
|
+
puts error.response_body # HTTP response body
|
|
74
|
+
puts error.backtrace[0..3].join("\n")
|
|
75
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# As a paid add-on, DocRaptor can provide long-term, publicly-accessible hosting for your documents.
|
|
2
|
+
# This allows you to provide a URL to your end users, third party tools like Zapier and Salesforce,
|
|
3
|
+
# or anyone else. We'll host the document on your behalf at a completely unbranded URL for as long
|
|
4
|
+
# as you want, or within the limits you specify.
|
|
5
|
+
#
|
|
6
|
+
# This example demonstrates creating a PDF that DocRaptor will host for you using common options.
|
|
7
|
+
# By default, hosted documents do not have limits on downloads or hosting time, though you may
|
|
8
|
+
# pass additional parameters to the document generation call to set your own limits. Learn more
|
|
9
|
+
# about the specific options in the hosted API documentation.
|
|
10
|
+
# https://docraptor.com/documentation/api#api_hosted
|
|
11
|
+
#
|
|
12
|
+
# It is created synchronously, which means DocRaptor will allow it to generate for up to 60 seconds.
|
|
13
|
+
# Since this document will be hosted by DocRaptor the response from this request will return a JSON
|
|
14
|
+
# formatted object containing public URL where the document can be downloaded from.
|
|
15
|
+
#
|
|
16
|
+
# DocRaptor supports many options for output customization, the full list is
|
|
17
|
+
# https://docraptor.com/documentation/api#api_general
|
|
18
|
+
#
|
|
19
|
+
# You can run this example with: ruby hosted_sync.rb
|
|
20
|
+
|
|
21
|
+
require "bundler/setup"
|
|
22
|
+
Bundler.require
|
|
23
|
+
require "open-uri"
|
|
24
|
+
|
|
25
|
+
DocRaptor.configure do |dr|
|
|
26
|
+
dr.username = "YOUR_API_KEY_HERE"
|
|
27
|
+
# dr.debugging = true
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
$docraptor = DocRaptor::DocApi.new
|
|
31
|
+
|
|
32
|
+
begin
|
|
33
|
+
|
|
34
|
+
# https://docraptor.com/documentation/api#api_general
|
|
35
|
+
create_response = $docraptor.create_hosted_doc(
|
|
36
|
+
test: true, # test documents are free but watermarked
|
|
37
|
+
document_content: "<html><body>Hello World</body></html>", # supply content directly
|
|
38
|
+
# document_url: "http://docraptor.com/examples/invoice.html", # or use a url
|
|
39
|
+
name: "docraptor-ruby.pdf", # help you find a document later
|
|
40
|
+
document_type: "pdf", # pdf or xls or xlsx
|
|
41
|
+
# javascript: true, # enable JavaScript processing
|
|
42
|
+
# prince_options: {
|
|
43
|
+
# media: "screen", # use screen styles instead of print styles
|
|
44
|
+
# baseurl: "http://hello.com", # pretend URL when using document_content
|
|
45
|
+
# },
|
|
46
|
+
)
|
|
47
|
+
puts "The hosted PDF is now available for public download at #{create_response.download_url}"
|
|
48
|
+
|
|
49
|
+
File.open("/tmp/docraptor-ruby.pdf", "wb") do |file|
|
|
50
|
+
open(create_response.download_url) do |uri|
|
|
51
|
+
file.write(uri.read)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
puts "Wrote PDF to /tmp/docraptor-ruby.pdf"
|
|
56
|
+
|
|
57
|
+
rescue DocRaptor::ApiError => error
|
|
58
|
+
puts "#{error.class}: #{error.message}"
|
|
59
|
+
puts error.code # HTTP response code
|
|
60
|
+
puts error.response_body # HTTP response body
|
|
61
|
+
puts error.backtrace[0..3].join("\n")
|
|
62
|
+
end
|