pdfmonkey 0.4.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +18 -8
- data/CHANGELOG.md +18 -0
- data/Gemfile.lock +33 -31
- data/README.md +42 -3
- data/Rakefile +16 -2
- data/lib/pdfmonkey/adapter.rb +16 -6
- data/lib/pdfmonkey/configuration.rb +2 -0
- data/lib/pdfmonkey/document.rb +12 -0
- data/lib/pdfmonkey/version.rb +1 -1
- data/pdfmonkey.gemspec +2 -2
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b013f0822a5527e71c4cdc59db5db57db55f99a211385794edee27cc7d80136
|
4
|
+
data.tar.gz: 2bd5e46799f7f211bfc113108c5a6bdcf8e6149c9d8584f7c7af907f168348cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be01b68099f078ab891f171abcdb8ad4f87db248235fe4cc1a93d5fc382a99dc097e9d72d06a3dc687be399ddd58713d01d1467fbc3c255e6ddcececc39aa517
|
7
|
+
data.tar.gz: d4f5cab8cebf933b09860df3b60829bd3b4d8a43cb316c5058125881ac46f85b5ed84cde22ed9766df71e659d84d0521df1201fa7b1dd9d55181c0122ce641b7
|
data/.travis.yml
CHANGED
@@ -1,13 +1,23 @@
|
|
1
1
|
language: ruby
|
2
2
|
|
3
|
-
before_install:
|
4
|
-
|
3
|
+
before_install: gem install bundler --version '~> 1.17'
|
4
|
+
cache: bundler
|
5
|
+
dist: bionic
|
5
6
|
|
6
|
-
|
7
|
+
matrix:
|
8
|
+
allow_failures:
|
9
|
+
- rvm: ruby-head
|
10
|
+
- rvm: jruby-head
|
11
|
+
fast_finish: true
|
12
|
+
|
13
|
+
notifications:
|
14
|
+
email: false
|
15
|
+
slack:
|
16
|
+
secure: YimzUcOW2fIo+CyYB5sBgUydS49JNtTIEowyinPAfDifAYgRNx/8c5kPk0aLk8klbnNBd8pMene/i4MIfApRuUmzAkGLe/1CCbotGn7zN7R6S46tpkGaHyMya5leiQemT6gIeL5+J4mQwDcTppXYh9kNTSYKh6RNLJxS7XUZZrNqOK6R2e/hX71aqUJTA5laSQ5mR5Hvyl9kUaJW5b77myXiU6VdrHmCl3sZ9hMqe6mroyBbVOAf1eFQMo7QX9HuLTUHJA2KIpnA7cLEXLINtnKjkhRVR0hcuGMETJhrJI/Ylqi1kf3PRPqkD/Q9msBo01OcRSoGwTjQ2IS1gOcYDowgvpJhkvx2v17fk4j1w3zR5KHSYJlrYOnr+ayU9K3LTs62X8ppVHff6pkKjOEF+p1Mayk/DqbaaH0PnCxqBqJOqZ5kFSkz6y4DDQzVuYILi6qUfgZFQJ01LNR7zbJAI6v9xDqREPG/Bfh7QI5z4eETlZWF9CVX6OARYm43to/wLLg2AEEduoMjexMoIxXRgzsTyBnxKYW3P+0oXWtiH68PXEKF9qAEl8lK4tTjbPBiEgXgUMDWQIiG0y6M567Rg8s8CUiw5ZsQTGJE+9zn4OkM/3VTce1mNLoZPyF66S5sXTPFXjieHCnMS3vegc3OJzLI/Xpx/lPDEU+8CYBaA1I=
|
7
17
|
|
8
18
|
rvm:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
19
|
+
- ruby-head
|
20
|
+
- 2.6
|
21
|
+
- 2.5
|
22
|
+
- 2.4
|
23
|
+
- jruby-head
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.8.0
|
4
|
+
|
5
|
+
* Adding support for single error responses
|
6
|
+
|
7
|
+
## 0.7.0
|
8
|
+
|
9
|
+
* Updating bundler to v2.2
|
10
|
+
* Adding `failure_cause`, `generation_logs` and `public_share_link` to the `Document` class
|
11
|
+
|
12
|
+
## 0.6.0
|
13
|
+
|
14
|
+
* Making the request `User-Agent` header configurable
|
15
|
+
|
16
|
+
## 0.5.0
|
17
|
+
|
18
|
+
* Adding `Document#filename`
|
19
|
+
* Adding `Document.delete` and `Document#delete!`
|
20
|
+
|
3
21
|
## 0.4.0
|
4
22
|
|
5
23
|
* Adding meta to `Document.generate!` and `Document.generate`
|
data/Gemfile.lock
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pdfmonkey (0.
|
4
|
+
pdfmonkey (0.8.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
ast (2.4.
|
10
|
-
coveralls (0.8.
|
9
|
+
ast (2.4.2)
|
10
|
+
coveralls (0.8.23)
|
11
11
|
json (>= 1.8, < 3)
|
12
12
|
simplecov (~> 0.16.1)
|
13
13
|
term-ansicolor (~> 1.3)
|
14
|
-
thor (
|
14
|
+
thor (>= 0.19.4, < 2.0)
|
15
15
|
tins (~> 1.6)
|
16
|
-
diff-lcs (1.
|
17
|
-
docile (1.
|
18
|
-
jaro_winkler (1.5.
|
19
|
-
json (2.1
|
20
|
-
parallel (1.
|
21
|
-
parser (
|
22
|
-
ast (~> 2.4.
|
23
|
-
powerpack (0.1.
|
16
|
+
diff-lcs (1.4.4)
|
17
|
+
docile (1.4.0)
|
18
|
+
jaro_winkler (1.5.4)
|
19
|
+
json (2.6.1)
|
20
|
+
parallel (1.21.0)
|
21
|
+
parser (3.0.2.0)
|
22
|
+
ast (~> 2.4.1)
|
23
|
+
powerpack (0.1.3)
|
24
24
|
rainbow (3.0.0)
|
25
|
-
rake (
|
26
|
-
rspec (3.
|
27
|
-
rspec-core (~> 3.
|
28
|
-
rspec-expectations (~> 3.
|
29
|
-
rspec-mocks (~> 3.
|
30
|
-
rspec-core (3.
|
31
|
-
rspec-support (~> 3.
|
32
|
-
rspec-expectations (3.
|
25
|
+
rake (13.0.6)
|
26
|
+
rspec (3.10.0)
|
27
|
+
rspec-core (~> 3.10.0)
|
28
|
+
rspec-expectations (~> 3.10.0)
|
29
|
+
rspec-mocks (~> 3.10.0)
|
30
|
+
rspec-core (3.10.1)
|
31
|
+
rspec-support (~> 3.10.0)
|
32
|
+
rspec-expectations (3.10.1)
|
33
33
|
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
-
rspec-support (~> 3.
|
35
|
-
rspec-mocks (3.
|
34
|
+
rspec-support (~> 3.10.0)
|
35
|
+
rspec-mocks (3.10.2)
|
36
36
|
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
-
rspec-support (~> 3.
|
38
|
-
rspec-support (3.
|
37
|
+
rspec-support (~> 3.10.0)
|
38
|
+
rspec-support (3.10.3)
|
39
39
|
rubocop (0.60.0)
|
40
40
|
jaro_winkler (~> 1.5.1)
|
41
41
|
parallel (~> 1.10)
|
@@ -44,28 +44,30 @@ GEM
|
|
44
44
|
rainbow (>= 2.2.2, < 4.0)
|
45
45
|
ruby-progressbar (~> 1.7)
|
46
46
|
unicode-display_width (~> 1.4.0)
|
47
|
-
ruby-progressbar (1.
|
47
|
+
ruby-progressbar (1.11.0)
|
48
48
|
simplecov (0.16.1)
|
49
49
|
docile (~> 1.1)
|
50
50
|
json (>= 1.8, < 3)
|
51
51
|
simplecov-html (~> 0.10.0)
|
52
52
|
simplecov-html (0.10.2)
|
53
|
-
|
53
|
+
sync (0.5.0)
|
54
|
+
term-ansicolor (1.7.1)
|
54
55
|
tins (~> 1.0)
|
55
|
-
thor (
|
56
|
-
tins (1.
|
56
|
+
thor (1.1.0)
|
57
|
+
tins (1.29.1)
|
58
|
+
sync
|
57
59
|
unicode-display_width (1.4.1)
|
58
60
|
|
59
61
|
PLATFORMS
|
60
62
|
ruby
|
61
63
|
|
62
64
|
DEPENDENCIES
|
63
|
-
bundler (~>
|
65
|
+
bundler (~> 2.2)
|
64
66
|
coveralls (~> 0.8)
|
65
67
|
pdfmonkey!
|
66
|
-
rake (~>
|
68
|
+
rake (~> 13.0)
|
67
69
|
rspec (~> 3.8)
|
68
70
|
rubocop (~> 0.60.0)
|
69
71
|
|
70
72
|
BUNDLED WITH
|
71
|
-
|
73
|
+
2.2.30
|
data/README.md
CHANGED
@@ -50,7 +50,7 @@ Once your App is created in the [PDFMonkey Dashboard](https://dashboard.pdfmonke
|
|
50
50
|
If your want to wait for a Document’s generation before continuing with your workflow, use the `generate!` method, it will request a document generation and wait for it to succeed or fail before giving you any answer.
|
51
51
|
|
52
52
|
```ruby
|
53
|
-
|
53
|
+
template_id = 'b13ebd75-d290-409b-9cac-8f597ae3e785'
|
54
54
|
data = { name: 'John Doe' }
|
55
55
|
|
56
56
|
document = Pdfmonkey::Document.generate!(template_id, data)
|
@@ -72,7 +72,7 @@ PDFMonkey was created with an asynchronous workflow in mind. It provides webhook
|
|
72
72
|
To leverage this behavior and continue working while your Document is generated, use the `generate` method:
|
73
73
|
|
74
74
|
```ruby
|
75
|
-
|
75
|
+
template_id = 'b13ebd75-d290-409b-9cac-8f597ae3e785'
|
76
76
|
data = { name: 'John Doe' }
|
77
77
|
|
78
78
|
document = Pdfmonkey::Document.generate(template_id, data)
|
@@ -94,6 +94,7 @@ curl <url of your app> \
|
|
94
94
|
"created_at": "2020-01-02T03:04:05.000+01:00",
|
95
95
|
"document_template_id": "f7fbe2b4-a57c-46ee-8422-5ae8cc37daac",
|
96
96
|
"download_url": "https://example.com/76bebeb9-9eb1-481a-bc3c-faf43dc3ac81.pdf",
|
97
|
+
"filename": "76bebeb9-9eb1-481a-bc3c-faf43dc3ac81.pdf",
|
97
98
|
"id": "76bebeb9-9eb1-481a-bc3c-faf43dc3ac81",
|
98
99
|
"meta": null,
|
99
100
|
"payload": "{\"name\": \"John Doe\"}",
|
@@ -132,7 +133,7 @@ In case of error, be it an HTTP layer error or an API error, `document.status` w
|
|
132
133
|
```ruby
|
133
134
|
# Using an unknown template
|
134
135
|
|
135
|
-
|
136
|
+
template_id = 'unknown'
|
136
137
|
data = { name: 'John Doe' }
|
137
138
|
|
138
139
|
document = Pdfmonkey::Document.generate(template_id, data)
|
@@ -172,6 +173,44 @@ document.status # => 'error'
|
|
172
173
|
document.errors # => ["Failed to open TCP connection to api.pdfmonkey.io:443 (getaddrinfo: nodename nor servname provided, or not known)"]
|
173
174
|
```
|
174
175
|
|
176
|
+
### Deleting a document
|
177
|
+
|
178
|
+
You can delete an existing document using the `.delete` method:
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
Pdfmonkey::Document.delete('76bebeb9-9eb1-481a-bc3c-faf43dc3ac81')
|
182
|
+
#=> true
|
183
|
+
```
|
184
|
+
|
185
|
+
Alternatively you can call the `#delete!` method:
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
document.delete!
|
189
|
+
#=> true
|
190
|
+
```
|
191
|
+
|
192
|
+
#### Error handling
|
193
|
+
|
194
|
+
In case of error, be it an HTTP layer error or an API error, an error Hash will be returned.
|
195
|
+
|
196
|
+
```ruby
|
197
|
+
document.delete!
|
198
|
+
#=> true
|
199
|
+
|
200
|
+
document.delete!
|
201
|
+
# {
|
202
|
+
# errors: ["We couldn't find any Document with ID \"11111111-2222-3333-4444-555555555555\". If ..."],
|
203
|
+
# status: "error"
|
204
|
+
# }
|
205
|
+
|
206
|
+
# If the network is down
|
207
|
+
document.delete!
|
208
|
+
# {
|
209
|
+
# errors: ["Failed to open TCP connection to api.pdfmonkey.io:443 (getaddrinfo: nodename nor servname provided, or not known)"],
|
210
|
+
# status: "error"
|
211
|
+
# }
|
212
|
+
```
|
213
|
+
|
175
214
|
## Development
|
176
215
|
|
177
216
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/Rakefile
CHANGED
@@ -1,6 +1,20 @@
|
|
1
|
-
require '
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'bundler'
|
10
|
+
Bundler::GemHelper.install_tasks
|
11
|
+
|
12
|
+
require 'rake'
|
2
13
|
require 'rspec/core/rake_task'
|
3
14
|
|
4
|
-
|
15
|
+
desc "Run all examples"
|
16
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
17
|
+
t.rspec_opts = %w[--color --require spec_helper]
|
18
|
+
end
|
5
19
|
|
6
20
|
task default: :spec
|
data/lib/pdfmonkey/adapter.rb
CHANGED
@@ -11,15 +11,19 @@ module Pdfmonkey
|
|
11
11
|
def call(method, resource)
|
12
12
|
response = send_request(method, resource)
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
case response
|
15
|
+
when Net::HTTPNoContent then true
|
16
|
+
when Net::HTTPSuccess then extract_attributes(response, resource)
|
17
|
+
else extract_errors(response)
|
18
18
|
end
|
19
19
|
rescue StandardError => e
|
20
20
|
{ errors: [e.message], status: 'error' }
|
21
21
|
end
|
22
22
|
|
23
|
+
private def build_delete_request(uri, _resource)
|
24
|
+
Net::HTTP::Delete.new(uri, headers)
|
25
|
+
end
|
26
|
+
|
23
27
|
private def build_get_request(uri, _resource)
|
24
28
|
Net::HTTP::Get.new(uri, headers)
|
25
29
|
end
|
@@ -37,7 +41,12 @@ module Pdfmonkey
|
|
37
41
|
|
38
42
|
private def extract_errors(response)
|
39
43
|
payload = JSON.parse(response.body)
|
40
|
-
errors =
|
44
|
+
errors =
|
45
|
+
if payload['error']
|
46
|
+
[payload['error']]
|
47
|
+
else
|
48
|
+
payload['errors'].to_a.map { |error| error['detail'] }
|
49
|
+
end
|
41
50
|
|
42
51
|
{ errors: errors, status: 'error' }
|
43
52
|
end
|
@@ -45,7 +54,8 @@ module Pdfmonkey
|
|
45
54
|
private def headers
|
46
55
|
{
|
47
56
|
'Authorization' => "Bearer #{config.private_key}",
|
48
|
-
'Content-Type' => 'application/json'
|
57
|
+
'Content-Type' => 'application/json',
|
58
|
+
'User-Agent' => config.user_agent
|
49
59
|
}
|
50
60
|
end
|
51
61
|
|
@@ -5,11 +5,13 @@ module Pdfmonkey
|
|
5
5
|
attr_accessor :host
|
6
6
|
attr_accessor :namespace
|
7
7
|
attr_accessor :private_key
|
8
|
+
attr_accessor :user_agent
|
8
9
|
|
9
10
|
def initialize
|
10
11
|
@host = 'https://api.pdfmonkey.io'
|
11
12
|
@namespace = 'api/v1'
|
12
13
|
@private_key = ENV['PDFMONKEY_PRIVATE_KEY']
|
14
|
+
@user_agent = 'Ruby'
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
data/lib/pdfmonkey/document.rb
CHANGED
@@ -15,10 +15,14 @@ module Pdfmonkey
|
|
15
15
|
document_template_id
|
16
16
|
download_url
|
17
17
|
errors
|
18
|
+
failure_cause
|
19
|
+
filename
|
20
|
+
generation_logs
|
18
21
|
id
|
19
22
|
meta
|
20
23
|
payload
|
21
24
|
preview_url
|
25
|
+
public_share_link
|
22
26
|
status
|
23
27
|
updated_at
|
24
28
|
].freeze
|
@@ -30,6 +34,10 @@ module Pdfmonkey
|
|
30
34
|
attr_reader :attributes
|
31
35
|
def_delegators :attributes, *ATTRIBUTES
|
32
36
|
|
37
|
+
def self.delete(document_id)
|
38
|
+
new(id: document_id).delete!
|
39
|
+
end
|
40
|
+
|
33
41
|
def self.fetch(document_id)
|
34
42
|
new(id: document_id).reload!
|
35
43
|
end
|
@@ -56,6 +64,10 @@ module Pdfmonkey
|
|
56
64
|
update(attributes)
|
57
65
|
end
|
58
66
|
|
67
|
+
def delete!
|
68
|
+
adapter.call(:delete, self)
|
69
|
+
end
|
70
|
+
|
59
71
|
def done?
|
60
72
|
COMPLETE_STATUSES.include?(status)
|
61
73
|
end
|
data/lib/pdfmonkey/version.rb
CHANGED
data/pdfmonkey.gemspec
CHANGED
@@ -22,9 +22,9 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
23
|
spec.require_paths = ['lib']
|
24
24
|
|
25
|
-
spec.add_development_dependency 'bundler', '~>
|
25
|
+
spec.add_development_dependency 'bundler', '~> 2.2'
|
26
26
|
spec.add_development_dependency 'coveralls', '~> 0.8'
|
27
|
-
spec.add_development_dependency 'rake', '~>
|
27
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
28
28
|
spec.add_development_dependency 'rspec', '~> 3.8'
|
29
29
|
spec.add_development_dependency 'rubocop', '~> 0.60.0'
|
30
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdfmonkey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Courtois
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.2'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: coveralls
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '13.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -110,7 +110,7 @@ homepage: https://github.com/pdfmonkeyio/pdfmonkey-ruby
|
|
110
110
|
licenses:
|
111
111
|
- MIT
|
112
112
|
metadata: {}
|
113
|
-
post_install_message:
|
113
|
+
post_install_message:
|
114
114
|
rdoc_options: []
|
115
115
|
require_paths:
|
116
116
|
- lib
|
@@ -125,8 +125,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
version: '0'
|
127
127
|
requirements: []
|
128
|
-
rubygems_version: 3.0.
|
129
|
-
signing_key:
|
128
|
+
rubygems_version: 3.0.3
|
129
|
+
signing_key:
|
130
130
|
specification_version: 4
|
131
131
|
summary: Connect to the PDFMonkey API
|
132
132
|
test_files: []
|