docraptor-cli 0.0.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.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +84 -0
- data/Rakefile +2 -0
- data/bin/docraptor +328 -0
- data/docraptor-cli.gemspec +24 -0
- data/lib/docraptor-cli/version.rb +3 -0
- data/script/test +12 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8057932a008393a2af5ede0830d893c2154c8847
|
4
|
+
data.tar.gz: 2aba90e1ffaedc4675035b02494987158ae3c9b9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 21520e48134b3a3966a075fcb2e5e1217f292fa05c09241740f2e414ce3b72c179adeedc037ff4bcbedd2b378359fddaad7d80215cc83616313c47b0be0c84dd
|
7
|
+
data.tar.gz: 6486ce5522ed2d1ea91a8515f6fd2e7aac34642322207d93860d7e00d5677ff52914a99e013b567757d4b55c94e2f012e6328dd060414fcaba7a1d86ea30629c
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2016 Expected Behavior
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# DocRaptor CLI
|
2
|
+
|
3
|
+
**WARNING: This is a beta client and subject to serious change**
|
4
|
+
|
5
|
+
This is a command line interface for using [DocRaptor API](https://docraptor.com/documentation) to convert [HTML to PDF and XLSX](https://docraptor.com).
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
```bash
|
11
|
+
gem install docraptor-cli
|
12
|
+
```
|
13
|
+
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
```bash
|
18
|
+
docraptor local_file.html # local files
|
19
|
+
docraptor https://docraptor.com/examples/invoice.html # URLs are detected by prefix
|
20
|
+
```
|
21
|
+
|
22
|
+
The full DocRaptor API is available, see:
|
23
|
+
|
24
|
+
```
|
25
|
+
Usage: docraptor [options] <url/file>
|
26
|
+
|
27
|
+
Server options:
|
28
|
+
-k, --key KEY The API Key to use when calling the service. Defaults to YOUR_API_KEY_HERE or ENV[DOCRAPTOR_API_KEY].
|
29
|
+
-s, --server SERVER Make API requests against SERVER, scheme not required. Defaults to https://docraptor.com
|
30
|
+
|
31
|
+
Document options:
|
32
|
+
--async Create document asynchronously(10 min limit). Defaults to synchronous(1 min limit).
|
33
|
+
-d, --debug Enable debug logging.
|
34
|
+
--no-ignore-resource-errors Error when a resource cannot be downloaded.
|
35
|
+
-j, --javascript Enable DocRaptor JavaScript parsing. Defaults to no javascript.
|
36
|
+
--name NAME Give a name to this document. Defaults to a randomized string. Does not affect output filename.
|
37
|
+
--referrer URL Set HTTP REFERRER when rendering. Defaults to localhost for file rendering or render url.
|
38
|
+
--strict STRICTNESS Set HTML strictness. Defaults to none.
|
39
|
+
--test Create this as a test document. Defaults to non-test.
|
40
|
+
-t, --type TYPE Type of document to make, can be pdf, xls, xlsx. Defaults to pdf.
|
41
|
+
|
42
|
+
Prince options:
|
43
|
+
--prince-baseurl URL Set base url when rendering. Defaults to nothing for file rendering or render url.
|
44
|
+
--prince-css-dpi DPI Set a base CSS DPI. Defaults value used by Prince is 96.
|
45
|
+
|
46
|
+
...
|
47
|
+
```
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
We have guides for doing some of the common things:
|
52
|
+
|
53
|
+
* [Headers and Footers](https://docraptor.com/documentation/style#pdf-headers-footers) including page skipping
|
54
|
+
* [CSS Media Selector](https://docraptor.com/documentation/api#api_basic_pdf) to make the page look exactly as it does in your browser
|
55
|
+
* 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
|
56
|
+
|
57
|
+
|
58
|
+
## More Help
|
59
|
+
|
60
|
+
DocRaptor has a lot of more [styling](https://docraptor.com/documentation/style) and [implementation options](https://docraptor.com/documentation/api).
|
61
|
+
|
62
|
+
Stuck? We're experts at using DocRaptor so please [email us](mailto:support@docraptor.com) if you run into trouble.
|
63
|
+
|
64
|
+
|
65
|
+
## Development
|
66
|
+
|
67
|
+
This code is a thin wrapper around the [docraptor gem](https://github.com/docraptor/docraptor-ruby) to make it suitable for command line users.
|
68
|
+
|
69
|
+
|
70
|
+
## Release Process
|
71
|
+
|
72
|
+
1. Pull latest master
|
73
|
+
2. Merge feature branch(es) into master
|
74
|
+
3. `script/test`
|
75
|
+
4. Increment version in code:
|
76
|
+
- ...
|
77
|
+
5. Update [CHANGELOG.md](CHANGELOG.md)
|
78
|
+
6. Commit "Release version vX.Y.Z"
|
79
|
+
7. `rake release`
|
80
|
+
|
81
|
+
|
82
|
+
## Version Policy
|
83
|
+
|
84
|
+
This library follows [Semantic Versioning 2.0.0](http://semver.org).
|
data/Rakefile
ADDED
data/bin/docraptor
ADDED
@@ -0,0 +1,328 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", __FILE__)
|
3
|
+
require "bundler"
|
4
|
+
Bundler.require
|
5
|
+
require "optparse"
|
6
|
+
|
7
|
+
TYPES = %w(pdf xls xlsx)
|
8
|
+
PRINT_STATUS_EVERY = 30
|
9
|
+
|
10
|
+
def log(message)
|
11
|
+
STDERR.puts(message)
|
12
|
+
end
|
13
|
+
|
14
|
+
options = {
|
15
|
+
# Server Options
|
16
|
+
key: ENV["DOCRAPTOR_API_KEY"] || "YOUR_API_KEY_HERE",
|
17
|
+
server: "https://docraptor.com",
|
18
|
+
|
19
|
+
# Document Options
|
20
|
+
javascript: false,
|
21
|
+
test: false,
|
22
|
+
type: "pdf",
|
23
|
+
strict: "none",
|
24
|
+
async: false,
|
25
|
+
|
26
|
+
# Script Options
|
27
|
+
open: true,
|
28
|
+
}
|
29
|
+
|
30
|
+
opt_parser = OptionParser.new do |opts|
|
31
|
+
opts.banner = "Usage: #{$0} [options] <url/file>"
|
32
|
+
|
33
|
+
|
34
|
+
opts.separator ""
|
35
|
+
opts.separator "Server options:"
|
36
|
+
|
37
|
+
opts.on("-kKEY", "--key KEY", "The API Key to use when calling the service. Defaults to YOUR_API_KEY_HERE or ENV[DOCRAPTOR_API_KEY].") do |key|
|
38
|
+
options[:key] = key
|
39
|
+
end
|
40
|
+
|
41
|
+
opts.on("-sSERVER", "--server SERVER",
|
42
|
+
"Make API requests against SERVER, scheme not required. Defaults to #{options[:server]}") do |server|
|
43
|
+
if !server.include?("://")
|
44
|
+
scheme = server =~ /\Alocalhost/ ? "http" : "https"
|
45
|
+
server = "#{scheme}://#{server}"
|
46
|
+
end
|
47
|
+
options[:server] = server
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
opts.separator ""
|
52
|
+
opts.separator "Document options:"
|
53
|
+
|
54
|
+
opts.on("--async", "Create document asynchronously(10 min limit). Defaults to synchronous(1 min limit).") do |async|
|
55
|
+
options[:async] = async
|
56
|
+
end
|
57
|
+
|
58
|
+
opts.on("-d", "--debug", "Enable debug logging.") do
|
59
|
+
options[:debug] = true
|
60
|
+
end
|
61
|
+
|
62
|
+
opts.on("--no-ignore-resource-errors",
|
63
|
+
"Error when a resource cannot be downloaded.") do |ignore_resource_errors|
|
64
|
+
options[:ignore_resource_errors] = true
|
65
|
+
end
|
66
|
+
|
67
|
+
opts.on("-j", "--javascript", "Enable DocRaptor JavaScript parsing. Defaults to no javascript.") do |javascript|
|
68
|
+
options[:javascript] = javascript
|
69
|
+
end
|
70
|
+
|
71
|
+
opts.on("--name NAME", "Give a name to this document. Defaults to a randomized string. Does not affect output filename.") do |name|
|
72
|
+
options[:name] = name
|
73
|
+
end
|
74
|
+
|
75
|
+
opts.on("--referrer URL", "Set HTTP REFERRER when rendering. Defaults to localhost for file rendering or render url.") do |url|
|
76
|
+
options[:referrer] = url
|
77
|
+
end
|
78
|
+
|
79
|
+
opts.on("--strict STRICTNESS", "Set HTML strictness. Defaults to none.") do |strict|
|
80
|
+
options[:strict] = strict
|
81
|
+
end
|
82
|
+
|
83
|
+
opts.on("--test", "Create this as a test document. Defaults to non-test.") do |test|
|
84
|
+
options[:test] = test
|
85
|
+
end
|
86
|
+
|
87
|
+
opts.on("-t", "--type TYPE", TYPES, "Type of document to make, can be #{TYPES.join(', ')}. Defaults to pdf.") do |type|
|
88
|
+
options[:type] = type
|
89
|
+
end
|
90
|
+
|
91
|
+
opts.separator ""
|
92
|
+
opts.separator "Prince options:"
|
93
|
+
|
94
|
+
opts.on("--prince-baseurl URL", "Set base url when rendering. Defaults to nothing for file rendering or render url.") do |url|
|
95
|
+
options[:prince_baseurl] = url
|
96
|
+
end
|
97
|
+
|
98
|
+
opts.on("--prince-css-dpi DPI", "Set a base CSS DPI. Defaults value used by Prince is 96.") do |dpi|
|
99
|
+
options[:prince_css_dpi] = dpi
|
100
|
+
end
|
101
|
+
|
102
|
+
opts.on("--prince-disallow-annotate", "Disallow annotating the final PDF.") do |disallow|
|
103
|
+
options[:prince_disallow_annotate] = disallow
|
104
|
+
end
|
105
|
+
|
106
|
+
opts.on("--prince-disallow-copy", "Disallow copying the final PDF.") do |disallow|
|
107
|
+
options[:prince_disallow_copy] = disallow
|
108
|
+
end
|
109
|
+
|
110
|
+
opts.on("--prince-disallow-modify", "Disallow modifying the final PDF.") do |disallow|
|
111
|
+
options[:prince_disallow_modify] = disallow
|
112
|
+
end
|
113
|
+
|
114
|
+
opts.on("--prince-disallow-print", "Disallow printing the final PDF.") do |disallow|
|
115
|
+
options[:prince_disallow_print] = disallow
|
116
|
+
end
|
117
|
+
|
118
|
+
opts.on("--prince-encrypt", "Encrypt the output PDF.") do |encrypt|
|
119
|
+
options[:prince_encrypt] = encrypt
|
120
|
+
end
|
121
|
+
|
122
|
+
opts.on("--prince-key-bits BITS", "Set the encryption key size, must be used with --prince-encrypt.") do |key_bits|
|
123
|
+
options[:prince_key_bits] = key_bits
|
124
|
+
end
|
125
|
+
|
126
|
+
opts.on("--prince-input INPUT", "Set the input type for PDF: xml, html, auto.") do |input|
|
127
|
+
options[:prince_input] = input
|
128
|
+
end
|
129
|
+
|
130
|
+
opts.on("--prince-no-compress", "Disable PDF compression.") do |no_compress|
|
131
|
+
options[:prince_no_compress] = no_compress
|
132
|
+
end
|
133
|
+
|
134
|
+
opts.on("--prince-user-password PASS", "Set the user password for decrypting an encrypted PDF.") do |password|
|
135
|
+
options[:prince_user_password] = password
|
136
|
+
end
|
137
|
+
|
138
|
+
opts.on("--prince-owner-password PASS", "Set the owner password for decrypting an encrypted PDF.") do |password|
|
139
|
+
options[:prince_owner_password] = password
|
140
|
+
end
|
141
|
+
|
142
|
+
opts.on("--prince-insecure", "Set the insecure flag") do |insecure|
|
143
|
+
options[:prince_insecure] = insecure
|
144
|
+
end
|
145
|
+
|
146
|
+
opts.on("--prince-http-timeout SECS", "Set the timeout for HTTP connections made by prince") do |timeout_seconds|
|
147
|
+
options[:prince_http_timeout] = timeout_seconds
|
148
|
+
end
|
149
|
+
|
150
|
+
opts.on("--prince-http-user USER", "Set the user for setting basic auth credentials. Defaults to nothing for file rendering or render url.") do |user|
|
151
|
+
options[:prince_http_user] = user
|
152
|
+
end
|
153
|
+
|
154
|
+
opts.on("--prince-http-password PASS", "Set the password for setting basic auth credentials. Defaults to nothing for file rendering or render url.") do |password|
|
155
|
+
options[:prince_http_password] = password
|
156
|
+
end
|
157
|
+
|
158
|
+
opts.on("--prince-http-proxy PROXY", "Set the proxy server.") do |proxy|
|
159
|
+
options[:prince_http_proxy] = proxy
|
160
|
+
end
|
161
|
+
|
162
|
+
opts.on("--prince-javascript", "Enable PrinceXML JavaScript parsing. Defaults to false.") do |prince_javascript|
|
163
|
+
options[:prince_javascript] = prince_javascript
|
164
|
+
end
|
165
|
+
|
166
|
+
opts.on("--prince-media MEDIA", "Create this with a specific CSS media selector. Defaults to print.") do |prince_media|
|
167
|
+
options[:prince_media] = prince_media.to_s
|
168
|
+
end
|
169
|
+
|
170
|
+
opts.on("--prince-profile PROFILE", "Set the PDF Profile. PDF/A-1b PDF/X-3:2003 PDF/X-4") do |prince_profile|
|
171
|
+
options[:prince_profile] = prince_profile.to_s
|
172
|
+
end
|
173
|
+
|
174
|
+
opts.on("--prince-debug", "Enable PrinceXML debug logging.") do |prince_debug|
|
175
|
+
options[:prince_debug] = prince_debug
|
176
|
+
end
|
177
|
+
|
178
|
+
opts.on("--prince-version VERSION", "Create this with a specific PrinceXML version. Defaults to user setting.") do |prince_version|
|
179
|
+
options[:prince_version] = prince_version.to_s
|
180
|
+
end
|
181
|
+
|
182
|
+
opts.on("--prince-no-embed-fonts", "Disable font embelistiteming in PDF output.") do |no_embed_fonts|
|
183
|
+
options[:no_embed_fonts] = no_embed_fonts
|
184
|
+
end
|
185
|
+
|
186
|
+
opts.on("--prince-no-subset-fonts", "Disable font subsetting in PDF output.") do |no_subset_fonts|
|
187
|
+
options[:no_subset_fonts] = no_subset_fonts
|
188
|
+
end
|
189
|
+
|
190
|
+
opts.separator ""
|
191
|
+
opts.separator "Script options:"
|
192
|
+
|
193
|
+
opts.on("-o", "--[no-]open", "Automatically open output files. Defaults to true.") do |open|
|
194
|
+
options[:open] = open
|
195
|
+
end
|
196
|
+
|
197
|
+
opts.separator ""
|
198
|
+
opts.separator "Common options:"
|
199
|
+
|
200
|
+
opts.on("-c", "--common", "Set common development options: open, test, javascript enabled") do
|
201
|
+
options[:open] = true
|
202
|
+
options[:test] = true
|
203
|
+
options[:javascript] = true
|
204
|
+
end
|
205
|
+
|
206
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
207
|
+
log opts
|
208
|
+
exit
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
opt_parser.parse!(ARGV)
|
213
|
+
|
214
|
+
file_or_url = ARGV.shift
|
215
|
+
|
216
|
+
if !file_or_url
|
217
|
+
log opt_parser
|
218
|
+
abort
|
219
|
+
end
|
220
|
+
|
221
|
+
DocRaptor.configure do |dr|
|
222
|
+
dr.username = options[:key]
|
223
|
+
server = URI.parse(options[:server])
|
224
|
+
dr.host = "#{server.host}:#{server.port}"
|
225
|
+
dr.scheme = server.scheme
|
226
|
+
dr.debugging = options[:debug]
|
227
|
+
end
|
228
|
+
|
229
|
+
$docraptor = DocRaptor::DocApi.new
|
230
|
+
|
231
|
+
all_doc_attributes = {
|
232
|
+
strict: options[:strict],
|
233
|
+
test: options[:test],
|
234
|
+
javascript: options[:javascript],
|
235
|
+
document_type: options[:type],
|
236
|
+
prince_options: {},
|
237
|
+
async: options[:async],
|
238
|
+
ignore_resource_errors: options[:ignore_resource_errors],
|
239
|
+
}
|
240
|
+
|
241
|
+
all_doc_attributes[:prince_options][:version] = options[:prince_version] if options[:prince_version]
|
242
|
+
all_doc_attributes[:prince_options][:javascript] = options[:prince_javascript] if options[:prince_javascript]
|
243
|
+
all_doc_attributes[:prince_options][:media] = options[:prince_media] if options[:prince_media]
|
244
|
+
all_doc_attributes[:prince_options][:baseurl] = options[:prince_baseurl] if options[:prince_baseurl]
|
245
|
+
all_doc_attributes[:prince_options][:css_dpi] = options[:prince_css_dpi] if options[:prince_css_dpi]
|
246
|
+
all_doc_attributes[:prince_options][:disallow_annotate] = options[:prince_disallow_annotate] if options[:prince_disallow_annotate]
|
247
|
+
all_doc_attributes[:prince_options][:disallow_copy] = options[:prince_disallow_copy] if options[:prince_disallow_copy]
|
248
|
+
all_doc_attributes[:prince_options][:disallow_modify] = options[:prince_disallow_modify] if options[:prince_disallow_modify]
|
249
|
+
all_doc_attributes[:prince_options][:disallow_print]= options[:prince_disallow_print] if options[:prince_disallow_print]
|
250
|
+
all_doc_attributes[:prince_options][:encrypt] = options[:prince_encrypt] if options[:prince_encrypt]
|
251
|
+
all_doc_attributes[:prince_options][:key_bits] = options[:prince_key_bits] if options[:prince_key_bits]
|
252
|
+
all_doc_attributes[:prince_options][:input] = options[:prince_input] if options[:prince_input]
|
253
|
+
all_doc_attributes[:prince_options][:no_compress] = options[:prince_no_compress] if options[:prince_no_compress]
|
254
|
+
all_doc_attributes[:prince_options][:user_password] = options[:prince_user_password] if options[:prince_user_password]
|
255
|
+
all_doc_attributes[:prince_options][:owner_password]= options[:prince_owner_password] if options[:prince_owner_password]
|
256
|
+
all_doc_attributes[:prince_options][:http_user] = options[:prince_http_user] if options[:prince_http_user]
|
257
|
+
all_doc_attributes[:prince_options][:http_password] = options[:prince_http_password] if options[:prince_http_password]
|
258
|
+
all_doc_attributes[:prince_options][:http_proxy] = options[:prince_http_proxy] if options[:prince_http_proxy]
|
259
|
+
all_doc_attributes[:prince_options][:http_timeout] = options[:prince_http_timeout] if options[:prince_http_timeout]
|
260
|
+
all_doc_attributes[:prince_options][:insecure] = options[:prince_insecure] if options[:prince_insecure]
|
261
|
+
all_doc_attributes[:prince_options][:debug] = options[:prince_debug] if options[:prince_debug]
|
262
|
+
all_doc_attributes[:prince_options][:profile] = options[:prince_profile] if options[:prince_profile]
|
263
|
+
all_doc_attributes[:prince_options][:no_embed_fonts] = options[:no_embed_fonts] if options[:no_embed_fonts]
|
264
|
+
all_doc_attributes[:prince_options][:no_subset_fonts] = options[:no_subset_fonts] if options[:no_subset_fonts]
|
265
|
+
|
266
|
+
if file_or_url.include?("://")
|
267
|
+
url = file_or_url
|
268
|
+
all_doc_attributes[:document_url] = url
|
269
|
+
all_doc_attributes[:referrer] = options[:referrer] || url
|
270
|
+
all_doc_attributes[:prince_options][:baseurl] ||= url
|
271
|
+
else
|
272
|
+
input_filename = file_or_url
|
273
|
+
all_doc_attributes[:referrer] = options[:referrer] || "http://localhost/"
|
274
|
+
all_doc_attributes[:document_content] = File.read(input_filename)
|
275
|
+
end
|
276
|
+
|
277
|
+
all_doc_attributes.delete(:prince_options) if all_doc_attributes[:prince_options].empty?
|
278
|
+
|
279
|
+
base_filename = rand(10**12).to_s(36) # random to make Preview refresh every time with ease
|
280
|
+
|
281
|
+
def run_doc(options, all_doc_attributes, base_filename)
|
282
|
+
output_filename = "/tmp/#{base_filename}.#{options[:type]}"
|
283
|
+
|
284
|
+
doc_attributes = all_doc_attributes.merge(name: options[:name] || File.basename(output_filename))
|
285
|
+
|
286
|
+
log "Creating document #{doc_attributes[:name]} using #{options[:server]}"
|
287
|
+
pretty_doc_attributes = doc_attributes.dup
|
288
|
+
pretty_doc_attributes[:document_content] = pretty_doc_attributes[:document_content][0..30] + "..." if pretty_doc_attributes.include?(:document_content)
|
289
|
+
start = Time.now
|
290
|
+
|
291
|
+
if options[:async]
|
292
|
+
response = $docraptor.create_async_doc(doc_attributes)
|
293
|
+
status_id = response.status_id
|
294
|
+
t = Time.now.to_f
|
295
|
+
time_of_last_status_message = Time.now - PRINT_STATUS_EVERY
|
296
|
+
while !%w{completed failed}.include?((status_response = $docraptor.get_async_doc_status(status_id)).status)
|
297
|
+
if Time.now - time_of_last_status_message > PRINT_STATUS_EVERY
|
298
|
+
log "STATUS (#{status_id}, elapsed time: #{(Time.now.to_f - t).round(3)} sec): #{status_response.status.inspect}"
|
299
|
+
time_of_last_status_message = Time.now
|
300
|
+
end
|
301
|
+
sleep 1
|
302
|
+
end
|
303
|
+
log "Elapsed time: #{(Time.now.to_f - t).round(3)} secs"
|
304
|
+
if status_response.status == 'completed'
|
305
|
+
download_response = $docraptor.get_async_doc(status_response.download_id)
|
306
|
+
File.open(output_filename, "wb") do |file|
|
307
|
+
file.write(download_response)
|
308
|
+
end
|
309
|
+
system("open", output_filename) if options[:open]
|
310
|
+
else
|
311
|
+
log "Document failed: #{status_response.inspect}"
|
312
|
+
failures << [status_response, {status_id: status_id, name: doc_attributes[:name]}]
|
313
|
+
end
|
314
|
+
else
|
315
|
+
response = $docraptor.create_doc(doc_attributes)
|
316
|
+
log " Success (%.3f seconds)" % (Time.now - start)
|
317
|
+
File.open(output_filename, "wb") do |file|
|
318
|
+
file.write(response)
|
319
|
+
end
|
320
|
+
system("open", output_filename) if options[:open]
|
321
|
+
end
|
322
|
+
rescue DocRaptor::ApiError => e
|
323
|
+
log "ERROR: #{e.class}"
|
324
|
+
log e.response_body
|
325
|
+
exit 1
|
326
|
+
end
|
327
|
+
|
328
|
+
run_doc(options, all_doc_attributes, base_filename)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "docraptor-cli/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "docraptor-cli"
|
6
|
+
s.version = DocRaptorCli::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Elijah Miller"]
|
9
|
+
s.email = ["elijah.miller@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/docraptor/docraptor-cli"
|
11
|
+
s.summary = %q{Command line interface for the DocRaptor HTML to PDF/XLS service.}
|
12
|
+
s.description = %q{A native command line client library for the DocRaptor HTML to PDF/XLS service.}
|
13
|
+
s.license = "MIT"
|
14
|
+
|
15
|
+
s.add_runtime_dependency 'docraptor', '~> 0.3.0'
|
16
|
+
|
17
|
+
s.add_development_dependency 'pry', '~> 0.10', '>= 0.10.3'
|
18
|
+
s.add_development_dependency 'rake', '~> 11.1', '>= 11.1.2'
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n").uniq.sort.select{|f| !f.empty? }
|
21
|
+
# s.test_files = `git ls-files spec`.split("\n")
|
22
|
+
s.executables = []
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
end
|
data/script/test
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
set -e
|
3
|
+
cd "$(dirname "$0")/.."
|
4
|
+
|
5
|
+
# check dependencies
|
6
|
+
ruby -v > /dev/null || (echo "ruby must be installed"; exit 1)
|
7
|
+
bundler -v > /dev/null || (echo "bundler must be installed"; exit 1)
|
8
|
+
|
9
|
+
bundle install
|
10
|
+
|
11
|
+
echo "Testing not yet written for this repository."
|
12
|
+
exit 1
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: docraptor-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Elijah Miller
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: docraptor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.3.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.3.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.10'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 0.10.3
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0.10'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.10.3
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '11.1'
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 11.1.2
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '11.1'
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 11.1.2
|
67
|
+
description: A native command line client library for the DocRaptor HTML to PDF/XLS
|
68
|
+
service.
|
69
|
+
email:
|
70
|
+
- elijah.miller@gmail.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- ".gitignore"
|
76
|
+
- CHANGELOG.md
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- bin/docraptor
|
82
|
+
- docraptor-cli.gemspec
|
83
|
+
- lib/docraptor-cli/version.rb
|
84
|
+
- script/test
|
85
|
+
homepage: https://github.com/docraptor/docraptor-cli
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.5.1
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Command line interface for the DocRaptor HTML to PDF/XLS service.
|
109
|
+
test_files: []
|