pdfmonkey 0.2.0 → 0.6.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 +21 -5
- data/CHANGELOG.md +23 -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 +22 -4
- data/lib/pdfmonkey/version.rb +1 -1
- data/pdfmonkey.gemspec +2 -2
- metadata +10 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 981628ac067f138aaf0a098ddf561f7537b3838df84d1c7b3410583b5e66fa35
|
4
|
+
data.tar.gz: 168ab9c7819b220d2e26eac8910993d7e62db504ecdae8806d0081962f60754b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3df5b9ac944318e0e47ba81cbd6aafe865e6eb00117e8646a5ea0f0068808fb24d8f3f6145beb2f7f87d9a3223b3d760f3c7d63dc42c04a5ca7498e24777b358
|
7
|
+
data.tar.gz: 0aee89379452faa4b588c258d54d7b44fb702c14d2ed6fe2efdb478fbe8dd58b6ce5a167bb93de1704fa49c51fff656e9e68a8f3b87184106c88f207425d9259
|
data/.travis.yml
CHANGED
@@ -1,7 +1,23 @@
|
|
1
1
|
language: ruby
|
2
|
+
|
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=
|
17
|
+
|
2
18
|
rvm:
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
19
|
+
- ruby-head
|
20
|
+
- 2.6
|
21
|
+
- 2.5
|
22
|
+
- 2.4
|
23
|
+
- jruby-head
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,28 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## HEAD
|
4
|
+
|
5
|
+
* Updating bundler to v2.2
|
6
|
+
|
7
|
+
## 0.6.0
|
8
|
+
|
9
|
+
* Making the request `User-Agent` header configurable
|
10
|
+
|
11
|
+
## 0.5.0
|
12
|
+
|
13
|
+
* Adding `Document#filename`
|
14
|
+
* Adding `Document.delete` and `Document#delete!`
|
15
|
+
|
16
|
+
## 0.4.0
|
17
|
+
|
18
|
+
* Adding meta to `Document.generate!` and `Document.generate`
|
19
|
+
* Fixing the errors extraction to conform to the current API format
|
20
|
+
* Adding `Document.fetch` to retrieve a document
|
21
|
+
|
22
|
+
## 0.3.0
|
23
|
+
|
24
|
+
* Adding `Document#done?` to check if a document is complete
|
25
|
+
|
3
26
|
## 0.2.0
|
4
27
|
|
5
28
|
* Handling HTTP and API errors and exposing the error messages
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pdfmonkey (0.
|
4
|
+
pdfmonkey (0.6.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,6 +15,7 @@ module Pdfmonkey
|
|
15
15
|
document_template_id
|
16
16
|
download_url
|
17
17
|
errors
|
18
|
+
filename
|
18
19
|
id
|
19
20
|
meta
|
20
21
|
payload
|
@@ -30,15 +31,24 @@ module Pdfmonkey
|
|
30
31
|
attr_reader :attributes
|
31
32
|
def_delegators :attributes, *ATTRIBUTES
|
32
33
|
|
33
|
-
def self.
|
34
|
-
|
35
|
-
|
34
|
+
def self.delete(document_id)
|
35
|
+
new(id: document_id).delete!
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.fetch(document_id)
|
39
|
+
new(id: document_id).reload!
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.generate!(document_template_id, payload, meta = {})
|
43
|
+
document = generate(document_template_id, payload, meta)
|
44
|
+
document.reload! until document.done?
|
36
45
|
document
|
37
46
|
end
|
38
47
|
|
39
|
-
def self.generate(template_id, payload)
|
48
|
+
def self.generate(template_id, payload, meta = {})
|
40
49
|
document = new(
|
41
50
|
document_template_id: template_id,
|
51
|
+
meta: meta.to_json,
|
42
52
|
payload: payload.to_json,
|
43
53
|
status: 'pending')
|
44
54
|
|
@@ -51,6 +61,14 @@ module Pdfmonkey
|
|
51
61
|
update(attributes)
|
52
62
|
end
|
53
63
|
|
64
|
+
def delete!
|
65
|
+
adapter.call(:delete, self)
|
66
|
+
end
|
67
|
+
|
68
|
+
def done?
|
69
|
+
COMPLETE_STATUSES.include?(status)
|
70
|
+
end
|
71
|
+
|
54
72
|
def reload!
|
55
73
|
attributes = adapter.call(:get, self)
|
56
74
|
update(attributes)
|
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.6.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-10-30 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,9 +125,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
version: '0'
|
127
127
|
requirements: []
|
128
|
-
|
129
|
-
|
130
|
-
signing_key:
|
128
|
+
rubygems_version: 3.0.3
|
129
|
+
signing_key:
|
131
130
|
specification_version: 4
|
132
131
|
summary: Connect to the PDFMonkey API
|
133
132
|
test_files: []
|