pdfmonkey 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +22 -0
- data/lib/pdfmonkey/adapter.rb +13 -1
- data/lib/pdfmonkey/document.rb +6 -2
- data/lib/pdfmonkey/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b12f7afdcc1eefd026e54906aed36c86d17b467ea000e8e0b7379b567c34c5d4
|
4
|
+
data.tar.gz: f953fd4a0568f46d8aec981b72cf94eb86c6c8c9fe5d42ecfc0eddbf8cb57c38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98348f398fffbabc5ea8b480cbfe6906a1e7eb252f04eb695483688fa36ae0352731498d6eddbe23d81ed38195f82237d11f5fe5ecdfac2bd67dad5a36c8aed1
|
7
|
+
data.tar.gz: 5e123b0f7e8f645f0ba96fed50d1aa5bfa4a1e76a8827d673f701d4c065bcc2252ce8f330d8bb719c87f6b6626a59c377265a519d691fa8acdccb4eb08d19992
|
data/CHANGELOG.md
ADDED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -104,6 +104,28 @@ curl <url of your app> \
|
|
104
104
|
}'
|
105
105
|
```
|
106
106
|
|
107
|
+
#### Error handling
|
108
|
+
|
109
|
+
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.
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
# Using an unknown template
|
113
|
+
|
114
|
+
tempalte_id = 'unknown'
|
115
|
+
data = { name: 'John Doe' }
|
116
|
+
|
117
|
+
document = Pdfmonkey::Document.generate(template_id, data)
|
118
|
+
|
119
|
+
document.status # => 'error'
|
120
|
+
document.errors # => ["Couldn't find DocumentTemplate with 'id'=unknown"]
|
121
|
+
|
122
|
+
# If the network is down
|
123
|
+
document = Pdfmonkey::Document.generate(template_id, data)
|
124
|
+
|
125
|
+
document.status # => 'error'
|
126
|
+
document.errors # => ["Failed to open TCP connection to api.pdfmonkey.io:443 (getaddrinfo: nodename nor servname provided, or not known)"]
|
127
|
+
```
|
128
|
+
|
107
129
|
## Development
|
108
130
|
|
109
131
|
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
@@ -10,7 +10,14 @@ module Pdfmonkey
|
|
10
10
|
|
11
11
|
def call(method, resource)
|
12
12
|
response = send_request(method, resource)
|
13
|
-
|
13
|
+
|
14
|
+
if response.is_a?(Net::HTTPSuccess)
|
15
|
+
extract_attributes(response, resource)
|
16
|
+
else
|
17
|
+
extract_errors(response)
|
18
|
+
end
|
19
|
+
rescue StandardError => e
|
20
|
+
{ errors: [e.message], status: 'error' }
|
14
21
|
end
|
15
22
|
|
16
23
|
private def build_get_request(uri, _resource)
|
@@ -28,6 +35,11 @@ module Pdfmonkey
|
|
28
35
|
JSON.parse(response.body).fetch(member)
|
29
36
|
end
|
30
37
|
|
38
|
+
private def extract_errors(response)
|
39
|
+
payload = JSON.parse(response.body)
|
40
|
+
{ errors: payload['errors'], status: 'error' }
|
41
|
+
end
|
42
|
+
|
31
43
|
private def headers
|
32
44
|
{
|
33
45
|
'Authorization' => "Bearer #{config.private_key}",
|
data/lib/pdfmonkey/document.rb
CHANGED
@@ -14,6 +14,7 @@ module Pdfmonkey
|
|
14
14
|
created_at
|
15
15
|
document_template_id
|
16
16
|
download_url
|
17
|
+
errors
|
17
18
|
id
|
18
19
|
meta
|
19
20
|
payload
|
@@ -22,7 +23,7 @@ module Pdfmonkey
|
|
22
23
|
updated_at
|
23
24
|
].freeze
|
24
25
|
|
25
|
-
COMPLETE_STATUSES = %w[failure success].freeze
|
26
|
+
COMPLETE_STATUSES = %w[error failure success].freeze
|
26
27
|
COLLECTION = 'documents'
|
27
28
|
MEMBER = 'document'
|
28
29
|
|
@@ -57,7 +58,10 @@ module Pdfmonkey
|
|
57
58
|
end
|
58
59
|
|
59
60
|
def to_json
|
60
|
-
|
61
|
+
attrs = attributes.to_h
|
62
|
+
attrs.delete(:errors)
|
63
|
+
|
64
|
+
{ document: attrs }.to_json
|
61
65
|
end
|
62
66
|
|
63
67
|
private def save
|
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.2.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-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- ".rspec"
|
92
92
|
- ".rubocop.yml"
|
93
93
|
- ".travis.yml"
|
94
|
+
- CHANGELOG.md
|
94
95
|
- CODE_OF_CONDUCT.md
|
95
96
|
- Gemfile
|
96
97
|
- Gemfile.lock
|