Class: Assinafy::Resources::SignerResource
- Inherits:
-
BaseResource
- Object
- BaseResource
- Assinafy::Resources::SignerResource
- Defined in:
- lib/assinafy/resources/signer_resource.rb,
sig/assinafy.rbs
Overview
Signer management. Covers both:
- Account-scoped CRUD on signers (authenticated as a workspace user).
- Signer self-service endpoints (authenticated via
signer-access-code).
See https://api.assinafy.com.br/v1/docs#signer for the full documentation of these endpoints.
Constant Summary collapse
- EMAIL_REGEX =
/\A[^\s@]+@[^\s@]+\.[^\s@]+\z/- SIGNATURE_TYPES =
%w[signature initial].freeze
Constants inherited from BaseResource
BaseResource::AUTH_HEADERS, BaseResource::PAGINATION_HEADERS, BaseResource::PATH_SEGMENT
Instance Method Summary collapse
-
#accept_terms(signer_access_code:) ⇒ nil
Accept the platform's terms of use as the signer.
-
#confirm_data(document_id, payload, signer_access_code:) ⇒ Hash
Confirm signer data before signing a virtual assignment.
-
#create(payload, account_id_override = nil) ⇒ Hash
Create a signer in the workspace.
-
#delete(signer_id, account_id_override = nil) ⇒ nil
Delete a signer.
-
#download_signature(signer_access_code:, type: 'signature') ⇒ String
Download the signer's signature image as raw bytes.
-
#find_by_email(email, account_id_override = nil) ⇒ Hash?
Convenience: find a signer by email using the documented
searchquery parameter, then do a case-insensitive client-side match. -
#get(signer_id, account_id_override = nil) ⇒ Hash
Fetch a signer by ID.
-
#list(params = {}, account_id_override = nil) ⇒ Hash{Symbol=>Array,Hash}
List signers in the workspace, with pagination metadata.
-
#self_data(signer_access_code:) ⇒ Hash
Fetch the authenticated signer's own profile (signer-access-code auth).
-
#update(signer_id, payload, account_id_override = nil) ⇒ Hash
Partially update a signer.
-
#upload_signature(content, signer_access_code:, type: 'signature', content_type: 'image/png', reuse: nil) ⇒ nil, Array
Upload the signer's signature image.
-
#validate_create!(payload) ⇒ Hash
Validate and normalize a payload accepted by #create without sending a request.
-
#verify_email(verification_code:, signer_access_code:) ⇒ nil
Verify the signer's email with a one-time verification code.
Methods inherited from BaseResource
Constructor Details
This class inherits a constructor from Assinafy::Resources::BaseResource
Instance Method Details
#accept_terms(signer_access_code:) ⇒ nil
Accept the platform's terms of use as the signer.
The signer-access-code is sent as the documented query parameter (the
signerAccessCode security scheme is in: query), consistent with every
other signer-authenticated endpoint. This operation has no request body.
273 274 275 276 277 278 279 |
# File 'lib/assinafy/resources/signer_resource.rb', line 273 def accept_terms(signer_access_code:) code = require_signer_access_code(signer_access_code) call('Failed to accept signer terms') do http_put('signers/accept-terms', nil, { signer_access_code: code }, workspace_auth: false) end end |
#confirm_data(document_id, payload, signer_access_code:) ⇒ Hash
Confirm signer data before signing a virtual assignment. The documented
body fields are full_name, email, and government_id; the payload is
passed through unchanged, so any additional fields the API accepts can be
supplied as well.
336 337 338 339 340 341 342 343 344 345 |
# File 'lib/assinafy/resources/signer_resource.rb', line 336 def confirm_data(document_id, payload, signer_access_code:) doc_id = require_id(document_id, 'Document ID') body = body_params(require_payload(payload)) code = require_signer_access_code(signer_access_code) call('Failed to confirm signer data') do http_put("documents/#{doc_id}/signers/confirm-data", body, { signer_access_code: code }, workspace_auth: false) end end |
#create(payload, account_id_override = nil) ⇒ Hash
Create a signer in the workspace.
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/assinafy/resources/signer_resource.rb', line 63 def create(payload, account_id_override = nil) body = validate_create!(payload) acc_id = account_id(account_id_override) @logger.info('Creating signer') call('Failed to create signer') do http_post("accounts/#{acc_id}/signers", body) end end |
#delete(signer_id, account_id_override = nil) ⇒ nil
Delete a signer.
179 180 181 182 183 184 185 186 |
# File 'lib/assinafy/resources/signer_resource.rb', line 179 def delete(signer_id, account_id_override = nil) acc_id = account_id(account_id_override) sid = require_id(signer_id, 'Signer ID') call_void('Failed to delete signer') do http_delete("accounts/#{acc_id}/signers/#{sid}") end end |
#download_signature(signer_access_code:, type: 'signature') ⇒ String
Download the signer's signature image as raw bytes.
413 414 415 416 417 418 419 420 |
# File 'lib/assinafy/resources/signer_resource.rb', line 413 def download_signature(signer_access_code:, type: 'signature') sig_type = signature_type(type) code = require_signer_access_code(signer_access_code) call_binary('Failed to download signer signature') do http_get("signature/#{sig_type}", { signer_access_code: code }, workspace_auth: false) end end |
#find_by_email(email, account_id_override = nil) ⇒ Hash?
Convenience: find a signer by email using the documented search query
parameter, then do a case-insensitive client-side match. Walks every
result page (using a fixed page size; the API clamps per-page to its
own maximum) until a match is found or the pages are exhausted. Returns
nil when no returned signer matches. API errors still propagate.
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/assinafy/resources/signer_resource.rb', line 211 def find_by_email(email, account_id_override = nil) assert_email!(email.to_s) target = email.to_s.downcase page = 1 loop do result = list({ search: email, page: page, per_page: 50 }, account_id_override) match = result[:data].find { |signer| signer['email'].to_s.downcase == target } return match if match = result[:meta] break unless && [:last_page] && page < [:last_page] page += 1 end nil end |
#get(signer_id, account_id_override = nil) ⇒ Hash
Fetch a signer by ID.
91 92 93 94 95 96 97 98 |
# File 'lib/assinafy/resources/signer_resource.rb', line 91 def get(signer_id, account_id_override = nil) acc_id = account_id(account_id_override) sid = require_id(signer_id, 'Signer ID') call('Failed to fetch signer') do http_get("accounts/#{acc_id}/signers/#{sid}") end end |
#list(params = {}, account_id_override = nil) ⇒ Hash{Symbol=>Array,Hash}
List signers in the workspace, with pagination metadata.
122 123 124 125 126 127 128 |
# File 'lib/assinafy/resources/signer_resource.rb', line 122 def list(params = {}, account_id_override = nil) acc_id = account_id(account_id_override) call_list('Failed to list signers') do http_get("accounts/#{acc_id}/signers", params) end end |
#self_data(signer_access_code:) ⇒ Hash
Fetch the authenticated signer's own profile (signer-access-code auth).
248 249 250 251 252 253 254 |
# File 'lib/assinafy/resources/signer_resource.rb', line 248 def self_data(signer_access_code:) code = require_signer_access_code(signer_access_code) call('Failed to fetch signer self') do http_get('signers/self', { signer_access_code: code }, workspace_auth: false) end end |
#update(signer_id, payload, account_id_override = nil) ⇒ Hash
Partially update a signer. Omitted fields are left unchanged. Updating
email or whatsapp_phone_number is rejected while that channel is
verified on an in-flight document; changing an unverified channel rotates
its access and verification codes.
160 161 162 163 164 165 166 167 168 |
# File 'lib/assinafy/resources/signer_resource.rb', line 160 def update(signer_id, payload, account_id_override = nil) acc_id = account_id(account_id_override) sid = require_id(signer_id, 'Signer ID') body = signer_payload(payload, require_full_name: false, include_government_id: true) call('Failed to update signer') do http_put("accounts/#{acc_id}/signers/#{sid}", body) end end |
#upload_signature(content, signer_access_code:, type: 'signature', content_type: 'image/png', reuse: nil) ⇒ nil, Array
Upload the signer's signature image. The request body is raw image bytes.
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'lib/assinafy/resources/signer_resource.rb', line 372 def upload_signature(content, signer_access_code:, type: 'signature', content_type: 'image/png', reuse: nil) unless content.is_a?(String) && !content.empty? raise ValidationError.new('Signature content must be a non-empty String') end unless content_type == 'image/png' raise ValidationError.new('Signature content type must be image/png') end require_boolean(reuse, 'reuse') unless reuse.nil? sig_type = signature_type(type) code = require_signer_access_code(signer_access_code) call('Failed to upload signer signature') do @connection.post('signature') do |request| prepare_request( request, { signer_access_code: code, type: sig_type, reuse: reuse }, workspace_auth: false ) request.headers['Content-Type'] = content_type request.body = content end end end |
#validate_create!(payload) ⇒ Hash
Validate and normalize a payload accepted by #create without sending a request. Useful for preflighting multi-step workflows before they create any remote resources.
32 33 34 |
# File 'lib/assinafy/resources/signer_resource.rb', line 32 def validate_create!(payload) signer_payload(payload, require_full_name: true) end |
#verify_email(verification_code:, signer_access_code:) ⇒ nil
Verify the signer's email with a one-time verification code.
298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/assinafy/resources/signer_resource.rb', line 298 def verify_email(verification_code:, signer_access_code:) verification = require_string(verification_code, 'Verification code') code = require_signer_access_code(signer_access_code) call('Failed to verify signer email') do http_post( 'verify', body_params(verification_code: verification), { signer_access_code: code }, workspace_auth: false ) end end |