Ruby SDK
We provide a Ruby SDK to connect to PDFMonkey. This gem is the quickest way to use our API with Ruby.
Github: https://github.com/pdfmonkey/pdfmonkey-ruby
Installation
Add this line to your application’s Gemfile:
gem 'pdfmonkey'And then execute:
$ bundleOr install it yourself as:
$ gem install pdfmonkeyUsage
Setting up authentication
Using the default environment variables
PDFMonkey will look for the PDFMONKEY_PRIVATE_KEY environment variable. This variable should contain your private key obtained at https://dashboard.pdfmonkey.io/account.
PDFMONKEY_PRIVATE_KEY=j39ckj4…Setting credentials manually
You can choose to set up your credentials explicitely in your application:
Generating a document
Once your App is created in the PDFMonkey Dashboard, create a Document Template and add the content you want to use. Every Document Template has a unique identifier (UUID), get your template’s identifier. Your ready to generate a Document.
Synchronous generation
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.
The Download URL is temporary
The download URL of a document is only valid for 1 hour. Passed this delay, reload the document to obtain a new one by calling document.reload!
Asynchronous generation
PDFMonkey was created with an asynchronous workflow in mind. It provides webhooks to inform you of a Document’s generation success.
To leverage this behavior and continue working while your Document is generated, use the generate method:
If you have a webhook URL set up it will be called with you document once the generation is complete. You can simulate it for testing with the following cURL command:
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:
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.
Fetching a document
You can fetch an existing document using the .fetch method:
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.
Deleting a document
You can delete an existing document using the .delete method:
Alternatively you can call the #delete! method:
Error handling
In case of error, be it an HTTP layer error or an API error, an error Hash will be returned.
Last updated
Was this helpful?
