Sha256: 37cdbc2e6c34a1633682aab7dd6f3c21dde19ac982be3b2d6b79d2507e2e3dbe

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

#!/usr/bin/env ruby
#
# This example demonstrates generating a PDF from a preconfigured template,
# and downloading the PDF to a local file.
#
# You can run this example with: ./examples/generate_and_download_pdf.rb

require "bundler/setup"
Bundler.require

API_TOKEN_ID = 'yRaaR9JmTPtGX7EN'
API_TOKEN_SECRET = 'IB3TRkSdm4f2BdtU_D3YgxjdMB7l-r2fOgvxD1Yzwec'
TEMPLATE_ID = '6zz3dYRYM67fxMXA'

PDF_FILENAME = '/tmp/formapi-test.pdf'

begin
  FormAPI.configure do |c|
    c.username  = API_TOKEN_ID               # Your API Token ID
    c.password  = API_TOKEN_SECRET           # Your API Token Secret
    # c.debugging = true
  end

  formapi = FormAPI::Client.new

  puts "Downloading PDF to #{PDF_FILENAME}..."

  formapi.generate_and_download_pdf(
    template_id: '6zz3dYRYM67fxMXA',
    filename: PDF_FILENAME,
    data: {
      first_name: 'John',
      last_name: 'Smith',
      favorite_color: 'Blue'
    }
  )

  puts "PDF was downloaded to /tmp/formapi-test.pdf"

  # Open the PDF on Mac or Linux.
  `type xdg-open > /dev/null 2>&1 && xdg-open '#{PDF_FILENAME}' || open '#{PDF_FILENAME}'`

rescue FormAPI::ApiError => ex
  puts "#{ex.class}: #{ex.message}"
  puts ex.code          # HTTP response code
  puts ex.response_body # HTTP response body
  puts ex.backtrace[0..3].join("\n")
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
form_api-0.1.1 examples/generate_and_download_pdf.rb