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 89 |
# 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) validate_optional_fields!(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.
241 242 243 244 245 246 247 248 249 250 |
# File 'lib/assinafy/resources/assignment_resource.rb', line 241 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.
455 456 457 458 459 460 461 462 463 464 465 466 |
# File 'lib/assinafy/resources/assignment_resource.rb', line 455 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.
275 276 277 278 279 280 281 282 |
# File 'lib/assinafy/resources/assignment_resource.rb', line 275 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.
362 363 364 365 366 367 368 369 370 |
# File 'lib/assinafy/resources/assignment_resource.rb', line 362 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).
199 200 201 202 203 204 205 206 |
# File 'lib/assinafy/resources/assignment_resource.rb', line 199 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.
331 332 333 334 335 336 337 338 339 |
# File 'lib/assinafy/resources/assignment_resource.rb', line 331 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.
309 310 311 312 313 314 315 316 317 |
# File 'lib/assinafy/resources/assignment_resource.rb', line 309 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.
429 430 431 432 433 434 435 436 437 438 439 |
# File 'lib/assinafy/resources/assignment_resource.rb', line 429 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).
395 396 397 398 399 400 401 402 403 404 |
# File 'lib/assinafy/resources/assignment_resource.rb', line 395 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.
487 488 489 490 491 492 493 494 |
# File 'lib/assinafy/resources/assignment_resource.rb', line 487 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 |