README.md in pdfmonkey-0.3.0 vs README.md in pdfmonkey-0.4.0
- old
+ new
@@ -102,10 +102,31 @@
"updated_at": "2020-01-02T03:04:15.000+01:00"
}
}'
```
+#### Attaching meta data to the document
+
+In addition to the Document’s payload you can add meta data when generating a Document.
+
+This can be done by passing a third argument to the `generate!` and `generate` methods:
+
+```ruby
+meta = {
+ _filename: 'john-doe-contract.pdf',
+ client_id: '123xxx123'
+}
+
+document = Pdfmonkey::Document.generate!(template_id, payload, meta)
+document.meta
+# => '{"_filename":"john-doe-contract.pdf","client_id":"123xxx123"}'
+
+document = Pdfmonkey::Document.generate(template_id, payload, meta)
+document.meta
+# => '{"_filename":"john-doe-contract.pdf","client_id":"123xxx123"}'
+```
+
#### Error handling
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.
```ruby
@@ -115,13 +136,38 @@
data = { name: 'John Doe' }
document = Pdfmonkey::Document.generate(template_id, data)
document.status # => 'error'
-document.errors # => ["Couldn't find DocumentTemplate with 'id'=unknown"]
+document.errors # => ["Document template must exist"]
# If the network is down
document = Pdfmonkey::Document.generate(template_id, data)
+
+document.status # => 'error'
+document.errors # => ["Failed to open TCP connection to api.pdfmonkey.io:443 (getaddrinfo: nodename nor servname provided, or not known)"]
+```
+
+### Fetching a document
+
+You can fetch an existing document using the `.fetch` method:
+
+```ruby
+document = Pdfmonkey::Document.fetch('76bebeb9-9eb1-481a-bc3c-faf43dc3ac81')
+```
+
+#### Error handling
+
+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.
+
+```ruby
+document = Pdfmonkey::Document.fetch('unknown')
+
+document.status # => 'error'
+document.errors # => ["We couldn't find any Document with ID \"unknown\"..."]
+
+# If the network is down
+document = Pdfmonkey::Document.fetch('95eb0b6e-090b-4195-9b7c-cc3d50099867')
document.status # => 'error'
document.errors # => ["Failed to open TCP connection to api.pdfmonkey.io:443 (getaddrinfo: nodename nor servname provided, or not known)"]
```