Skip to Content

Ruby

Official Ruby SDK for TemplateFox.

Gem Version GitHub Repository 

Installation

Add to your Gemfile:

gem 'templatefox'

Then run:

bundle install

Or install directly:

gem install templatefox

Generate a PDF

require 'templatefox' # Initialize the client TemplateFox.configure do |config| config.api_key['ApiKeyAuth'] = 'your-api-key' end api = TemplateFox::PDFApi.new # Generate a PDF request = TemplateFox::CreatePdfRequest.new( template_id: 'YOUR_TEMPLATE_ID', data: { name: 'John Doe', invoice_number: 'INV-001', total_amount: 150.00 } ) begin response = api.create_pdf(request) puts "PDF URL: #{response.url}" puts "Credits remaining: #{response.credits_remaining}" rescue TemplateFox::ApiError => e puts "Error: #{e.message}" end

Save PDF to File

require 'open-uri' response = api.create_pdf(request) # Download and save locally URI.open(response.url) do |pdf| File.open('invoice.pdf', 'wb') { |file| file.write(pdf.read) } end

Error Handling

begin response = api.create_pdf(request) rescue TemplateFox::ApiError => e puts "Status: #{e.code}" puts "Message: #{e.response_body}" end

Available Methods

The SDK covers all TemplateFox API endpoints through four service classes:

ClassMethodDescription
PDFApicreate_pdfGenerate a PDF from a template
TemplatesApilist_templatesList all templates in your team
TemplatesApiget_template_fieldsGet data fields for a template
AccountApiget_accountGet account info and credit balance
AccountApilist_transactionsList credit transaction history
IntegrationsApisave_s3_configConfigure S3 storage integration
IntegrationsApiget_s3_configGet current S3 configuration
IntegrationsApidelete_s3_configRemove S3 configuration
IntegrationsApitest_s3_connectionTest S3 bucket connectivity

Configuration

TemplateFox.configure do |config| config.api_key['ApiKeyAuth'] = ENV['TEMPLATEFOX_API_KEY'] end

Quick Testing

Want to test the API before integrating the SDK? Use our Postman collection  to try all endpoints interactively.

Full SDK Reference

For the complete API coverage including templates, account, S3 integration, and error handling, see the GitHub repository README .

Last updated on