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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f949266c25fee699e6a0a3bde90256f2240e0b866a873034f54b9e31b7e6fa88
4
- data.tar.gz: dde8fa07bba2aa84869fd8945183b9cc82eb9b6439054eca030e541503a7e7e4
3
+ metadata.gz: f29d523ed6bb4e6c17d42092bd8962761e2379b98627b09c04b6dd13c4c65e4a
4
+ data.tar.gz: 0d167f19f5640220aadd5bae73760bb00b864e977e3a720b921b9b1d04ab6e73
5
5
  SHA512:
6
- metadata.gz: 9ef0addfc109cb571ac602b3acf2c783afd61013114e424133c6144c9f375741056421db9ccdaf8a536b6aa87a5257deca76c0152b32892add868a7c57a55752
7
- data.tar.gz: 55a890ebe8f847c8cbc0e483d55dcc72a1f7f355cb7a4b3ec66f3488376199887cf0f55ec29894880af2f77f81c2044fda67b7f66909b1d2ac73673719a39648
6
+ metadata.gz: cd81871ef526fa6f3b30349984726bda426873a741206cd1dccc48a921ab3d6bad6278d48d80ea6ba292de49c9fb99ce0ad6cd450f04a1e83e90d01c1d0f9bb9
7
+ data.tar.gz: 349aab6b0ba114c260e72538e030e201489b15836d13b0abb8fc6fd9d577895b34f8c055f182d8c329ed3578ca40b1b9517b491bdcf2ad5b46bc139cd40ecc5e
@@ -3,9 +3,11 @@ language: ruby
3
3
  before_install:
4
4
  - gem install bundler --version '~> 1.17'
5
5
 
6
+ dist: trusty
7
+
6
8
  rvm:
7
9
  - 2.6
8
10
  - 2.5
9
11
  - 2.4
10
- - rbx-3
12
+ - rbx-4
11
13
  - truffleruby
@@ -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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pdfmonkey (0.3.0)
4
+ pdfmonkey (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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 # => ["Couldn't find DocumentTemplate with 'id'=unknown"]
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.
@@ -37,7 +37,9 @@ module Pdfmonkey
37
37
 
38
38
  private def extract_errors(response)
39
39
  payload = JSON.parse(response.body)
40
- { errors: payload['errors'], status: 'error' }
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
@@ -30,15 +30,20 @@ module Pdfmonkey
30
30
  attr_reader :attributes
31
31
  def_delegators :attributes, *ATTRIBUTES
32
32
 
33
- def self.generate!(document_template_id, payload)
34
- document = generate(document_template_id, payload)
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pdfmonkey
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  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.3.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-10-07 00:00:00.000000000 Z
11
+ date: 2019-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler