Ruby
Official Ruby SDK for TemplateFox.
Installation
Add to your Gemfile:
gem 'templatefox'Then run:
bundle installOr install directly:
gem install templatefoxGenerate 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}"
endSave 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) }
endError Handling
begin
response = api.create_pdf(request)
rescue TemplateFox::ApiError => e
puts "Status: #{e.code}"
puts "Message: #{e.response_body}"
endAvailable Methods
The SDK covers all TemplateFox API endpoints through four service classes:
| Class | Method | Description |
|---|---|---|
PDFApi | create_pdf | Generate a PDF from a template |
TemplatesApi | list_templates | List all templates in your team |
TemplatesApi | get_template_fields | Get data fields for a template |
AccountApi | get_account | Get account info and credit balance |
AccountApi | list_transactions | List credit transaction history |
IntegrationsApi | save_s3_config | Configure S3 storage integration |
IntegrationsApi | get_s3_config | Get current S3 configuration |
IntegrationsApi | delete_s3_config | Remove S3 configuration |
IntegrationsApi | test_s3_connection | Test S3 bucket connectivity |
Configuration
TemplateFox.configure do |config|
config.api_key['ApiKeyAuth'] = ENV['TEMPLATEFOX_API_KEY']
endQuick 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