Class: Assinafy::Resources::TemplateResource
- Inherits:
-
BaseResource
- Object
- BaseResource
- Assinafy::Resources::TemplateResource
- Defined in:
- lib/assinafy/resources/template_resource.rb,
sig/assinafy.rbs
Overview
Templates — reusable document blueprints with roles and field placements.
See https://api.assinafy.com.br/v1/docs#template for the documentation of the Template Object and its related endpoints.
Constant Summary
Constants inherited from BaseResource
BaseResource::AUTH_HEADERS, BaseResource::PAGINATION_HEADERS, BaseResource::PATH_SEGMENT
Instance Method Summary collapse
-
#create(source, options = {}, account_id_override = nil) ⇒ Hash
Create a template by uploading a source document.
-
#delete(template_id, account_id_override = nil) ⇒ nil
Delete a template.
-
#download_page(template_id, page_id, account_id_override = nil) ⇒ String
Download a rendered template page image as raw bytes.
-
#get(template_id, account_id_override = nil) ⇒ Hash
Fetch a template by ID.
-
#list(params = {}, account_id_override = nil) ⇒ Hash{Symbol=>Array,Hash}
List templates with pagination metadata.
-
#update(template_id, payload, account_id_override = nil) ⇒ Hash
Update a template.
Methods inherited from BaseResource
Constructor Details
This class inherits a constructor from Assinafy::Resources::BaseResource
Instance Method Details
#create(source, options = {}, account_id_override = nil) ⇒ Hash
Create a template by uploading a source document. The endpoint requires a
multipart/form-data file upload (verified live) — the template name
defaults to the uploaded file's name and an Editor role is created
automatically.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/assinafy/resources/template_resource.rb', line 117 def create(source, = {}, account_id_override = nil) acc_id = account_id(account_id_override) = require_payload(, 'Template options') buffer, file_name = read_source(source) validate_pdf_source!(buffer, file_name) # @type var payload: Hash[String | Symbol, untyped] payload = { file: file_part(buffer, file_name) } .each { |key, value| payload[key.to_s] = value unless value.nil? } call('Failed to create template') do http_post("accounts/#{acc_id}/templates", payload) end end |
#delete(template_id, account_id_override = nil) ⇒ nil
Delete a template.
180 181 182 183 184 185 186 187 |
# File 'lib/assinafy/resources/template_resource.rb', line 180 def delete(template_id, account_id_override = nil) acc_id = account_id(account_id_override) tmpl_id = require_id(template_id, 'Template ID') call_void('Failed to delete template') do http_delete("accounts/#{acc_id}/templates/#{tmpl_id}") end end |
#download_page(template_id, page_id, account_id_override = nil) ⇒ String
Download a rendered template page image as raw bytes. The page IDs come
from the Template Page Objects on #get (each carries a download_url).
207 208 209 210 211 212 213 214 215 |
# File 'lib/assinafy/resources/template_resource.rb', line 207 def download_page(template_id, page_id, account_id_override = nil) acc_id = account_id(account_id_override) tmpl_id = require_id(template_id, 'Template ID') pid = require_id(page_id, 'Page ID') call_binary('Failed to download template page') do http_get("accounts/#{acc_id}/templates/#{tmpl_id}/pages/#{pid}/download") end end |
#get(template_id, account_id_override = nil) ⇒ Hash
Fetch a template by ID.
76 77 78 79 80 81 82 83 |
# File 'lib/assinafy/resources/template_resource.rb', line 76 def get(template_id, account_id_override = nil) acc_id = account_id(account_id_override) tmpl_id = require_id(template_id, 'Template ID') call('Failed to fetch template') do http_get("accounts/#{acc_id}/templates/#{tmpl_id}") end end |
#list(params = {}, account_id_override = nil) ⇒ Hash{Symbol=>Array,Hash}
List templates with pagination metadata.
38 39 40 41 42 43 44 |
# File 'lib/assinafy/resources/template_resource.rb', line 38 def list(params = {}, account_id_override = nil) acc_id = account_id(account_id_override) call_list('Failed to list templates') do http_get("accounts/#{acc_id}/templates", params) end end |
#update(template_id, payload, account_id_override = nil) ⇒ Hash
Update a template.
155 156 157 158 159 160 161 162 163 |
# File 'lib/assinafy/resources/template_resource.rb', line 155 def update(template_id, payload, account_id_override = nil) acc_id = account_id(account_id_override) tmpl_id = require_id(template_id, 'Template ID') body = body_params(require_payload(payload, 'Template payload')) call('Failed to update template') do http_put("accounts/#{acc_id}/templates/#{tmpl_id}", body) end end |