Sha256: c59640b19af41ecf26a651beda27a087c829071d969aee837966beaba3168175

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

#!/usr/bin/env ruby
#
# This example demonstrates generating a PDF from a preconfigured template,
# and NOT waiting for the PDF to be processed.
#
# You can run this example with: ./examples/generate_pdf.rb

require "bundler/setup"
Bundler.require

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

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 "Generating PDF, but not waiting for job to finish processing..."

  response = formapi.generate_pdf(
    template_id: TEMPLATE_ID,
    wait: false,
    data: {
      first_name: 'John',
      last_name: 'Smith',
      favorite_color: 'Blue'
    }
  )

  puts "PDF job was submitted:"
  puts response

  submission = response.submission
  while submission.state == 'pending'
    sleep 1
    submission = formapi.get_submission(response.submission.id)
  end

  puts "PDF finished processing:"
  puts submission


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_pdf_no_wait.rb