Class: Assinafy::Client
- Inherits:
-
Object
- Object
- Assinafy::Client
- Defined in:
- lib/assinafy/client.rb
Overview
Top-level entry point for the Assinafy Ruby SDK.
A Client owns a single Faraday connection (with shared auth headers, timeouts, and User-Agent) and exposes one resource accessor per documented API surface.
Instance Attribute Summary collapse
- #accounts ⇒ Resources::AccountResource readonly
- #assignments ⇒ Resources::AssignmentResource readonly
- #auth ⇒ Resources::AuthResource readonly
- #documents ⇒ Resources::DocumentResource readonly
- #fields ⇒ Resources::FieldResource readonly
- #signer_documents ⇒ Resources::SignerDocumentResource readonly
- #signers ⇒ Resources::SignerResource readonly
- #tags ⇒ Resources::TagResource readonly
- #templates ⇒ Resources::TemplateResource readonly
- #users ⇒ Resources::UserResource readonly
- #webhook_verifier ⇒ Support::WebhookVerifier readonly
- #webhooks ⇒ Resources::WebhookResource readonly
Class Method Summary collapse
-
.create(api_key, account_id, **options) ⇒ Client
Convenience constructor with positional
api_key/account_id. -
.from_config(config) ⇒ Client
Build a Client from a Hash (string or symbol keys).
-
.from_hash(config) ⇒ Client
Alias of Client.from_config for symmetry with Assinafy::Configuration.from_hash.
Instance Method Summary collapse
-
#faraday_connection ⇒ Faraday::Connection
Expose the underlying Faraday connection (for advanced use cases, such as adding middleware or inspecting headers in tests).
-
#initialize(api_key: nil, token: nil, account_id: nil, base_url: Configuration::DEFAULT_BASE_URL, webhook_secret: nil, timeout: Configuration::DEFAULT_TIMEOUT, logger: nil) ⇒ Client
constructor
A new instance of Client.
-
#upload_and_request_signatures(source:, signers:, message: nil, wait_for_ready: true, expires_at: nil, copy_receivers: nil, account_id: nil) ⇒ Hash{Symbol=>Object}
High-level helper that bundles the most common workflow: upload PDF → (optionally wait for metadata) → create signers → create a virtual assignment for them.
Constructor Details
#initialize(api_key: nil, token: nil, account_id: nil, base_url: Configuration::DEFAULT_BASE_URL, webhook_secret: nil, timeout: Configuration::DEFAULT_TIMEOUT, logger: nil) ⇒ Client
Returns a new instance of Client.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/assinafy/client.rb', line 56 def initialize(api_key: nil, token: nil, account_id: nil, base_url: Configuration::DEFAULT_BASE_URL, webhook_secret: nil, timeout: Configuration::DEFAULT_TIMEOUT, logger: nil) config = Configuration.new( api_key: api_key, token: token, account_id: account_id, base_url: base_url, webhook_secret: webhook_secret, timeout: timeout, logger: logger ) @connection = build_connection(config) @logger = config.logger || NullLogger.new @auth = Resources::AuthResource.new(@connection, nil, @logger) @accounts = Resources::AccountResource.new(@connection, account_id, @logger) @users = Resources::UserResource.new(@connection, nil, @logger) @documents = Resources::DocumentResource.new(@connection, account_id, @logger) @signers = Resources::SignerResource.new(@connection, account_id, @logger) @signer_documents = Resources::SignerDocumentResource.new(@connection, nil, @logger) @assignments = Resources::AssignmentResource.new(@connection, account_id, @logger) @webhooks = Resources::WebhookResource.new(@connection, account_id, @logger) @templates = Resources::TemplateResource.new(@connection, account_id, @logger) @fields = Resources::FieldResource.new(@connection, account_id, @logger) @tags = Resources::TagResource.new(@connection, account_id, @logger) @webhook_verifier = Support::WebhookVerifier.new(webhook_secret) end |
Instance Attribute Details
#accounts ⇒ Resources::AccountResource (readonly)
21 22 23 |
# File 'lib/assinafy/client.rb', line 21 def accounts @accounts end |
#assignments ⇒ Resources::AssignmentResource (readonly)
31 32 33 |
# File 'lib/assinafy/client.rb', line 31 def assignments @assignments end |
#auth ⇒ Resources::AuthResource (readonly)
19 20 21 |
# File 'lib/assinafy/client.rb', line 19 def auth @auth end |
#documents ⇒ Resources::DocumentResource (readonly)
25 26 27 |
# File 'lib/assinafy/client.rb', line 25 def documents @documents end |
#fields ⇒ Resources::FieldResource (readonly)
37 38 39 |
# File 'lib/assinafy/client.rb', line 37 def fields @fields end |
#signer_documents ⇒ Resources::SignerDocumentResource (readonly)
29 30 31 |
# File 'lib/assinafy/client.rb', line 29 def signer_documents @signer_documents end |
#signers ⇒ Resources::SignerResource (readonly)
27 28 29 |
# File 'lib/assinafy/client.rb', line 27 def signers @signers end |
#tags ⇒ Resources::TagResource (readonly)
39 40 41 |
# File 'lib/assinafy/client.rb', line 39 def @tags end |
#templates ⇒ Resources::TemplateResource (readonly)
35 36 37 |
# File 'lib/assinafy/client.rb', line 35 def templates @templates end |
#users ⇒ Resources::UserResource (readonly)
23 24 25 |
# File 'lib/assinafy/client.rb', line 23 def users @users end |
#webhook_verifier ⇒ Support::WebhookVerifier (readonly)
41 42 43 |
# File 'lib/assinafy/client.rb', line 41 def webhook_verifier @webhook_verifier end |
#webhooks ⇒ Resources::WebhookResource (readonly)
33 34 35 |
# File 'lib/assinafy/client.rb', line 33 def webhooks @webhooks end |
Class Method Details
.create(api_key, account_id, **options) ⇒ Client
Convenience constructor with positional api_key/account_id.
94 95 96 |
# File 'lib/assinafy/client.rb', line 94 def self.create(api_key, account_id, **) new(api_key: api_key, account_id: account_id, **) end |
.from_config(config) ⇒ Client
Build a Client from a Hash (string or symbol keys). Useful for credentials loaded from YAML/JSON.
108 109 110 |
# File 'lib/assinafy/client.rb', line 108 def self.from_config(config) from_hash(config) end |
.from_hash(config) ⇒ Client
Alias of from_config for symmetry with Assinafy::Configuration.from_hash.
120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/assinafy/client.rb', line 120 def self.from_hash(config) cfg = Configuration.from_hash(config) new( api_key: cfg.api_key, token: cfg.token, account_id: cfg.account_id, base_url: cfg.base_url, webhook_secret: cfg.webhook_secret, timeout: cfg.timeout, logger: cfg.logger ) end |
Instance Method Details
#faraday_connection ⇒ Faraday::Connection
Expose the underlying Faraday connection (for advanced use cases, such as adding middleware or inspecting headers in tests).
225 226 227 |
# File 'lib/assinafy/client.rb', line 225 def faraday_connection @connection end |
#upload_and_request_signatures(source:, signers:, message: nil, wait_for_ready: true, expires_at: nil, copy_receivers: nil, account_id: nil) ⇒ Hash{Symbol=>Object}
This helper is not transactional. If a later API call fails, an uploaded document or newly created signer may remain and should be cleaned up by the caller.
High-level helper that bundles the most common workflow: upload PDF → (optionally wait for metadata) → create signers → create a virtual assignment for them.
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/assinafy/client.rb', line 189 def upload_and_request_signatures(source:, signers:, message: nil, wait_for_ready: true, expires_at: nil, copy_receivers: nil, account_id: nil) unless signers.is_a?(Array) && !signers.empty? && signers.all?(Hash) raise ValidationError.new('Signers must be a non-empty Array of Hashes') end @logger.info("Starting upload and signature workflow for #{signers.length} signer(s)") upload_opts = account_id.nil? ? {} : { account_id: account_id } document = @documents.upload(source, upload_opts) document = @documents.wait_until_ready(document['id']) if wait_for_ready signer_ids = signers.map do |signer| created = @signers.create(signer, account_id) created['id'] || raise(ApiError.new('Signer created but the API returned no ID', 502, created)) end assignment_payload = { method: 'virtual', signers: signer_ids, message: , expires_at: expires_at, copy_receivers: copy_receivers } assignment = @assignments.create(document['id'], assignment_payload) @logger.info("Upload and signature workflow completed for document #{document['id']}") { document: document, assignment: assignment, signer_ids: signer_ids } end |