docraptor 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f5a1c61577a464a76a8c99838bf03671dacf4868
4
- data.tar.gz: fd38c94ea003066f08f23bbecda331d12f3d942e
3
+ metadata.gz: 849a038e2617f4e9c537a2e8203ed6325d8fe997
4
+ data.tar.gz: 2f4d476200f471d163df0842b7e03ed808c2ad5c
5
5
  SHA512:
6
- metadata.gz: cb72fe8bf315cde69177f0277ee357b995cb03f4b26a1e69d9b4f5149bb6a3299ec5106e54c50296cd999f9a1bb9eff8027526e6f18731269e0e623103a9ff60
7
- data.tar.gz: a9ad7e0ff6509865334d9294f560130a6011d4e6ac2dd2600f9712fcbdb35f13c5de7d91feefe30ee69c66f2b9a3312cff75c71092ae9c7e5ff8bb1266e60375
6
+ metadata.gz: b3f25bc6162a31222d20c545fe1927d45b3f0518c78ffea9673d56af26aab81102f5980906036cec905af05a5707f3430feff61103ad4cde45b692270c9677c3
7
+ data.tar.gz: 6ff94a9cdf1a915b69ff1175cf8dc391d4a359c8b29c035427235f7a289abd8acaaed16ae08d0b5758b8a6bf558abd395efbdbd5c6ff0c7fd43a5d8e5c321f36
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ### 0.0.3 [January 15, 1016]
2
+ * Use better API command names: create_doc, create_async_doc, get_async_doc_status, get_async_doc
3
+ * Fix file encoding issues when used in Rails
4
+
5
+ ### 0.0.2 [January 6, 2016]
6
+ * Regenerate using swagger-codegen v2.1.5
7
+
8
+ ### 0.0.1 [November 1, 2015]
9
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,67 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ docraptor (0.0.3)
5
+ json (~> 1.4, >= 1.4.6)
6
+ typhoeus (~> 0.2, >= 0.2.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ZenTest (4.11.0)
12
+ addressable (2.4.0)
13
+ autotest (4.4.6)
14
+ ZenTest (>= 4.4.1)
15
+ autotest-fsevent (0.2.11)
16
+ sys-uname
17
+ autotest-growl (0.2.16)
18
+ autotest-rails-pure (4.1.2)
19
+ crack (0.4.3)
20
+ safe_yaml (~> 1.0.0)
21
+ diff-lcs (1.2.5)
22
+ ethon (0.8.1)
23
+ ffi (>= 1.3.0)
24
+ ffi (1.9.10)
25
+ hashdiff (0.2.3)
26
+ json (1.8.3)
27
+ rake (10.5.0)
28
+ rspec (3.4.0)
29
+ rspec-core (~> 3.4.0)
30
+ rspec-expectations (~> 3.4.0)
31
+ rspec-mocks (~> 3.4.0)
32
+ rspec-core (3.4.1)
33
+ rspec-support (~> 3.4.0)
34
+ rspec-expectations (3.4.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.4.0)
37
+ rspec-mocks (3.4.1)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.4.0)
40
+ rspec-support (3.4.1)
41
+ safe_yaml (1.0.4)
42
+ sys-uname (1.0.2)
43
+ ffi (>= 1.0.0)
44
+ typhoeus (0.8.0)
45
+ ethon (>= 0.8.0)
46
+ vcr (2.9.3)
47
+ webmock (1.22.6)
48
+ addressable (>= 2.3.6)
49
+ crack (>= 0.3.2)
50
+ hashdiff
51
+
52
+ PLATFORMS
53
+ ruby
54
+
55
+ DEPENDENCIES
56
+ autotest (~> 4.4, >= 4.4.6)
57
+ autotest-fsevent (~> 0.2, >= 0.2.11)
58
+ autotest-growl (~> 0.2, >= 0.2.16)
59
+ autotest-rails-pure (~> 4.1, >= 4.1.2)
60
+ docraptor!
61
+ rake (~> 10.4, >= 10.4.2)
62
+ rspec (~> 3.2, >= 3.2.0)
63
+ vcr (~> 2.9, >= 2.9.3)
64
+ webmock (~> 1.6, >= 1.6.2)
65
+
66
+ BUNDLED WITH
67
+ 1.10.6
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2010- Expected Behavior, LLC (http://expectedbehavior.com)
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # DocRaptor Ruby Native Client Library
2
+
3
+ **WARNING: This code is not production ready, you should use [doc_raptor_gem](https://github.com/expectedbehavior/doc_raptor_gem).**
4
+
5
+ This is a Ruby gem for using [DocRaptor API](http://docraptor.com/documentation) to convert HTML to PDF and XLSX.
6
+
7
+ ## Installation
8
+
9
+ Add the following to your `Gemfile`.
10
+
11
+ ```ruby
12
+ gem "docraptor"
13
+ ```
14
+
15
+ Then run `bundle install`.
16
+
17
+ ## Usage
18
+
19
+ ```ruby
20
+ DocRaptor.configure do |dr|
21
+ dr.username = "YOUR_API_KEY_HERE" # this key works for test documents
22
+ # dr.debugging = true
23
+ end
24
+
25
+ $docraptor = DocRaptor::ClientApi.new
26
+
27
+ response = $docraptor.docs_post(
28
+ test: true, # test documents are free but watermarked
29
+ document_content: "<html><body>Hello World</body></html>", # supply content directly
30
+ # document_url: "http://docraptor.com/examples/invoice.html", # or use a url
31
+ name: "swagger-ruby.pdf", # help you find a document later
32
+ document_type: "pdf", # pdf or xls or xlsx
33
+ # javascript: true, # enable JavaScript processing
34
+ # prince_options: {
35
+ # media: "screen", # use screen styles instead of print styles
36
+ # baseurl: "http://hello.com", # pretend URL when using document_content
37
+ # },
38
+ )
39
+ ```
40
+
41
+ If your document will take longer than 60 seconds to render to PDF you will need to use our async api which allows up to 10 minutes, check out the [example](example/async.rb).
42
+
43
+
44
+ We have guides for doing some of the common things:
45
+ * [Headers and Footers](https://docraptor.com/documentation/style#pdf-headers-footers) including page skipping
46
+ * [CSS Media Selector](https://docraptor.com/documentation/api#api_basic_pdf) to make the page look exactly as it does in your browser
47
+ * [Protected Content](https://docraptor.com/documentation/api#api_advanced_pdf) to secure your URLs so only DocRaptor can access them
48
+
49
+ ## More Help
50
+
51
+ DocRaptor has a lot of more [styling](https://docraptor.com/documentation/style) and [implementation options](https://docraptor.com/documentation/api).
52
+
53
+ Stuck? We're experts at using DocRaptor so please [email us](mailto:support@docraptor.com) if you run into trouble.
54
+
55
+
56
+ ## Development
57
+
58
+ The majority of the code in this repo is generated using swagger-codegen on [docraptor.yaml](docraptor.yaml). You can modify this file and regenerate the client using `script/generate_language ruby`.
59
+
60
+ ## Release Process
61
+
62
+ 1. Merge code and run tests
63
+ 2. Increment version in code
64
+ 3. Update [CHANGELOG.md](CHANGELOG.md)
65
+ 4. Push to GitHub
66
+ 5. `rake release`
67
+
68
+ ## Version Policy
69
+
70
+ This library follows [Semantic Versioning 2.0.0](http://semver.org).
data/docraptor.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.homepage = "https://docraptor.com"
12
12
  s.summary = %q{A wrapper for the DocRaptor HTML to PDF/XLS service.}
13
13
  s.description = %q{A native client library for the DocRaptor HTML to PDF/XLS service.}
14
- s.license = "MIT"
14
+ s.license = "Apache-2.0"
15
15
 
16
16
  s.add_runtime_dependency 'typhoeus', '~> 0.2', '>= 0.2.1'
17
17
  s.add_runtime_dependency 'json', '~> 1.4', '>= 1.4.6'
@@ -23,10 +23,9 @@ Gem::Specification.new do |s|
23
23
  s.add_development_dependency 'autotest', '~> 4.4', '>= 4.4.6'
24
24
  s.add_development_dependency 'autotest-rails-pure', '~> 4.1', '>= 4.1.2'
25
25
  s.add_development_dependency 'autotest-growl', '~> 0.2', '>= 0.2.16'
26
- s.add_development_dependency 'autotest-fsevent', '~> 0.2', '>= 0.2.10'
26
+ s.add_development_dependency 'autotest-fsevent', '~> 0.2', '>= 0.2.11'
27
27
 
28
28
  s.files = `find *`.split("\n").uniq.sort.select{|f| !f.empty? }
29
- s.test_files = `find spec/*`.split("\n")
30
29
  s.executables = []
31
30
  s.require_paths = ["lib"]
32
31
  end
data/docraptor.yaml ADDED
@@ -0,0 +1,339 @@
1
+ swagger: '2.0'
2
+
3
+ info:
4
+ version: "0.0.1"
5
+ title: DocRaptor v1
6
+
7
+ host: docraptor.com
8
+ basePath: /
9
+ schemes: [https]
10
+ securityDefinitions:
11
+ basicAuth:
12
+ type: basic
13
+ description: HTTP Basic Authentication. Works over `HTTP` and `HTTPS`
14
+ produces:
15
+ - application/json
16
+ - application/xml
17
+ - application/pdf
18
+ - application/vnd.ms-excel
19
+ - application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
20
+
21
+ paths:
22
+ /docs:
23
+ post:
24
+ operationId: createDoc
25
+ tags: [Client]
26
+ description: |
27
+ Creates a document synchronously.
28
+ security:
29
+ - basicAuth: []
30
+ parameters:
31
+ - name: doc
32
+ in: body
33
+ description: The document to be created.
34
+ required: true
35
+ schema:
36
+ $ref: '#/definitions/Doc'
37
+ responses:
38
+ 200:
39
+ description: Successful response
40
+ schema:
41
+ type: file
42
+ 400:
43
+ description: Bad Request
44
+ 401:
45
+ description: Unauthorized
46
+ 403:
47
+ description: Forbidden
48
+ 422:
49
+ description: Unprocessable Entity
50
+ 500:
51
+ description: Server Error
52
+ /async_docs:
53
+ post:
54
+ operationId: createAsyncDoc
55
+ tags: [Client]
56
+ description: |
57
+ Creates a document asynchronously.
58
+ 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.
59
+ security:
60
+ - basicAuth: []
61
+ parameters:
62
+ - name: doc
63
+ in: body
64
+ description: The document to be created.
65
+ required: true
66
+ schema:
67
+ $ref: '#/definitions/Doc'
68
+ responses:
69
+ 200:
70
+ description: Successful response
71
+ schema:
72
+ $ref: '#/definitions/AsyncDoc'
73
+ 400:
74
+ description: Bad Request
75
+ 401:
76
+ description: Unauthorized
77
+ 403:
78
+ description: Forbidden
79
+ 422:
80
+ description: Unprocessable Entity
81
+ 500:
82
+ description: Server Error
83
+
84
+ /status/{id}:
85
+ get:
86
+ operationId: getAsyncDocStatus
87
+ tags: [Client]
88
+ description: |
89
+ Check on the status of an asynchronously created document.
90
+ security:
91
+ - basicAuth: []
92
+ parameters:
93
+ - name: id
94
+ in: path
95
+ description: The status_id returned when creating an asynchronous document.
96
+ required: true
97
+ schema:
98
+ $ref: '#/definitions/AsyncDocStatus'
99
+ responses:
100
+ 200:
101
+ description: Successful response
102
+ schema:
103
+ $ref: '#/definitions/AsyncDocStatus'
104
+ 401:
105
+ description: Unauthorized
106
+ 403:
107
+ description: Forbidden
108
+ 500:
109
+ description: Server Error
110
+
111
+
112
+ /download/{id}:
113
+ get:
114
+ operationId: getAsyncDoc
115
+ tags: [Client]
116
+ description: |
117
+ Downloads a document.
118
+ security:
119
+ - basicAuth: []
120
+ parameters:
121
+ - name: id
122
+ in: path
123
+ description: The download_id returned from status request or a callback.
124
+ required: true
125
+ responses:
126
+ 200:
127
+ description: Successful response
128
+ schema:
129
+ type: file
130
+ 400:
131
+ description: Bad Request
132
+ 403:
133
+ description: Forbidden
134
+ 500:
135
+ description: Server Error
136
+
137
+ definitions:
138
+ Doc:
139
+ type: object
140
+ required:
141
+ - name
142
+ - document_type
143
+ - document_content
144
+ properties:
145
+ name:
146
+ type: string
147
+ description: A name for identifying your document.
148
+ document_type:
149
+ type: string
150
+ description: The type of document being created.
151
+ enum:
152
+ - pdf
153
+ - xls
154
+ - xlsx
155
+ document_content:
156
+ type: string
157
+ description: |
158
+ The HTML data to be transformed into a document.
159
+ You must supply content using document_content or document_url.
160
+ document_url:
161
+ type: string
162
+ description: |
163
+ The URL to fetch the HTML data to be transformed into a document.
164
+ You must supply content using document_content or document_url.
165
+ test:
166
+ type: boolean
167
+ description: Enable test mode for this document. Test documents are not charged for but include a watermark.
168
+ default: true
169
+ strict:
170
+ type: string
171
+ description: Force strict HTML validation.
172
+ default: none
173
+ enum:
174
+ - none
175
+ - true
176
+ ignore_resource_errors:
177
+ type: boolean
178
+ description: Failed loading of images/javascripts/stylesheets/etc. will not cause the rendering to stop.
179
+ default: true
180
+ tag:
181
+ type: string
182
+ description: A field for storing a small amount of metadata with this document.
183
+ help:
184
+ type: boolean
185
+ description: Request support help with this request if it succeeds.
186
+ default: false
187
+ javascript:
188
+ type: boolean
189
+ description: Enable DocRaptor JavaScript parsing. PrinceXML JavaScript parsing is also available elsewhere.
190
+ default: false
191
+ referrer:
192
+ type: string
193
+ description: Set HTTP referrer when generating this document.
194
+ callback_url:
195
+ type: string
196
+ description: |
197
+ A URL that will receive a POST request after successfully completing an asynchronous document.
198
+ The POST data will include download_url and download_id similar to status api responses.
199
+ WARNING: this only works on asynchronous documents.
200
+ prince_options:
201
+ $ref: '#/definitions/PrinceOptions'
202
+
203
+ PrinceOptions:
204
+ type: object
205
+ properties:
206
+ baseurl:
207
+ type: string
208
+ description: Set the baseurl for assets.
209
+ no_xinclude:
210
+ type: boolean
211
+ description: Disable XML inclusion.
212
+ no_network:
213
+ type: boolean
214
+ description: Disable network access.
215
+ http_user:
216
+ type: string
217
+ description: Set the user for HTTP authentication.
218
+ http_password:
219
+ type: string
220
+ description: Set the password for HTTP authentication.
221
+ http_proxy:
222
+ type: string
223
+ description: Set the HTTP proxy server.
224
+ http_timeout:
225
+ type: integer
226
+ description: Set the HTTP request timeout.
227
+ # default: 10
228
+ insecure:
229
+ type: boolean
230
+ description: Disable SSL verification.
231
+ # default: false
232
+ media:
233
+ type: string
234
+ description: Specify the CSS media type. Defaults to "print" but you may want to use "screen" for web styles.
235
+ default: print
236
+ no_author_style:
237
+ type: boolean
238
+ description: Ignore author stylesheets.
239
+ no_default_style:
240
+ type: boolean
241
+ description: Ignore default stylesheets.
242
+ no_embed_fonts:
243
+ type: boolean
244
+ description: Disable font embedding in PDFs.
245
+ no_subset_fonts:
246
+ type: boolean
247
+ description: Disable font subsetting in PDFs.
248
+ no_compress:
249
+ type: boolean
250
+ description: Disable PDF compression.
251
+ encrypt:
252
+ type: boolean
253
+ description: Encrypt PDF output.
254
+ key_bits:
255
+ type: integer
256
+ description: Set encryption key size.
257
+ enum:
258
+ - 40
259
+ - 128
260
+ user_password:
261
+ type: string
262
+ description: Set the PDF user password.
263
+ owner_password:
264
+ type: string
265
+ description: Set the PDF owner password.
266
+ disallow_print:
267
+ type: boolean
268
+ description: Disallow printing of this PDF.
269
+ disallow_copy:
270
+ type: boolean
271
+ description: Disallow copying of this PDF.
272
+ disallow_annotate:
273
+ type: boolean
274
+ description: Disallow annotation of this PDF.
275
+ disallow_modify:
276
+ type: boolean
277
+ description: Disallow modification of this PDF.
278
+ input:
279
+ type: string
280
+ description: Specify the input format.
281
+ default: html
282
+ enum:
283
+ - html
284
+ - xml
285
+ - auto
286
+ version:
287
+ type: string
288
+ description: Specify a specific verison of PrinceXML to use.
289
+ # default: 10
290
+ # disabled because Java will try to make an enum as 7_1 which fails
291
+ # enum:
292
+ # - 7.1
293
+ # - 8.1
294
+ # - 9.0
295
+ # - 10
296
+ javascript:
297
+ type: boolean
298
+ description: Enable PrinceXML JavaScript. DocRaptor JavaScript parsing is also available elsewhere.
299
+ css_dpi:
300
+ type: integer
301
+ description: Set the DPI when rendering CSS. Defaults to 96 but can be set with Prince 9.0 and up.
302
+ # default: 96
303
+ profile:
304
+ type: string
305
+ description: In Prince 9.0 and up you can set the PDF profile.
306
+ # disabled because Java will try to make an enum with PDF/A-1b which fails
307
+ # enum:
308
+ # - PDF/A-1b
309
+ # - PDF/X-3:2003
310
+ # - PDF/X-4
311
+
312
+ AsyncDoc:
313
+ type: object
314
+ properties:
315
+ status_id:
316
+ type: string
317
+ description: The identifier used to get the status of the document using the status api.
318
+
319
+ AsyncDocStatus:
320
+ type: object
321
+ properties:
322
+ status:
323
+ type: string
324
+ description: The present status of the document. Can be queued, working, completed, and failed.
325
+ download_url:
326
+ type: string
327
+ description: The URL where the document can be retrieved. This URL may only be used a few times.
328
+ download_id:
329
+ type: string
330
+ description: The identifier for downloading the document with the download api.
331
+ message:
332
+ type: string
333
+ description: Additional information.
334
+ number_of_pages:
335
+ type: integer
336
+ description: Number of PDF pages in document.
337
+ validation_errors:
338
+ type: string
339
+ description: Error information.
@@ -13,8 +13,8 @@ module DocRaptor
13
13
  # @param doc The document to be created.
14
14
  # @param [Hash] opts the optional parameters
15
15
  # @return [AsyncDoc]
16
- def async_docs_post(doc, opts = {})
17
- data, status_code, headers = async_docs_post_with_http_info(doc, opts)
16
+ def create_async_doc(doc, opts = {})
17
+ data, status_code, headers = create_async_doc_with_http_info(doc, opts)
18
18
  return data
19
19
  end
20
20
 
@@ -23,13 +23,13 @@ module DocRaptor
23
23
  # @param doc The document to be created.
24
24
  # @param [Hash] opts the optional parameters
25
25
  # @return [Array<(AsyncDoc, Fixnum, Hash)>] AsyncDoc data, response status code and response headers
26
- def async_docs_post_with_http_info(doc, opts = {})
26
+ def create_async_doc_with_http_info(doc, opts = {})
27
27
  if @api_client.config.debugging
28
- @api_client.config.logger.debug "Calling API: ClientApi#async_docs_post ..."
28
+ @api_client.config.logger.debug "Calling API: ClientApi#create_async_doc ..."
29
29
  end
30
30
 
31
31
  # verify the required parameter 'doc' is set
32
- fail "Missing the required parameter 'doc' when calling async_docs_post" if doc.nil?
32
+ fail "Missing the required parameter 'doc' when calling create_async_doc" if doc.nil?
33
33
 
34
34
  # resource path
35
35
  path = "/async_docs".sub('{format}','json')
@@ -64,7 +64,7 @@ module DocRaptor
64
64
  :auth_names => auth_names,
65
65
  :return_type => 'AsyncDoc')
66
66
  if @api_client.config.debugging
67
- @api_client.config.logger.debug "API called: ClientApi#async_docs_post\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
67
+ @api_client.config.logger.debug "API called: ClientApi#create_async_doc\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
68
68
  end
69
69
  return data, status_code, headers
70
70
  end
@@ -74,8 +74,8 @@ module DocRaptor
74
74
  # @param doc The document to be created.
75
75
  # @param [Hash] opts the optional parameters
76
76
  # @return [File]
77
- def docs_post(doc, opts = {})
78
- data, status_code, headers = docs_post_with_http_info(doc, opts)
77
+ def create_doc(doc, opts = {})
78
+ data, status_code, headers = create_doc_with_http_info(doc, opts)
79
79
  return data
80
80
  end
81
81
 
@@ -84,13 +84,13 @@ module DocRaptor
84
84
  # @param doc The document to be created.
85
85
  # @param [Hash] opts the optional parameters
86
86
  # @return [Array<(File, Fixnum, Hash)>] File data, response status code and response headers
87
- def docs_post_with_http_info(doc, opts = {})
87
+ def create_doc_with_http_info(doc, opts = {})
88
88
  if @api_client.config.debugging
89
- @api_client.config.logger.debug "Calling API: ClientApi#docs_post ..."
89
+ @api_client.config.logger.debug "Calling API: ClientApi#create_doc ..."
90
90
  end
91
91
 
92
92
  # verify the required parameter 'doc' is set
93
- fail "Missing the required parameter 'doc' when calling docs_post" if doc.nil?
93
+ fail "Missing the required parameter 'doc' when calling create_doc" if doc.nil?
94
94
 
95
95
  # resource path
96
96
  path = "/docs".sub('{format}','json')
@@ -125,7 +125,7 @@ module DocRaptor
125
125
  :auth_names => auth_names,
126
126
  :return_type => 'File')
127
127
  if @api_client.config.debugging
128
- @api_client.config.logger.debug "API called: ClientApi#docs_post\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
128
+ @api_client.config.logger.debug "API called: ClientApi#create_doc\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
129
129
  end
130
130
  return data, status_code, headers
131
131
  end
@@ -135,8 +135,8 @@ module DocRaptor
135
135
  # @param id The download_id returned from status request or a callback.
136
136
  # @param [Hash] opts the optional parameters
137
137
  # @return [File]
138
- def download_id_get(id, opts = {})
139
- data, status_code, headers = download_id_get_with_http_info(id, opts)
138
+ def get_async_doc(id, opts = {})
139
+ data, status_code, headers = get_async_doc_with_http_info(id, opts)
140
140
  return data
141
141
  end
142
142
 
@@ -145,13 +145,13 @@ module DocRaptor
145
145
  # @param id The download_id returned from status request or a callback.
146
146
  # @param [Hash] opts the optional parameters
147
147
  # @return [Array<(File, Fixnum, Hash)>] File data, response status code and response headers
148
- def download_id_get_with_http_info(id, opts = {})
148
+ def get_async_doc_with_http_info(id, opts = {})
149
149
  if @api_client.config.debugging
150
- @api_client.config.logger.debug "Calling API: ClientApi#download_id_get ..."
150
+ @api_client.config.logger.debug "Calling API: ClientApi#get_async_doc ..."
151
151
  end
152
152
 
153
153
  # verify the required parameter 'id' is set
154
- fail "Missing the required parameter 'id' when calling download_id_get" if id.nil?
154
+ fail "Missing the required parameter 'id' when calling get_async_doc" if id.nil?
155
155
 
156
156
  # resource path
157
157
  path = "/download/{id}".sub('{format}','json').sub('{' + 'id' + '}', id.to_s)
@@ -186,7 +186,7 @@ module DocRaptor
186
186
  :auth_names => auth_names,
187
187
  :return_type => 'File')
188
188
  if @api_client.config.debugging
189
- @api_client.config.logger.debug "API called: ClientApi#download_id_get\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
189
+ @api_client.config.logger.debug "API called: ClientApi#get_async_doc\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
190
190
  end
191
191
  return data, status_code, headers
192
192
  end
@@ -196,8 +196,8 @@ module DocRaptor
196
196
  # @param id The status_id returned when creating an asynchronous document.
197
197
  # @param [Hash] opts the optional parameters
198
198
  # @return [AsyncDocStatus]
199
- def status_id_get(id, opts = {})
200
- data, status_code, headers = status_id_get_with_http_info(id, opts)
199
+ def get_async_doc_status(id, opts = {})
200
+ data, status_code, headers = get_async_doc_status_with_http_info(id, opts)
201
201
  return data
202
202
  end
203
203
 
@@ -206,13 +206,13 @@ module DocRaptor
206
206
  # @param id The status_id returned when creating an asynchronous document.
207
207
  # @param [Hash] opts the optional parameters
208
208
  # @return [Array<(AsyncDocStatus, Fixnum, Hash)>] AsyncDocStatus data, response status code and response headers
209
- def status_id_get_with_http_info(id, opts = {})
209
+ def get_async_doc_status_with_http_info(id, opts = {})
210
210
  if @api_client.config.debugging
211
- @api_client.config.logger.debug "Calling API: ClientApi#status_id_get ..."
211
+ @api_client.config.logger.debug "Calling API: ClientApi#get_async_doc_status ..."
212
212
  end
213
213
 
214
214
  # verify the required parameter 'id' is set
215
- fail "Missing the required parameter 'id' when calling status_id_get" if id.nil?
215
+ fail "Missing the required parameter 'id' when calling get_async_doc_status" if id.nil?
216
216
 
217
217
  # resource path
218
218
  path = "/status/{id}".sub('{format}','json').sub('{' + 'id' + '}', id.to_s)
@@ -247,7 +247,7 @@ module DocRaptor
247
247
  :auth_names => auth_names,
248
248
  :return_type => 'AsyncDocStatus')
249
249
  if @api_client.config.debugging
250
- @api_client.config.logger.debug "API called: ClientApi#status_id_get\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
250
+ @api_client.config.logger.debug "API called: ClientApi#get_async_doc_status\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
251
251
  end
252
252
  return data, status_code, headers
253
253
  end
@@ -170,23 +170,37 @@ module DocRaptor
170
170
  # from the "Content-Disposition" header if provided, otherwise a random filename.
171
171
  #
172
172
  # @see Configuration#temp_folder_path
173
- # @return [File] the file downloaded
173
+ # @return [Tempfile] the file downloaded
174
174
  def download_file(response)
175
- tmp_file = Tempfile.new '', @config.temp_folder_path
176
175
  content_disposition = response.headers['Content-Disposition']
177
176
  if content_disposition
178
177
  filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
179
- path = File.join File.dirname(tmp_file), filename
178
+ prefix = sanitize_filename(filename)
180
179
  else
181
- path = tmp_file.path
180
+ prefix = 'download-'
182
181
  end
183
- # close and delete temp file
184
- tmp_file.close!
182
+ prefix = prefix + '-' unless prefix.end_with?('-')
185
183
 
186
- File.open(path, 'w') { |file| file.write(response.body) }
187
- @config.logger.info "File written to #{path}. Please move the file to a proper folder "\
188
- "for further processing and delete the temp afterwards"
189
- File.new(path)
184
+ tempfile = nil
185
+ encoding = response.body.encoding
186
+ Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) do |file|
187
+ file.write(response.body)
188
+ tempfile = file
189
+ end
190
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
191
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
192
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
193
+ "explicitly with `tempfile.delete`"
194
+ tempfile
195
+ end
196
+
197
+ # Sanitize filename by removing path.
198
+ # e.g. ../../sun.gif becomes sun.gif
199
+ #
200
+ # @param [String] filename the filename to be sanitized
201
+ # @return [String] the sanitized filename
202
+ def sanitize_filename(filename)
203
+ filename.gsub /.*[\/\\]/, ''
190
204
  end
191
205
 
192
206
  def build_request_url(path)
@@ -20,6 +20,9 @@ module DocRaptor
20
20
  # Force strict HTML validation.
21
21
  attr_accessor :strict
22
22
 
23
+ # Failed loading of images/javascripts/stylesheets/etc. will not cause the rendering to stop.
24
+ attr_accessor :ignore_resource_errors
25
+
23
26
  # A field for storing a small amount of metadata with this document.
24
27
  attr_accessor :tag
25
28
 
@@ -53,6 +56,8 @@ module DocRaptor
53
56
 
54
57
  :'strict' => :'strict',
55
58
 
59
+ :'ignore_resource_errors' => :'ignore_resource_errors',
60
+
56
61
  :'tag' => :'tag',
57
62
 
58
63
  :'help' => :'help',
@@ -77,6 +82,7 @@ module DocRaptor
77
82
  :'document_url' => :'String',
78
83
  :'test' => :'BOOLEAN',
79
84
  :'strict' => :'String',
85
+ :'ignore_resource_errors' => :'BOOLEAN',
80
86
  :'tag' => :'String',
81
87
  :'help' => :'BOOLEAN',
82
88
  :'javascript' => :'BOOLEAN',
@@ -122,6 +128,12 @@ module DocRaptor
122
128
  self.strict = "none"
123
129
  end
124
130
 
131
+ if attributes[:'ignore_resource_errors']
132
+ self.ignore_resource_errors = attributes[:'ignore_resource_errors']
133
+ else
134
+ self.ignore_resource_errors = true
135
+ end
136
+
125
137
  if attributes[:'tag']
126
138
  self.tag = attributes[:'tag']
127
139
  end
@@ -180,6 +192,7 @@ module DocRaptor
180
192
  document_url == o.document_url &&
181
193
  test == o.test &&
182
194
  strict == o.strict &&
195
+ ignore_resource_errors == o.ignore_resource_errors &&
183
196
  tag == o.tag &&
184
197
  help == o.help &&
185
198
  javascript == o.javascript &&
@@ -195,7 +208,7 @@ module DocRaptor
195
208
 
196
209
  # Calculate hash code according to all attributes.
197
210
  def hash
198
- [name, document_type, document_content, document_url, test, strict, tag, help, javascript, referrer, callback_url, prince_options].hash
211
+ [name, document_type, document_content, document_url, test, strict, ignore_resource_errors, tag, help, javascript, referrer, callback_url, prince_options].hash
199
212
  end
200
213
 
201
214
  # build the object from hash
@@ -1,3 +1,3 @@
1
1
  module DocRaptor
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
Binary file
data/script/clean ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+ set -e
3
+ cd "`dirname \"$0\"`/.."
4
+
5
+ rm -rf lib/
@@ -0,0 +1,29 @@
1
+ #!/bin/sh
2
+ set -e
3
+ cd "`dirname \"$0\"`/.."
4
+
5
+ LANGUAGE="$1"
6
+ CONFIG_FILE="swagger-config.json"
7
+
8
+ if [ "$LANGUAGE" == "" ]; then
9
+ ./script/swagger # prints languages
10
+ exit 1
11
+ fi
12
+
13
+ if [ ! -f "$CONFIG_FILE" ]; then
14
+ echo "Could not find $CONFIG_FILE"
15
+ ./script/swagger config-help -l $LANGUAGE
16
+ exit 1
17
+ fi
18
+
19
+ ./script/clean
20
+
21
+ ./script/swagger generate \
22
+ -i docraptor.yaml \
23
+ -l $LANGUAGE \
24
+ -c $CONFIG_FILE
25
+
26
+ # call a generator cleanup script
27
+ if [ -f "script/post_generate_language" ]; then
28
+ ./script/post_generate_language
29
+ fi
data/script/swagger ADDED
@@ -0,0 +1,26 @@
1
+ #!/bin/bash
2
+ set -e
3
+ cd "`dirname \"$0\"`/.."
4
+
5
+ if [ ! -d "swagger-codegen" ]; then
6
+ git clone https://github.com/swagger-api/swagger-codegen
7
+ fi
8
+
9
+ cd swagger-codegen
10
+
11
+ SWAGGER_CODGEN_REVISION="e50dc04418b288dff16686a57eb6d4d540c073d2" # v2.1.5+
12
+ if [[ `cat .git/HEAD` != "$SWAGGER_CODGEN_REVISION" ]]; then
13
+ git fetch
14
+ git checkout $SWAGGER_CODGEN_REVISION
15
+ mvn clean package
16
+ fi
17
+ cd ..
18
+
19
+ executable="./swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
20
+
21
+ if [ ! -f "$executable" ]; then
22
+ mvn clean package
23
+ fi
24
+
25
+ export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
26
+ java $JAVA_OPTS -jar $executable $*
data/script/test ADDED
@@ -0,0 +1,14 @@
1
+ #!/bin/sh
2
+ set -e
3
+ cd "`dirname \"$0\"`/.."
4
+
5
+ cd test/
6
+ bundle install
7
+
8
+ if [ "$1" == "" ]; then
9
+ for test in $(ls *.rb); do
10
+ ruby $test
11
+ done
12
+ else
13
+ ruby $1.rb
14
+ fi
@@ -0,0 +1,43 @@
1
+ #!/bin/bash
2
+ set -e
3
+ cd "`dirname \"$0\"`/.."
4
+
5
+ if [[ `basename $PWD` == "swagger" ]]; then
6
+ echo "This command is only used in langauge specific repositories"
7
+ exit 1
8
+ fi
9
+
10
+ # Gets content at $1 and puts it into $2, automatically chmod +x if $2 is the
11
+ # script dir.
12
+ get() {
13
+ curl --fail --silent --show-error $1 > $2
14
+ if [[ `dirname $2` == "script" ]]; then
15
+ chmod +x $2
16
+ fi
17
+ }
18
+
19
+ # Gets a file $1 from the upstream repo and places it in the same location.
20
+ get_upstream() {
21
+ get "https://raw.githubusercontent.com/docraptor/docraptor-swagger/master/$1" $1
22
+ }
23
+
24
+ # Main entry point, wrapped in a function so that bash can handle replacing
25
+ # this file while executing it.
26
+ update() {
27
+ original=`md5 script/update_from_upstream`
28
+ get_upstream script/update_from_upstream
29
+ if [[ `md5 script/update_from_upstream` != "$original" ]]; then
30
+ echo "Detected updated update_from_upstream command, running again"
31
+ script/update_from_upstream
32
+ exit 0 # recursive call above handled everything
33
+ fi
34
+
35
+ get_upstream docraptor.yaml
36
+
37
+ get_upstream script/swagger
38
+ script/swagger # download repo, etc.
39
+
40
+ get_upstream script/generate_language
41
+ }
42
+
43
+ update
@@ -0,0 +1,5 @@
1
+ {
2
+ "gemName": "docraptor",
3
+ "moduleName": "DocRaptor",
4
+ "gemVersion": "0.0.3"
5
+ }
data/test/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "pry"
4
+ gem "docraptor", path: ".."
data/test/async.rb ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ require "bundler/setup"
3
+ Bundler.require
4
+
5
+ DocRaptor.configure do |dr|
6
+ dr.username = "YOUR_API_KEY_HERE"
7
+ dr.debugging = true
8
+ end
9
+
10
+ doc_api = DocRaptor::ClientApi.new
11
+
12
+ response = doc_api.create_async_doc(test: true, document_content: "<html><body>Swagger Ruby</body></html>", name: "swagger-ruby.pdf", document_type: "pdf")
13
+
14
+ status_response = nil
15
+ loop do
16
+ status_response = doc_api.get_async_doc_status(response.status_id)
17
+ break if status_response.status == "completed"
18
+ sleep 1
19
+ end
20
+
21
+ puts doc_api.get_async_doc(status_response.download_id)
22
+
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ require "bundler/setup"
3
+ Bundler.require
4
+
5
+ DocRaptor.configure do |dr|
6
+ dr.username = "YOUR_API_KEY_HERE"
7
+ dr.debugging = true
8
+ end
9
+
10
+ doc_api = DocRaptor::ClientApi.new
11
+
12
+ response = doc_api.create_async_doc(test: true, document_content: "<html><body>Swagger Ruby</body></html>", name: "s" * 201, document_type: "pdf")
13
+
14
+ status_response = nil
15
+ 30.times do
16
+ status_response = doc_api.get_async_doc_status(response.status_id)
17
+ exit if status_response.status == "failed"
18
+ sleep 1
19
+ end
20
+
21
+ abort "Did not receive failed validation within 30 seconds."
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ require "bundler/setup"
3
+ Bundler.require
4
+
5
+ DocRaptor.configure do |dr|
6
+ dr.username = "YOUR_API_KEY_HERE"
7
+ dr.debugging = true
8
+ end
9
+
10
+ doc_api = DocRaptor::ClientApi.new
11
+
12
+
13
+ begin
14
+ response = doc_api.create_doc(test: true, name: "s" * 201, document_type: "pdf")
15
+ rescue DocRaptor::ApiError
16
+ exit
17
+ end
18
+
19
+ abort "Exception expected, but not raised"
data/test/sync.rb ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ require "bundler/setup"
3
+ Bundler.require
4
+
5
+ DocRaptor.configure do |dr|
6
+ dr.username = "YOUR_API_KEY_HERE"
7
+ dr.debugging = true
8
+ end
9
+
10
+ doc_api = DocRaptor::ClientApi.new
11
+
12
+ response = doc_api.create_doc(test: true, document_content: "<html><body>Swagger Ruby</body></html>", name: "swagger-ruby.pdf", document_type: "pdf")
data/test/xlsx.rb ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ require "bundler/setup"
3
+ Bundler.require
4
+
5
+ DocRaptor.configure do |dr|
6
+ dr.username = "YOUR_API_KEY_HERE"
7
+ dr.debugging = true
8
+ end
9
+
10
+ dr = DocRaptor::ClientApi.new
11
+
12
+ response = dr.create_doc(test: true, document_content: "<html><body><table><tr><td>Swagger Ruby</td></tr></table></body></html>", name: "swagger-ruby.xlsx", document_type: "xlsx")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docraptor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elijah Miller
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-01-07 00:00:00.000000000 Z
12
+ date: 2016-01-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: typhoeus
@@ -200,7 +200,7 @@ dependencies:
200
200
  version: '0.2'
201
201
  - - ">="
202
202
  - !ruby/object:Gem::Version
203
- version: 0.2.10
203
+ version: 0.2.11
204
204
  type: :development
205
205
  prerelease: false
206
206
  version_requirements: !ruby/object:Gem::Requirement
@@ -210,7 +210,7 @@ dependencies:
210
210
  version: '0.2'
211
211
  - - ">="
212
212
  - !ruby/object:Gem::Version
213
- version: 0.2.10
213
+ version: 0.2.11
214
214
  description: A native client library for the DocRaptor HTML to PDF/XLS service.
215
215
  email:
216
216
  - elijah@expectedbehavior.com
@@ -219,8 +219,14 @@ executables: []
219
219
  extensions: []
220
220
  extra_rdoc_files: []
221
221
  files:
222
+ - CHANGELOG.md
223
+ - Gemfile
224
+ - Gemfile.lock
225
+ - LICENSE
226
+ - README.md
222
227
  - Rakefile
223
228
  - docraptor.gemspec
229
+ - docraptor.yaml
224
230
  - lib/docraptor.rb
225
231
  - lib/docraptor/api/client_api.rb
226
232
  - lib/docraptor/api_client.rb
@@ -231,9 +237,22 @@ files:
231
237
  - lib/docraptor/models/doc.rb
232
238
  - lib/docraptor/models/prince_options.rb
233
239
  - lib/docraptor/version.rb
240
+ - pkg/docraptor-0.0.3.gem
241
+ - script/clean
242
+ - script/generate_language
243
+ - script/swagger
244
+ - script/test
245
+ - script/update_from_upstream
246
+ - swagger-config.json
247
+ - test/Gemfile
248
+ - test/async.rb
249
+ - test/invalid_async.rb
250
+ - test/invalid_sync.rb
251
+ - test/sync.rb
252
+ - test/xlsx.rb
234
253
  homepage: https://docraptor.com
235
254
  licenses:
236
- - MIT
255
+ - Apache-2.0
237
256
  metadata: {}
238
257
  post_install_message:
239
258
  rdoc_options: []
@@ -251,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
251
270
  version: '0'
252
271
  requirements: []
253
272
  rubyforge_project:
254
- rubygems_version: 2.5.1
273
+ rubygems_version: 2.4.5.1
255
274
  signing_key:
256
275
  specification_version: 4
257
276
  summary: A wrapper for the DocRaptor HTML to PDF/XLS service.