pdfmonkey 0.3.0 → 0.7.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 +4 -4
- data/.travis.yml +19 -7
- data/CHANGELOG.md +20 -0
- data/Gemfile.lock +6 -6
- data/README.md +89 -4
- data/Rakefile +16 -2
- data/lib/pdfmonkey/adapter.rb +13 -6
- data/lib/pdfmonkey/configuration.rb +2 -0
- data/lib/pdfmonkey/document.rb +20 -3
- 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: 0e3a3403ab1a990afe5d3a7ef306b21c03bfba1d49cd5c668a9700dd0e9bc882
|
4
|
+
data.tar.gz: f8db2ef91cc4335ded29af594b690614d58c1228e066d231e0d39626ee73c41f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 165b35b6d11bcf094b9bd95a24a642c19e5b74a8988c03368c77bfca8feddfffff0435eb19e80e0f13aa155790eaf2168d240f58954c4b9406369647a849f185
|
7
|
+
data.tar.gz: ab2b6ba2f1218bd8ffa636fbe89c7f9eea3996740c6fc5a4ec1e8fb2d00dcbbb3b090fd8e74e180c8d39755d6cd22c1b76677128a81c1566c1c0e7694db93d28
|
data/.travis.yml
CHANGED
@@ -1,11 +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
|
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=
|
5
17
|
|
6
18
|
rvm:
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
19
|
+
- ruby-head
|
20
|
+
- 2.6
|
21
|
+
- 2.5
|
22
|
+
- 2.4
|
23
|
+
- jruby-head
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.7.0
|
4
|
+
|
5
|
+
* Updating bundler to v2.2
|
6
|
+
* Adding `failure_cause`, `generation_logs` and `public_share_link` to the `Document` class
|
7
|
+
|
8
|
+
## 0.6.0
|
9
|
+
|
10
|
+
* Making the request `User-Agent` header configurable
|
11
|
+
|
12
|
+
## 0.5.0
|
13
|
+
|
14
|
+
* Adding `Document#filename`
|
15
|
+
* Adding `Document.delete` and `Document#delete!`
|
16
|
+
|
17
|
+
## 0.4.0
|
18
|
+
|
19
|
+
* Adding meta to `Document.generate!` and `Document.generate`
|
20
|
+
* Fixing the errors extraction to conform to the current API format
|
21
|
+
* Adding `Document.fetch` to retrieve a document
|
22
|
+
|
3
23
|
## 0.3.0
|
4
24
|
|
5
25
|
* Adding `Document#done?` to check if a document is complete
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pdfmonkey (0.
|
4
|
+
pdfmonkey (0.7.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -16,13 +16,13 @@ GEM
|
|
16
16
|
diff-lcs (1.3)
|
17
17
|
docile (1.3.1)
|
18
18
|
jaro_winkler (1.5.2)
|
19
|
-
json (2.1
|
19
|
+
json (2.3.1)
|
20
20
|
parallel (1.12.1)
|
21
21
|
parser (2.5.3.0)
|
22
22
|
ast (~> 2.4.0)
|
23
23
|
powerpack (0.1.2)
|
24
24
|
rainbow (3.0.0)
|
25
|
-
rake (
|
25
|
+
rake (13.0.1)
|
26
26
|
rspec (3.8.0)
|
27
27
|
rspec-core (~> 3.8.0)
|
28
28
|
rspec-expectations (~> 3.8.0)
|
@@ -60,12 +60,12 @@ PLATFORMS
|
|
60
60
|
ruby
|
61
61
|
|
62
62
|
DEPENDENCIES
|
63
|
-
bundler (~>
|
63
|
+
bundler (~> 2.2)
|
64
64
|
coveralls (~> 0.8)
|
65
65
|
pdfmonkey!
|
66
|
-
rake (~>
|
66
|
+
rake (~> 13.0)
|
67
67
|
rspec (~> 3.8)
|
68
68
|
rubocop (~> 0.60.0)
|
69
69
|
|
70
70
|
BUNDLED WITH
|
71
|
-
|
71
|
+
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\"}",
|
@@ -104,6 +105,27 @@ curl <url of your app> \
|
|
104
105
|
}'
|
105
106
|
```
|
106
107
|
|
108
|
+
#### Attaching meta data to the document
|
109
|
+
|
110
|
+
In addition to the Document’s payload you can add meta data when generating a Document.
|
111
|
+
|
112
|
+
This can be done by passing a third argument to the `generate!` and `generate` methods:
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
meta = {
|
116
|
+
_filename: 'john-doe-contract.pdf',
|
117
|
+
client_id: '123xxx123'
|
118
|
+
}
|
119
|
+
|
120
|
+
document = Pdfmonkey::Document.generate!(template_id, payload, meta)
|
121
|
+
document.meta
|
122
|
+
# => '{"_filename":"john-doe-contract.pdf","client_id":"123xxx123"}'
|
123
|
+
|
124
|
+
document = Pdfmonkey::Document.generate(template_id, payload, meta)
|
125
|
+
document.meta
|
126
|
+
# => '{"_filename":"john-doe-contract.pdf","client_id":"123xxx123"}'
|
127
|
+
```
|
128
|
+
|
107
129
|
#### Error handling
|
108
130
|
|
109
131
|
In case of error, be it an HTTP layer error or an API error, `document.status` will be set to `'error'` and `document.error` will contain the error message.
|
@@ -111,13 +133,13 @@ In case of error, be it an HTTP layer error or an API error, `document.status` w
|
|
111
133
|
```ruby
|
112
134
|
# Using an unknown template
|
113
135
|
|
114
|
-
|
136
|
+
template_id = 'unknown'
|
115
137
|
data = { name: 'John Doe' }
|
116
138
|
|
117
139
|
document = Pdfmonkey::Document.generate(template_id, data)
|
118
140
|
|
119
141
|
document.status # => 'error'
|
120
|
-
document.errors # => ["
|
142
|
+
document.errors # => ["Document template must exist"]
|
121
143
|
|
122
144
|
# If the network is down
|
123
145
|
document = Pdfmonkey::Document.generate(template_id, data)
|
@@ -126,6 +148,69 @@ document.status # => 'error'
|
|
126
148
|
document.errors # => ["Failed to open TCP connection to api.pdfmonkey.io:443 (getaddrinfo: nodename nor servname provided, or not known)"]
|
127
149
|
```
|
128
150
|
|
151
|
+
### Fetching a document
|
152
|
+
|
153
|
+
You can fetch an existing document using the `.fetch` method:
|
154
|
+
|
155
|
+
```ruby
|
156
|
+
document = Pdfmonkey::Document.fetch('76bebeb9-9eb1-481a-bc3c-faf43dc3ac81')
|
157
|
+
```
|
158
|
+
|
159
|
+
#### Error handling
|
160
|
+
|
161
|
+
In case of error, be it an HTTP layer error or an API error, `document.status` will be set to `'error'` and `document.error` will contain the error message.
|
162
|
+
|
163
|
+
```ruby
|
164
|
+
document = Pdfmonkey::Document.fetch('unknown')
|
165
|
+
|
166
|
+
document.status # => 'error'
|
167
|
+
document.errors # => ["We couldn't find any Document with ID \"unknown\"..."]
|
168
|
+
|
169
|
+
# If the network is down
|
170
|
+
document = Pdfmonkey::Document.fetch('95eb0b6e-090b-4195-9b7c-cc3d50099867')
|
171
|
+
|
172
|
+
document.status # => 'error'
|
173
|
+
document.errors # => ["Failed to open TCP connection to api.pdfmonkey.io:443 (getaddrinfo: nodename nor servname provided, or not known)"]
|
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
|
+
|
129
214
|
## Development
|
130
215
|
|
131
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,13 +41,16 @@ module Pdfmonkey
|
|
37
41
|
|
38
42
|
private def extract_errors(response)
|
39
43
|
payload = JSON.parse(response.body)
|
40
|
-
|
44
|
+
errors = payload['errors'].to_a.map { |error| error['detail'] }
|
45
|
+
|
46
|
+
{ errors: errors, status: 'error' }
|
41
47
|
end
|
42
48
|
|
43
49
|
private def headers
|
44
50
|
{
|
45
51
|
'Authorization' => "Bearer #{config.private_key}",
|
46
|
-
'Content-Type' => 'application/json'
|
52
|
+
'Content-Type' => 'application/json',
|
53
|
+
'User-Agent' => config.user_agent
|
47
54
|
}
|
48
55
|
end
|
49
56
|
|
@@ -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,15 +34,24 @@ module Pdfmonkey
|
|
30
34
|
attr_reader :attributes
|
31
35
|
def_delegators :attributes, *ATTRIBUTES
|
32
36
|
|
33
|
-
def self.
|
34
|
-
|
37
|
+
def self.delete(document_id)
|
38
|
+
new(id: document_id).delete!
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.fetch(document_id)
|
42
|
+
new(id: document_id).reload!
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.generate!(document_template_id, payload, meta = {})
|
46
|
+
document = generate(document_template_id, payload, meta)
|
35
47
|
document.reload! until document.done?
|
36
48
|
document
|
37
49
|
end
|
38
50
|
|
39
|
-
def self.generate(template_id, payload)
|
51
|
+
def self.generate(template_id, payload, meta = {})
|
40
52
|
document = new(
|
41
53
|
document_template_id: template_id,
|
54
|
+
meta: meta.to_json,
|
42
55
|
payload: payload.to_json,
|
43
56
|
status: 'pending')
|
44
57
|
|
@@ -51,6 +64,10 @@ module Pdfmonkey
|
|
51
64
|
update(attributes)
|
52
65
|
end
|
53
66
|
|
67
|
+
def delete!
|
68
|
+
adapter.call(:delete, self)
|
69
|
+
end
|
70
|
+
|
54
71
|
def done?
|
55
72
|
COMPLETE_STATUSES.include?(status)
|
56
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.7.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-02 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: []
|