Ruby wrapper for Docupilot API.
# Gemfile
gem "docupilot", github: "kuartz-org/docupilot"
For Rails:
# config/initializers/docupilot.rb
Docupilot.configure do |config|
config.api_key = Rails.application.credentials.docupilot[:api_key]
config.secret_key = Rails.application.credentials.docupilot[:secret_key]
end
Docupilot::Template.all
# => [#<Docupilot::Template:0x0000..>, #<Docupilot::Template:0x0000..>]
# Optional `folder_id` attribute to get all templates from a specific folder.
Docupilot::Template.all(folder_id: 42)
Warning
Without
folder_id
, this returns only templates from root.
Docupilot::Template.find(42)
# => #<Docupilot::Template:0x0000..>
template = Docupilot::Template.new(
output_file_name: "Contract n°{{contract_number}}",
folder: Docupilot::Folder.find(1),
document_status: "test",
description: "Contract template for client",
type: "docx",
title: "Contract template"
)
template.save
# => #<Docupilot::Template:0x0000..>
# or
Docupilot::Template.create(
output_file_name: "Contract n°{{contract_number}}",
folder: Docupilot::Folder.find(1),
document_status: "test",
description: "Contract template for client",
type: "docx",
title: "Contract template"
)
# => #<Docupilot::Template:0x0000..>
template = Docupilot::Template.find(42)
template.title = "New title"
template.save
# => #<Docupilot::Template:0x0000..>
# or
template.update(title: "New title")
# => #<Docupilot::Template:0x0000..>
file = File.open(Rails.root.join("tmp/sample_project_proposal.docx"))
template = Docupilot::Template.find(42)
template.upload_content(file)
# => nil
template = Docupilot::Template.find(42)
template.schema
# => [
# {:name=>"project_name", :type=>"string"},
# {:name=>"client", :type=>"object", :fields=>[{:name=>"name", :type=>"string"}, {:name=>"company", :type=>"string"}]},
# {:name=>"start_date", :type=>"string"},
# {:name=>"end_date", :type=>"string"}
# ]
attributes = {
project_name: "test 1",
client: { name: "michel", company: "acme" },
start_date: "10 juin 2022",
end_date: "12 juin 2022"
}
template = Docupilot::Template.find(42)
template.merge_document(attributes)
# => {
# :file_url=> "https://docupilot-documents.s3.amazonaws.com/temp/...",
# :file_name=>"Sample Project Proposal_2022-05-22 16_53_08.docx"
# }
Docupilot::Folder.all
# => [#<Docupilot::Folder:0x0000...>, #<Docupilot::Folder:0x0000...>]
folder = Docupilot::Folder.new(name: "dev")
folder.save
# => #<Docupilot::Folder:0x0000..>
# or
Docupilot::Folder.create(name: "dev")
# => #<Docupilot::Folder:0x0000..>