Class: Assinafy::Resources::AssignmentResource
- Inherits:
-
BaseResource
- Object
- BaseResource
- Assinafy::Resources::AssignmentResource
- Defined in:
- lib/assinafy/resources/assignment_resource.rb,
sig/assinafy.rbs
Overview
Assignments — invitations to sign a specific document. Covers virtual (no positioned fields) and collect (positioned fields) methods, cost estimation, signer notification resends, declines, and signing.
See https://api.assinafy.com.br/v1/docs#assignment for the full documentation of these endpoints.
Constant Summary collapse
- OPTIONAL_FIELDS =
%i[message expires_at copy_receivers].freeze
- METHODS =
%w[virtual collect].freeze
- SIGN_ITEM_KEY_MAP =
{ 'item_id' => 'itemId', 'field_id' => 'fieldId', 'page_id' => 'pageId', 'value' => 'value' }.freeze
Constants inherited from BaseResource
BaseResource::AUTH_HEADERS, BaseResource::PAGINATION_HEADERS, BaseResource::PATH_SEGMENT
Class Method Summary collapse
-
.build_payload(payload, options = {}) ⇒ Hash
Normalise a flexible Ruby-side assignment payload into the body shape the API expects.
Instance Method Summary collapse
-
#create(document_id, payload) ⇒ Hash
Create an assignment for a document.
-
#decline(document_id, assignment_id, decline_reason:, signer_access_code:) ⇒ Array
Decline an assignment as a signer.
-
#estimate_cost(document_id, payload) ⇒ Hash
Estimate the credit cost of a potential assignment, without creating it.
-
#estimate_resend_cost(document_id, assignment_id, signer_id) ⇒ Hash
Estimate the credit cost of resending the notification to a signer.
-
#list(params = {}, account_id_override = nil) ⇒ Hash{Symbol=>Array,Hash}
List assignments for an account.
-
#resend_notification(document_id, assignment_id, signer_id) ⇒ Hash
Resend the assignment notification (email/WhatsApp) to a signer.
-
#reset_expiration(document_id, assignment_id, expires_at) ⇒ Hash
Update the expiration timestamp of an existing assignment.
-
#sign(document_id, assignment_id, items, signer_access_code:) ⇒ Hash
Submit signatures for an assignment as a signer.
-
#signer_document(signer_access_code:, has_accepted_terms: nil) ⇒ Hash
Fetch the document a signer is being asked to sign (signer-access-code auth).
-
#whatsapp_notifications(document_id, assignment_id) ⇒ Array<Hash>
List the WhatsApp notifications that were sent for an assignment, including the rendered template text.
Methods inherited from BaseResource
Constructor Details
This class inherits a constructor from Assinafy::Resources::BaseResource
Class Method Details
.build_payload(payload, options = {}) ⇒ Hash
The OpenAPI marks top-level signers as required, but the sandbox
accepts collect payloads that reference signer IDs only in positioned
fields. This builder preserves that live-compatible form.
Normalise a flexible Ruby-side assignment payload into the body shape the API expects. Accepts:
signers: ['id1', 'id2']— bare IDssigners: [{ id:, verification_method:, notification_methods:, step: }]- Legacy
signer_ids:/signerIds:arrays of IDs
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/assinafy/resources/assignment_resource.rb', line 73 def build_payload(payload, = {}) p = Utils.clean_params(payload).transform_keys(&:to_sym) if payload.is_a?(Hash) raise ValidationError.new('Assignment payload must be a Hash') unless p signers = extract_signer_refs(p) entries = p[:entries] method = (p[:method] || 'virtual').to_s validate_method!(method, signers, entries, p) result = { method: method } result[:signers] = signers.map { |ref| normalise_signer_ref(ref, ) } unless signers.empty? OPTIONAL_FIELDS.each { |key| result[key] = p[key] if p[key] } result[:entries] = entries if entries Utils.body_params(result) end |
Instance Method Details
#create(document_id, payload) ⇒ Hash
Create an assignment for a document. See build_payload for the
accepted shapes, including the sandbox-compatible collect form without
a top-level signers array.
218 219 220 221 222 223 224 225 226 227 |
# File 'lib/assinafy/resources/assignment_resource.rb', line 218 def create(document_id, payload) doc_id = require_id(document_id, 'Document ID') body = self.class.build_payload(payload) @logger.info("Creating assignment for document #{doc_id}") call('Failed to create assignment') do http_post("documents/#{doc_id}/assignments", body) end end |
#decline(document_id, assignment_id, decline_reason:, signer_access_code:) ⇒ Array
Decline an assignment as a signer.
432 433 434 435 436 437 438 439 440 441 442 443 |
# File 'lib/assinafy/resources/assignment_resource.rb', line 432 def decline(document_id, assignment_id, decline_reason:, signer_access_code:) doc_id = require_id(document_id, 'Document ID') asg_id = require_id(assignment_id, 'Assignment ID') reason = require_string(decline_reason, 'Decline reason') access_code = require_signer_access_code(signer_access_code) call_array('Failed to decline assignment') do http_put("documents/#{doc_id}/assignments/#{asg_id}/reject", body_params(decline_reason: reason), { signer_access_code: access_code }, workspace_auth: false) end end |
#estimate_cost(document_id, payload) ⇒ Hash
Estimate the credit cost of a potential assignment, without creating it.
Accepts the same payload as #create, but signer descriptors may omit
id. An empty descriptor ({}) defaults both methods to Email.
252 253 254 255 256 257 258 259 |
# File 'lib/assinafy/resources/assignment_resource.rb', line 252 def estimate_cost(document_id, payload) doc_id = require_id(document_id, 'Document ID') body = self.class.build_payload(payload, allow_signers_without_id: true) call('Failed to estimate assignment cost') do http_post("documents/#{doc_id}/assignments/estimate-cost", body) end end |
#estimate_resend_cost(document_id, assignment_id, signer_id) ⇒ Hash
Estimate the credit cost of resending the notification to a signer.
339 340 341 342 343 344 345 346 347 |
# File 'lib/assinafy/resources/assignment_resource.rb', line 339 def estimate_resend_cost(document_id, assignment_id, signer_id) doc_id = require_id(document_id, 'Document ID') asg_id = require_id(assignment_id, 'Assignment ID') sid = require_id(signer_id, 'Signer ID') call('Failed to estimate resend cost') do http_post("documents/#{doc_id}/assignments/#{asg_id}/signers/#{sid}/estimate-resend-cost") end end |
#list(params = {}, account_id_override = nil) ⇒ Hash{Symbol=>Array,Hash}
List assignments for an account. The API requires an account context,
supplied as the accountId query parameter — note the camelCase, which
is unusual for this otherwise snake_case API (verified live).
176 177 178 179 180 181 182 183 |
# File 'lib/assinafy/resources/assignment_resource.rb', line 176 def list(params = {}, account_id_override = nil) acc_id = account_id(account_id_override) query = require_payload(params, 'Assignment query parameters') call_list('Failed to list assignments') do http_get('assignments', query.merge(accountId: acc_id)) end end |
#resend_notification(document_id, assignment_id, signer_id) ⇒ Hash
Resend the assignment notification (email/WhatsApp) to a signer. May charge credits — use #estimate_resend_cost to preview.
308 309 310 311 312 313 314 315 316 |
# File 'lib/assinafy/resources/assignment_resource.rb', line 308 def resend_notification(document_id, assignment_id, signer_id) doc_id = require_id(document_id, 'Document ID') asg_id = require_id(assignment_id, 'Assignment ID') sid = require_id(signer_id, 'Signer ID') call('Failed to resend signer notification') do http_put("documents/#{doc_id}/assignments/#{asg_id}/signers/#{sid}/resend") end end |
#reset_expiration(document_id, assignment_id, expires_at) ⇒ Hash
Update the expiration timestamp of an existing assignment. The
expires_at body field is required by the API and accepts an explicit
nil (serialized as JSON null) to mean "no expiration". The value is
therefore sent verbatim rather than through Utils.body_params, which
would drop the nil.
286 287 288 289 290 291 292 293 294 |
# File 'lib/assinafy/resources/assignment_resource.rb', line 286 def reset_expiration(document_id, assignment_id, expires_at) doc_id = require_id(document_id, 'Document ID') asg_id = require_id(assignment_id, 'Assignment ID') call('Failed to update assignment expiration') do http_put("documents/#{doc_id}/assignments/#{asg_id}/reset-expiration", { 'expires_at' => expires_at }) end end |
#sign(document_id, assignment_id, items, signer_access_code:) ⇒ Hash
Submit signatures for an assignment as a signer.
The API uses camelCase for this body. Callers may pass snake_case
(item_id, field_id, page_id, value) — this method maps them
to the API's itemId, fieldId, pageId, value.
406 407 408 409 410 411 412 413 414 415 416 |
# File 'lib/assinafy/resources/assignment_resource.rb', line 406 def sign(document_id, assignment_id, items, signer_access_code:) doc_id = require_id(document_id, 'Document ID') asg_id = require_id(assignment_id, 'Assignment ID') body = require_array(items, 'Assignment items').map { |item| normalise_sign_item(item) } access_code = require_signer_access_code(signer_access_code) call('Failed to sign assignment') do http_post("documents/#{doc_id}/assignments/#{asg_id}", body, { signer_access_code: access_code }, workspace_auth: false) end end |
#signer_document(signer_access_code:, has_accepted_terms: nil) ⇒ Hash
Fetch the document a signer is being asked to sign (signer-access-code auth).
372 373 374 375 376 377 378 379 380 381 |
# File 'lib/assinafy/resources/assignment_resource.rb', line 372 def signer_document(signer_access_code:, has_accepted_terms: nil) access_code = require_signer_access_code(signer_access_code) accepted = has_accepted_terms.nil? ? nil : require_boolean(has_accepted_terms, 'has_accepted_terms') call('Failed to fetch signer assignment document') do http_get('sign', { signer_access_code: access_code, has_accepted_terms: accepted }, workspace_auth: false) end end |
#whatsapp_notifications(document_id, assignment_id) ⇒ Array<Hash>
List the WhatsApp notifications that were sent for an assignment, including the rendered template text.
464 465 466 467 468 469 470 471 |
# File 'lib/assinafy/resources/assignment_resource.rb', line 464 def whatsapp_notifications(document_id, assignment_id) doc_id = require_id(document_id, 'Document ID') asg_id = require_id(assignment_id, 'Assignment ID') call_array('Failed to list WhatsApp notifications') do http_get("documents/#{doc_id}/assignments/#{asg_id}/whatsapp-notifications") end end |