pdfmonkey 0.3.0 → 0.4.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 +3 -1
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +47 -1
- data/lib/pdfmonkey/adapter.rb +3 -1
- data/lib/pdfmonkey/document.rb +8 -3
- data/lib/pdfmonkey/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f29d523ed6bb4e6c17d42092bd8962761e2379b98627b09c04b6dd13c4c65e4a
|
4
|
+
data.tar.gz: 0d167f19f5640220aadd5bae73760bb00b864e977e3a720b921b9b1d04ab6e73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd81871ef526fa6f3b30349984726bda426873a741206cd1dccc48a921ab3d6bad6278d48d80ea6ba292de49c9fb99ce0ad6cd450f04a1e83e90d01c1d0f9bb9
|
7
|
+
data.tar.gz: 349aab6b0ba114c260e72538e030e201489b15836d13b0abb8fc6fd9d577895b34f8c055f182d8c329ed3578ca40b1b9517b491bdcf2ad5b46bc139cd40ecc5e
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.4.0
|
4
|
+
|
5
|
+
* Adding meta to `Document.generate!` and `Document.generate`
|
6
|
+
* Fixing the errors extraction to conform to the current API format
|
7
|
+
* Adding `Document.fetch` to retrieve a document
|
8
|
+
|
3
9
|
## 0.3.0
|
4
10
|
|
5
11
|
* Adding `Document#done?` to check if a document is complete
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -104,6 +104,27 @@ curl <url of your app> \
|
|
104
104
|
}'
|
105
105
|
```
|
106
106
|
|
107
|
+
#### Attaching meta data to the document
|
108
|
+
|
109
|
+
In addition to the Document’s payload you can add meta data when generating a Document.
|
110
|
+
|
111
|
+
This can be done by passing a third argument to the `generate!` and `generate` methods:
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
meta = {
|
115
|
+
_filename: 'john-doe-contract.pdf',
|
116
|
+
client_id: '123xxx123'
|
117
|
+
}
|
118
|
+
|
119
|
+
document = Pdfmonkey::Document.generate!(template_id, payload, meta)
|
120
|
+
document.meta
|
121
|
+
# => '{"_filename":"john-doe-contract.pdf","client_id":"123xxx123"}'
|
122
|
+
|
123
|
+
document = Pdfmonkey::Document.generate(template_id, payload, meta)
|
124
|
+
document.meta
|
125
|
+
# => '{"_filename":"john-doe-contract.pdf","client_id":"123xxx123"}'
|
126
|
+
```
|
127
|
+
|
107
128
|
#### Error handling
|
108
129
|
|
109
130
|
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.
|
@@ -117,7 +138,7 @@ data = { name: 'John Doe' }
|
|
117
138
|
document = Pdfmonkey::Document.generate(template_id, data)
|
118
139
|
|
119
140
|
document.status # => 'error'
|
120
|
-
document.errors # => ["
|
141
|
+
document.errors # => ["Document template must exist"]
|
121
142
|
|
122
143
|
# If the network is down
|
123
144
|
document = Pdfmonkey::Document.generate(template_id, data)
|
@@ -126,6 +147,31 @@ document.status # => 'error'
|
|
126
147
|
document.errors # => ["Failed to open TCP connection to api.pdfmonkey.io:443 (getaddrinfo: nodename nor servname provided, or not known)"]
|
127
148
|
```
|
128
149
|
|
150
|
+
### Fetching a document
|
151
|
+
|
152
|
+
You can fetch an existing document using the `.fetch` method:
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
document = Pdfmonkey::Document.fetch('76bebeb9-9eb1-481a-bc3c-faf43dc3ac81')
|
156
|
+
```
|
157
|
+
|
158
|
+
#### Error handling
|
159
|
+
|
160
|
+
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.
|
161
|
+
|
162
|
+
```ruby
|
163
|
+
document = Pdfmonkey::Document.fetch('unknown')
|
164
|
+
|
165
|
+
document.status # => 'error'
|
166
|
+
document.errors # => ["We couldn't find any Document with ID \"unknown\"..."]
|
167
|
+
|
168
|
+
# If the network is down
|
169
|
+
document = Pdfmonkey::Document.fetch('95eb0b6e-090b-4195-9b7c-cc3d50099867')
|
170
|
+
|
171
|
+
document.status # => 'error'
|
172
|
+
document.errors # => ["Failed to open TCP connection to api.pdfmonkey.io:443 (getaddrinfo: nodename nor servname provided, or not known)"]
|
173
|
+
```
|
174
|
+
|
129
175
|
## Development
|
130
176
|
|
131
177
|
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/lib/pdfmonkey/adapter.rb
CHANGED
@@ -37,7 +37,9 @@ module Pdfmonkey
|
|
37
37
|
|
38
38
|
private def extract_errors(response)
|
39
39
|
payload = JSON.parse(response.body)
|
40
|
-
|
40
|
+
errors = payload['errors'].to_a.map { |error| error['detail'] }
|
41
|
+
|
42
|
+
{ errors: errors, status: 'error' }
|
41
43
|
end
|
42
44
|
|
43
45
|
private def headers
|
data/lib/pdfmonkey/document.rb
CHANGED
@@ -30,15 +30,20 @@ module Pdfmonkey
|
|
30
30
|
attr_reader :attributes
|
31
31
|
def_delegators :attributes, *ATTRIBUTES
|
32
32
|
|
33
|
-
def self.
|
34
|
-
|
33
|
+
def self.fetch(document_id)
|
34
|
+
new(id: document_id).reload!
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.generate!(document_template_id, payload, meta = {})
|
38
|
+
document = generate(document_template_id, payload, meta)
|
35
39
|
document.reload! until document.done?
|
36
40
|
document
|
37
41
|
end
|
38
42
|
|
39
|
-
def self.generate(template_id, payload)
|
43
|
+
def self.generate(template_id, payload, meta = {})
|
40
44
|
document = new(
|
41
45
|
document_template_id: template_id,
|
46
|
+
meta: meta.to_json,
|
42
47
|
payload: payload.to_json,
|
43
48
|
status: 'pending')
|
44
49
|
|
data/lib/pdfmonkey/version.rb
CHANGED
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.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Courtois
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|