### OAuth Token Exchange Example Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/client.md Example showing how to exchange an OAuth authorization code for tokens and create a client with the resulting access token. ```APIDOC ## OAuth Token Exchange Example ### Description Example showing how to exchange an OAuth authorization code for tokens and create a client with the resulting access token. ### Example ```ruby # OAuth access: act as the user in the workspace they chose tokens = Assinafy::Client.new.oauth.exchange_code( code: params.fetch('code'), client_id: client_id, code_verifier: verifier, redirect_uri: callback_url ) client = Assinafy::Client.new(token: tokens.fetch('access_token'), account_id: 'account_example') ``` ``` -------------------------------- ### Instalar dependências com bundle install Source: https://github.com/assinafy/ruby-sdk/blob/main/README.md Instala as gems declaradas no Gemfile, incluindo o SDK assinafy. ```bash bundle install ``` -------------------------------- ### Manage API key (create, get, delete) Source: https://github.com/assinafy/ruby-sdk/blob/main/README.md Create an API key with password (shown once), get the masked key, or delete it. Generating a new key invalidates the previous one. Never expose the key in a front-end. ```ruby usuario.auth.create_api_key(password: ENV.fetch('ASSINAFY_PASSWORD')) # => { 'api_key' => '...' } — exibida uma única vez usuario.auth.get_api_key # => { 'api_key' => '****...' } — mascarada usuario.auth.delete_api_key # => nil ``` -------------------------------- ### Check and start biometric identity verification Source: https://github.com/assinafy/ruby-sdk/blob/main/README.md Use `identity_verification` to check if a signer can start biometric verification, then `start_identity_verification` with explicit consent to open a session. The returned URL must be opened without modification and not logged or stored. ```ruby estado = signatario_client.signers.identity_verification(signer_access_code: codigo) # => { 'can_start' => true, 'status' => nil, 'url' => nil, 'expires_at' => nil, 'completed_at' => nil } # Após o consentimento explícito do signatário para o processamento biométrico: sessao = signatario_client.signers.start_identity_verification(consent: true, signer_access_code: codigo) # => { 'id' => 'verification-id', 'url' => 'https://verify.assinafy.com.br/c/session#t=token-placeholder', # 'expires_at' => '2026-10-16T13:00:00Z' } ``` -------------------------------- ### Manage two-factor authentication (TOTP enrollment, methods, recovery codes) Source: https://github.com/assinafy/ruby-sdk/blob/main/README.md These calls act on the authenticated user. Start TOTP enrollment to get a provisioning URI and secret (shown only once). Confirm enrollment to receive recovery codes (shown once). List MFA methods, regenerate recovery codes, and delete an MFA method. Two-factor authentication only activates after confirm_totp_enrollment. Confirming a new authenticator replaces the previous one and requires reauthentication. regenerate_recovery_codes and delete_mfa_method require password or code; otherwise the SDK raises ValidationError before sending. Removing the last method also discards recovery codes. ```ruby inscricao = usuario.auth.start_totp_enrollment(label: 'Meu celular') inscricao['provisioning_uri'] # => "otpauth://totp/...": mostre como QR code inscricao['secret'] # exibido só nesta resposta codigos = usuario.auth.confirm_totp_enrollment(method_id: inscricao.fetch('id'), code: '123456') codigos['recovery_codes'] # => ["ABCD-EFGH-JKMN", ...] — exibidos uma única vez usuario.auth.mfa_methods # => { 'methods' => [{ 'id' => 'mfa-method-id', 'type' => 'Totp', 'label' => 'Meu celular', ... }], # 'recovery_codes_remaining' => 10 } usuario.auth.regenerate_recovery_codes(password: ENV.fetch('ASSINAFY_PASSWORD')) usuario.auth.delete_mfa_method('mfa-method-id', code: '123456') # => { 'is_mfa_enabled' => false } ``` -------------------------------- ### GET /accounts/{account_id}/templates Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/endpoints.md Lists templates. Requires workspace authentication. ```APIDOC ## GET /accounts/{account_id}/templates ### Description Lists templates. Requires workspace authentication. ### Method GET ### Endpoint /accounts/{account_id}/templates ### Parameters #### Path Parameters - **account_id** (string) - Required - The account identifier. #### Query Parameters - **search** (string) - Optional - Search query. - **page** (integer) - Optional - Page number. - **per_page** (integer) - Optional - Items per page. ### Response #### Success Response (200) - **templates** (array) - List of templates. #### Response Example { "templates": [] } ``` -------------------------------- ### POST /users/self/mfa/totp Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/endpoints.md Starts TOTP enrollment for the current user. Requires workspace authentication. ```APIDOC ## POST /users/self/mfa/totp ### Description Starts TOTP enrollment for the current user. ### Method POST ### Endpoint `/users/self/mfa/totp` ### Authentication - Workspace authentication required ### Parameters #### Request Body - **label** (string) - Required - Label for the TOTP method ### Request Example ```json { "label": "My Authenticator" } ``` ### Response #### Success Response (200) - TOTP enrollment details (e.g., secret, QR code) ``` -------------------------------- ### POST /users/self/mfa/totp Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/auth_resource.md Starts TOTP enrollment for the authenticated user. ```APIDOC ## POST /users/self/mfa/totp ### Description Starts TOTP enrollment for the authenticated user. ### Method POST ### Endpoint /users/self/mfa/totp ### Authentication Requires workspace authentication. ### Response #### Success Response - **id** (string) - The enrollment ID. - **secret** (string) - The TOTP secret. - **provisioning_uri** (string) - The provisioning URI for the authenticator app. ``` -------------------------------- ### get account with client.accounts.get Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/account_resource.md GET /accounts/{account_id}. Without an override, uses the client's default account. ```ruby client.accounts.get # usa client.accounts (account_id do client) ``` -------------------------------- ### Assinafy::Client#initialize Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/configuration.md Creates a new Assinafy::Client instance with configuration options. Accepts keyword arguments for API credentials and connection settings. ```ruby 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) end ``` -------------------------------- ### #get(signer_id, account_id_override = nil) → Hash Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/signer_resource.md Retrieves a signer by ID via GET /accounts/{account_id}/signers/{signer_id}. ```APIDOC ## [GET] /accounts/{account_id}/signers/{signer_id} ### Description Retrieves a signer by its ID. ### Method GET ### Endpoint /accounts/{account_id}/signers/{signer_id} ### Parameters #### Path Parameters - **account_id** (string) - Required - The account identifier. - **signer_id** (string) - Required - The signer identifier. ### Response #### Success Response (200) Returns the signer object as a Hash. ``` -------------------------------- ### Initialize Assinafy::Client with keyword arguments Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/configuration.md Constructor for Assinafy::Client accepting the same keys and rules as Configuration, with keywords converted to an internal Configuration immediately. Defaults for base_url and timeout come from Configuration::DEFAULT_BASE_URL and Configuration::DEFAULT_TIMEOUT. ```ruby 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) ``` -------------------------------- ### Create client and access resource Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/client.md Instantiates a client with API key and account ID, then accesses the documents resource. No network call is made during construction. ```ruby client = Assinafy::Client.new(api_key: 'example_api_key', account_id: 'account_example') client.documents #=> # ``` -------------------------------- ### Assinafy::Client.create Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/configuration.md Convenience constructor that accepts positional api_key and account_id, with additional options passed to #initialize. ```ruby def self.create(api_key, account_id, **options) new(api_key: api_key, account_id: account_id, **options) end ``` ```ruby client = Assinafy::Client.create('example_api_key', 'account_example', webhook_secret: 'gateway_secret') ``` -------------------------------- ### Rescue Assinafy::ApiError example Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/errors.md Shows how to rescue Assinafy::ApiError when calling client.documents.details with a missing ID. The example accesses status_code (404), error_name ("Not Found" or nil), error_code (0 or nil), and response_data (raw body). ```ruby begin client.documents.details('missing-id') rescue Assinafy::ApiError => e e.status_code # => 404 e.error_name # => "Not Found" (nil quando o corpo omite) e.error_code # => 0 (nil quando o corpo omite) e.response_data # => corpo bruto end ``` -------------------------------- ### Create client with .create(api_key, account_id, **options) Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/client.md Class method that instantiates a Client with the given API key and account ID, forwarding extra options such as webhook_secret. Use environment variables for credentials. ```ruby def self.create(api_key, account_id, **options) new(api_key: api_key, account_id: account_id, **options) end ``` ```ruby client = Assinafy::Client.create(ENV['ASSINAFY_API_KEY'], ENV['ASSINAFY_ACCOUNT_ID'], webhook_secret: 'gateway_secret') ``` -------------------------------- ### Assinafy::Client.from_config Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/client.md Creates a Client instance from a configuration object. This is useful for loading settings from a config file. ```APIDOC ## Client.from_config ### Description Creates a Client instance from a configuration object. This is useful for loading settings from a config file. ### Method `self.from_config` ### Parameters - **config** (params) - Required - Configuration object containing client settings. ### Returns - **Client** - A new Client instance. ### Example ```ruby client = Assinafy::Client.from_config(config) ``` ``` -------------------------------- ### Get protected resource metadata with #protected_resource_metadata Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/oauth_resource.md Calls GET /.well-known/oauth-protected-resource on the host root, outside /v1, without credentials. Returns RFC 9728 fields: resource, authorization_servers[], scopes_supported[], bearer_methods_supported[]. scopes_supported deliberately omits offline_access. ```ruby meta = client.oauth.protected_resource_metadata meta.fetch('authorization_servers').first # => "https://auth.assinafy.com.br" ``` -------------------------------- ### Load client from config with .from_config(config) Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/client.md Builds a Client from a string-keyed Hash loaded from a YAML file. Delegates to Configuration.from_hash and accepts String or Symbol keys, including the legacy access_token alias. Raises ValidationError unless the input is a Hash. ```ruby creds = YAML.load_file('config/assinafy.yml') # string-keyed Hash client = Assinafy::Client.from_config(creds) client.documents.list # usa as credenciais do Hash ``` -------------------------------- ### Get masked API key with #get_api_key Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/auth_resource.md GET /users/api-keys. Returns a masked key like { "api_key" => "********************************9Jdr" } or nil if no key was generated (404 → call_optional). Works with X-Api-Key, not only Bearer. ```ruby masked = client.auth.get_api_key # => { "api_key" => "********************************9Jdr" } ``` -------------------------------- ### Assinafy::Client.from_hash Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/client.md Creates a Client instance from a hash of configuration options. This is useful for programmatic configuration. ```APIDOC ## Client.from_hash ### Description Creates a Client instance from a hash of configuration options. This is useful for programmatic configuration. ### Method `self.from_hash` ### Parameters - **config** (params) - Required - Hash containing client settings. ### Returns - **Client** - A new Client instance. ### Example ```ruby client = Assinafy::Client.from_hash({ api_key: 'your_api_key', account_id: 'your_account_id' }) ``` ``` -------------------------------- ### GET /users/self/stats Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/endpoints.md Retrieves statistics for the current user. ```APIDOC ## GET /users/self/stats ### Description Retrieves statistics for the current user. ### Method GET ### Endpoint `/users/self/stats` ### Parameters #### Query Parameters - **granularity** (string) - Optional - Granularity (monthly or daily) - **month** (string) - Optional - Month in YYYY-MM format ### Response #### Success Response (200) - Statistics data ``` -------------------------------- ### Build client from config hash with from_config/from_hash Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/configuration.md Both class methods build a client from a String/Symbol Hash (e.g., YAML loaded from config/assinafy.yml). from_config is an alias for from_hash. ```ruby def self.from_config(config) from_hash(config) end 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 ``` ```ruby creds = YAML.load_file('config/assinafy.yml') client = Assinafy::Client.from_config(creds) ``` -------------------------------- ### GET /documents/{document_id} Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/endpoints.md Retrieves details of a specific document. ```APIDOC ## GET /documents/{document_id} ### Description Retrieves details of a specific document. ### Method GET ### Endpoint `/documents/{document_id}` ### Parameters #### Path Parameters - **document_id** (string) - Required - The document identifier. ### Response #### Success Response (200) - **document** (object) - The document details. #### Response Example ```json { "document": {} } ``` ``` -------------------------------- ### Create client with positional arguments via Client.create Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/configuration.md Convenience class method that accepts api_key and account_id positionally, passing additional options (e.g., webhook_secret:) to #initialize. ```ruby def self.create(api_key, account_id, **options) new(api_key: api_key, account_id: account_id, **options) end ``` ```ruby client = Assinafy::Client.create('example_api_key', 'account_example', webhook_secret: 'gateway_secret') ``` -------------------------------- ### GET /documents/statuses Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/endpoints.md Retrieves the catalog of document status codes. ```APIDOC ## GET /documents/statuses ### Description Retrieves the catalog of document status codes. ### Method GET ### Endpoint `/documents/statuses` ### Response #### Success Response (200) - **statuses** (array) - List of status codes. #### Response Example ```json { "statuses": [] } ``` ``` -------------------------------- ### GET /users/self Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/endpoints.md Retrieves the current user's profile. ```APIDOC ## GET /users/self ### Description Retrieves the current user's profile. ### Method GET ### Endpoint `/users/self` ### Response #### Success Response (200) - User profile ``` -------------------------------- ### .from_config(config) / .from_hash(config) → Client Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/client.md Creates a client from a configuration hash, supporting both string and symbol keys. The legacy alias `access_token` is also accepted. Raises `ValidationError` if the input is not a Hash. ```APIDOC ## .from_config(config) / .from_hash(config) → Client ### Description Creates a client from a configuration hash, supporting both string and symbol keys. The legacy alias `access_token` is also accepted. Raises `ValidationError` if the input is not a Hash. ### Method from_config / from_hash ### Parameters - **config** (Hash) - Required - Configuration hash with credentials. ### Request Example ```ruby creds = YAML.load_file('config/assinafy.yml') # string-keyed Hash client = Assinafy::Client.from_config(creds) client.documents.list # usa as credenciais do Hash ``` ### Response Returns a `Client` instance. ### Errors - `ValidationError` - If the input is not a Hash. ``` -------------------------------- ### GET /accounts/{account_id}/logo Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/endpoints.md Downloads the logo for an account. ```APIDOC ## GET /accounts/{account_id}/logo ### Description Downloads the logo for an account. ### Method GET ### Endpoint `/accounts/{account_id}/logo` ### Parameters #### Path Parameters - **account_id** (string) - Required - Account ID ### Response #### Success Response (200) - Logo file ``` -------------------------------- ### Assinafy::Client.new Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/client.md Initializes a new Client instance with optional configuration parameters. This is the primary constructor for the SDK. ```APIDOC ## Client.new ### Description Initializes a new Client instance with optional configuration parameters. This is the primary constructor for the SDK. ### Method `initialize` ### Parameters - **api_key** (String?) - Optional - API key for authentication. - **token** (String?) - Optional - Token for authentication. - **account_id** (String?) - Optional - Account identifier. - **base_url** (String) - Required - Base URL for the API. - **webhook_secret** (String?) - Optional - Secret for webhook verification. - **timeout** (Integer | String | nil) - Optional - Request timeout. - **logger** (_Logger?) - Optional - Logger instance. ### Returns - **Client** - A new Client instance. ### Example ```ruby client = Assinafy::Client.new(api_key: 'your_api_key', account_id: 'your_account_id') ``` ``` -------------------------------- ### GET /accounts/{account_id}/theme Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/endpoints.md Retrieves the theme for an account. ```APIDOC ## GET /accounts/{account_id}/theme ### Description Retrieves the theme for an account. ### Method GET ### Endpoint `/accounts/{account_id}/theme` ### Parameters #### Path Parameters - **account_id** (string) - Required - Account ID ### Response #### Success Response (200) - Theme configuration ``` -------------------------------- ### Login with email and password Source: https://github.com/assinafy/ruby-sdk/blob/main/README.md Creates a public client and logs in with email and password. The session object contains an access token and account list on success, or an mfa_token if two-factor authentication is enabled. ```ruby publico = Assinafy::Client.new sessao = publico.auth.login(email: 'usuario@example.com', password: ENV.fetch('ASSINAFY_PASSWORD')) ``` -------------------------------- ### GET /accounts/{account_id} Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/endpoints.md Retrieves details of a specific account. ```APIDOC ## GET /accounts/{account_id} ### Description Retrieves details of a specific account. ### Method GET ### Endpoint `/accounts/{account_id}` ### Parameters #### Path Parameters - **account_id** (string) - Required - Account ID ### Response #### Success Response (200) - Account details ``` -------------------------------- ### Configurar cliente Assinafy::Client Source: https://github.com/assinafy/ruby-sdk/blob/main/README.md Cria um cliente com credenciais via variáveis de ambiente, define base_url padrão de produção, timeout de 30s e logger. Requer Ruby 3.2+ e TLS 1.2+. ```ruby require 'assinafy' require 'logger' client = Assinafy::Client.new( api_key: ENV.fetch('ASSINAFY_API_KEY'), account_id: ENV.fetch('ASSINAFY_ACCOUNT_ID'), base_url: ENV.fetch('ASSINAFY_BASE_URL', 'https://api.assinafy.com.br/v1'), webhook_secret: ENV['ASSINAFY_WEBHOOK_SECRET'], # whsec_... do endpoint de webhook timeout: 30, logger: Logger.new($stdout) ) ``` -------------------------------- ### .create(api_key, account_id, **options) → Client Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/client.md Creates a new Assinafy client instance with the provided API key and account ID. Additional options can be passed as keyword arguments. ```APIDOC ## .create(api_key, account_id, **options) → Client ### Description Creates a new Assinafy client instance with the provided API key and account ID. Additional options can be passed as keyword arguments. ### Method create ### Parameters - **api_key** (String) - Required - The API key for authentication. - **account_id** (String) - Required - The account ID. - **options** (Hash) - Optional - Additional options (e.g., `webhook_secret`). ### Request Example ```ruby client = Assinafy::Client.create(ENV['ASSINAFY_API_KEY'], ENV['ASSINAFY_ACCOUNT_ID'], webhook_secret: 'gateway_secret') ``` ### Response Returns a `Client` instance. ``` -------------------------------- ### GET /webhooks/event-types Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/webhook_resource.md Lists the available webhook event types. ```APIDOC ## [GET] /webhooks/event-types ### Description Lists the available webhook event types. ### Method GET ### Endpoint /webhooks/event-types ### Response #### Success Response (200) - **event_types** (array) - List of event type strings. ``` -------------------------------- ### Handle MFA challenge and create authenticated client Source: https://github.com/assinafy/ruby-sdk/blob/main/README.md If login returns an mfa_token, verify it with a code from the authenticator app or a recovery code. Then create a client with the returned access token and account ID. verify_mfa is sent without workspace credentials; the challenge is single-use and expires 5 minutes after login. A wrong code returns 400, an expired/used/overused challenge returns 401. ```ruby if sessao['mfa_token'] sessao = publico.auth.verify_mfa( mfa_token: sessao['mfa_token'], code: '123456' # ou um código de recuperação, como "ABCD-EFGH-JKMN" ) end usuario = Assinafy::Client.new( token: sessao.fetch('access_token'), account_id: sessao.fetch('accounts').first.fetch('id') ) ``` -------------------------------- ### GET /signers/{signer_id}/document Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/endpoints.md Retrieves the current document for a signer. ```APIDOC ## GET /signers/{signer_id}/document ### Description Retrieves the current document for a signer. ### Method GET ### Endpoint `/signers/{signer_id}/document` ### Parameters #### Path Parameters - **signer_id** (string) - Required - The signer identifier. #### Query Parameters - **signer-access-code** (string) - Required - The signer access code. ### Response #### Success Response (200) - **document** (object) - The current document. #### Response Example ```json { "document": {} } ``` ``` -------------------------------- ### build_connection: Configurar conexão Faraday com TLS 1.2 Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/configuration.md Método privado que cria a conexão Faraday para o cliente. Define TLS mínimo 1.2 (a API rejeita TLS 1.0/1.1), usa middleware multipart e JSON, e aplica timeouts e headers de autenticação. Não faz pinning de certificado; usa o trust store do sistema. ```ruby def build_connection(config) # The API rejects TLS 1.0 and 1.1; never offer them. Faraday.new(url: config.base_url, ssl: { min_version: OpenSSL::SSL::TLS1_2_VERSION }) do |f| f.request :multipart f.request :json f.response :json, content_type: /\bjson/ f.options.timeout = config.timeout f.options.open_timeout = config.timeout f.headers.merge!(config.auth_headers) f.headers['Accept'] = 'application/json' f.headers['User-Agent'] = USER_AGENT f.adapter Faraday.default_adapter end end ``` -------------------------------- ### Upload de documento com caminho de arquivo Source: https://github.com/assinafy/ruby-sdk/blob/main/README.md Envia um arquivo PDF local para a Assinafy e retorna um hash com os metadados do documento, incluindo 'id', 'name' e 'status' (que será 'uploaded'). O SDK valida a extensão, o tamanho (máximo 25 MB) e o cabeçalho '%PDF-' antes do envio. ```ruby documento = client.documents.upload('./contrato-acme.pdf') documento['id'] # => "document-id" documento['name'] # => "contrato-acme.pdf" documento['status'] # => "uploaded" ``` -------------------------------- ### GET /signature/{type} Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/endpoints.md Downloads a signature image of the specified type. ```APIDOC ## GET /signature/{type} ### Description Downloads a signature image of the specified type. ### Method GET ### Endpoint `/signature/{type}` ### Parameters #### Path Parameters - **type** (string) - Required - The signature type. #### Query Parameters - **signer-access-code** (string) - Required - The signer access code. ### Response #### Success Response (200) - **body** (binary) - The signature image. #### Response Example ``` (binary data) ``` ``` -------------------------------- ### Client.new Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/client.md Creates a new Assinafy client instance. Accepts authentication credentials, account scope, and connection settings. Returns a Client instance or raises ValidationError for invalid base_url or timeout. ```APIDOC ## Client.new ### Description Creates a new Assinafy client instance. Accepts authentication credentials, account scope, and connection settings. Returns a Client instance or raises ValidationError for invalid base_url or timeout. ### Method Constructor ### Signature ```ruby 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) ``` ### Parameters - **api_key** (String, nil) - Optional - Sent as `X-Api-Key` - **token** (String, nil) - Optional - Bearer (login session or OAuth access token); used when api_key is nil - **account_id** (String, nil) - Optional - Default workspace for account-scoped resources - **base_url** (String) - Optional - API base URL (default: Configuration::DEFAULT_BASE_URL) - **webhook_secret** (String, nil) - Optional - Secret for Support::WebhookVerifier - **timeout** (Integer) - Optional - Faraday timeout in seconds (default: Configuration::DEFAULT_TIMEOUT, 30) - **logger** (Logger, nil) - Optional - Lifecycle messages ### Returns - **Client** - The client instance ### Raises - **ValidationError** - For invalid base_url or timeout ### Example ```ruby client = Assinafy::Client.new(api_key: 'example_api_key', account_id: 'account_example') ``` ``` -------------------------------- ### GET /signers/identity-verification Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/endpoints.md Retrieves identity verification status for the current signer. ```APIDOC ## GET /signers/identity-verification ### Description Retrieves identity verification status for the current signer. ### Method GET ### Endpoint `/signers/identity-verification` ### Parameters #### Query Parameters - **signer-access-code** (string) - Required - The signer access code. ### Response #### Success Response (200) - **verification** (object) - Identity verification details. #### Response Example ```json { "verification": {} } ``` ``` -------------------------------- ### GET /users/self/notification-preferences Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/endpoints.md Retrieves the current user's notification preferences. ```APIDOC ## GET /users/self/notification-preferences ### Description Retrieves the current user's notification preferences. ### Method GET ### Endpoint `/users/self/notification-preferences` ### Response #### Success Response (200) - Notification preferences ``` -------------------------------- ### Creating a Configuration with api_key and account_id Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/configuration.md Shows typical instantiation with api_key and account_id, and the resulting default base_url, timeout, and auth_headers. ```ruby config = Assinafy::Configuration.new( api_key: 'example_api_key', account_id: 'account_example' ) config.base_url # => "https://api.assinafy.com.br/v1" config.timeout # => 30 config.auth_headers # => { "X-Api-Key" => "example_api_key" } ``` -------------------------------- ### Client constructor signature Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/client.md Shows the initialize method signature with all parameters and defaults. Raises ValidationError for invalid base_url or timeout. ```ruby 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) ``` -------------------------------- ### GET /accounts Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/endpoints.md Lists all accounts (workspaces) accessible to the authenticated user. ```APIDOC ## GET /accounts ### Description Lists all accounts (workspaces) accessible to the authenticated user. ### Method GET ### Endpoint `/accounts` ### Response #### Success Response (200) - List of accounts #### Response Example ```json [ { "id": "...", "name": "Account Name" } ] ``` ``` -------------------------------- ### Configurar credenciais do GitHub Packages com bundle config Source: https://github.com/assinafy/ruby-sdk/blob/main/README.md Define o usuário e token para autenticação no mirror do GitHub Packages. Substitua USUARIO:TOKEN pelas suas credenciais. ```bash bundle config https://rubygems.pkg.github.com/assinafy USUARIO:TOKEN ``` -------------------------------- ### GET /accounts/{id}/webhooks/endpoints Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/webhook_resource.md Lists all webhook endpoints for the account. ```APIDOC ## [GET] /accounts/{id}/webhooks/endpoints ### Description Lists all webhook endpoints for the account. ### Method GET ### Endpoint /accounts/{id}/webhooks/endpoints ### Parameters #### Path Parameters - **id** (string) - Required - The account identifier. ### Response #### Success Response (200) - **endpoints** (array) - List of endpoint objects. ``` -------------------------------- ### Receptor Rack (Sinatra) para webhooks Assinafy Source: https://github.com/assinafy/ruby-sdk/blob/main/README.md Endpoint Sinatra que lê o corpo bruto de request.body.read e valida com request.env. Interrompe com 401 se a assinatura falhar. Extrai o evento e processa conforme o tipo: 'signer_signed_document' passa o objeto do evento (o Document) e 'document_ready' usa o id do objeto para baixar o assinado. Retorna 200 em sucesso. ```ruby post '/webhooks/assinafy' do corpo = request.body.read halt 401 unless VERIFICADOR.verify_delivery(corpo, request.env) evento = VERIFICADOR.extract_event(corpo) case VERIFICADOR.event_type(evento) when 'signer_signed_document' then processar(VERIFICADOR.event_object(evento)) # o Document when 'document_ready' then baixar_assinado(VERIFICADOR.event_object(evento)['id']) end 200 end ``` -------------------------------- ### GET /accounts/{id}/webhooks Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/webhook_resource.md Lists webhook dispatches for the account. ```APIDOC ## [GET] /accounts/{id}/webhooks ### Description Lists webhook dispatches for the account. ### Method GET ### Endpoint /accounts/{id}/webhooks ### Parameters #### Path Parameters - **id** (string) - Required - The account identifier. ### Response #### Success Response (200) - **dispatches** (array) - List of dispatch objects. ``` -------------------------------- ### GET /field-types Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/endpoints.md Lists available field types. Requires workspace authentication. ```APIDOC ## GET /field-types ### Description Lists available field types. Requires workspace authentication. ### Method GET ### Endpoint /field-types ### Response #### Success Response (200) - **field_types** (array) - List of field types. #### Response Example { "field_types": [] } ``` -------------------------------- ### Configuration#initialize signature Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/configuration.md Constructor accepting optional keyword arguments for api_key, token, account_id, base_url, webhook_secret, timeout, and logger. Raises ValidationError for invalid base_url or timeout. ```ruby def initialize(api_key: nil, token: nil, account_id: nil, base_url: DEFAULT_BASE_URL, webhook_secret: nil, timeout: DEFAULT_TIMEOUT, logger: nil) ``` -------------------------------- ### Assinafy::Client.create Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/client.md Creates a new Client instance using an API key and account ID, with additional options. This is a convenience factory method. ```APIDOC ## Client.create ### Description Creates a new Client instance using an API key and account ID, with additional options. This is a convenience factory method. ### Method `self.create` ### Parameters - **api_key** (String) - Required - API key for authentication. - **account_id** (String) - Required - Account identifier. - **options** (**untyped) - Optional - Additional options passed to the initializer. ### Returns - **Client** - A new Client instance. ### Example ```ruby client = Assinafy::Client.create('your_api_key', 'your_account_id') ``` ``` -------------------------------- ### GET /accounts/{accountId}/fields Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/endpoints.md Lists fields. Requires workspace authentication. ```APIDOC ## GET /accounts/{accountId}/fields ### Description Lists fields. Requires workspace authentication. ### Method GET ### Endpoint /accounts/{accountId}/fields ### Parameters #### Path Parameters - **accountId** (string) - Required - The account identifier (camelCase). #### Query Parameters - **include_inactive** (boolean) - Optional - Include inactive fields. - **include_standard** (boolean) - Optional - Include standard fields. ### Response #### Success Response (200) - **fields** (array) - List of fields. #### Response Example { "fields": [] } ``` -------------------------------- ### client.templates.list Source: https://github.com/assinafy/ruby-sdk/blob/main/README.md Lists all templates. ```ruby client.templates.list ``` -------------------------------- ### Verificar progresso de assinatura e atividades Source: https://github.com/assinafy/ruby-sdk/blob/main/README.md Consulta o progresso de assinatura de um documento, verifica se está totalmente assinado e obtém a trilha completa de eventos com origem (IP e user-agent). ```ruby client.documents.signing_progress(documento['id']) # => { signed: 1, total: 3, pending: 2, percentage: 33.33 } client.documents.fully_signed?(documento['id']) # => false client.documents.activities(documento['id']) # trilha completa de eventos, com origin (ip, user-agent) ``` -------------------------------- ### GET /accounts/{account_id}/signers/{signer_id} Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/endpoints.md Retrieves details of a specific signer. ```APIDOC ## GET /accounts/{account_id}/signers/{signer_id} ### Description Retrieves details of a specific signer. ### Method GET ### Endpoint `/accounts/{account_id}/signers/{signer_id}` ### Parameters #### Path Parameters - **account_id** (string) - Required - The account identifier. - **signer_id** (string) - Required - The signer identifier. ### Response #### Success Response (200) - **signer** (object) - The signer details. #### Response Example ```json { "signer": {} } ``` ``` -------------------------------- ### #start_totp_enrollment(label: nil) → Hash Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/auth_resource.md Starts the enrollment of a new TOTP authenticator app. Returns a Hash with 'id', 'secret', and 'provisioning_uri'. The secret is shown only once; 2FA remains disabled until #confirm_totp_enrollment is called. ```APIDOC ## POST /users/self/mfa/totp ### Description Starts the enrollment of a new TOTP authenticator app. Returns a Hash with 'id', 'secret', and 'provisioning_uri'. The secret is shown only once; 2FA remains disabled until #confirm_totp_enrollment is called. ### Method POST ### Endpoint /users/self/mfa/totp ### Parameters #### Request Body - **label** (string) - Optional - A label for the authenticator app. ### Response #### Success Response (200) - **id** (string) - The enrollment ID. - **secret** (string) - The TOTP secret (shown only once). - **provisioning_uri** (string) - The provisioning URI for the authenticator app. ``` -------------------------------- ### GET /public/documents/{document_id} Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/endpoints.md Retrieves public metadata for a document. No authentication is required. ```APIDOC ## GET /public/documents/{document_id} ### Description Retrieves public metadata for a document. No authentication is required. ### Method GET ### Endpoint `/public/documents/{document_id}` ### Parameters #### Path Parameters - **document_id** (string) - Required - The document identifier. ### Response #### Success Response (200) - **metadata** (object) - Public metadata. #### Response Example ```json { "metadata": {} } ``` ``` -------------------------------- ### GET /.well-known/oauth-protected-resource Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/endpoints.md Retrieves OAuth protected resource metadata. No authentication required. ```APIDOC ## GET /.well-known/oauth-protected-resource ### Description Retrieves OAuth protected resource metadata. ### Method GET ### Endpoint `/.well-known/oauth-protected-resource` ### Response #### Success Response (200) - Protected resource metadata (JSON) ``` -------------------------------- ### OAuth token exchange and client creation Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/client.md Exchanges an OAuth code for tokens and creates a client with the access token and account ID. Used to act as the user in their chosen workspace. ```ruby # Acesso OAuth: agir como o usuário no workspace que ele escolheu tokens = Assinafy::Client.new.oauth.exchange_code( code: params.fetch('code'), client_id: client_id, code_verifier: verifier, redirect_uri: callback_url ) client = Assinafy::Client.new(token: tokens.fetch('access_token'), account_id: 'account_example') ``` -------------------------------- ### Adicionar gem 'assinafy' no Gemfile Source: https://github.com/assinafy/ruby-sdk/blob/main/README.md Declara a dependência do SDK no Gemfile para instalação via RubyGems.org. ```ruby # Gemfile gem 'assinafy' ``` -------------------------------- ### GET /oauth/userinfo Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/endpoints.md Retrieves information about the authenticated user. Requires Bearer token. ```APIDOC ## GET /oauth/userinfo ### Description Retrieves information about the authenticated user. ### Method GET ### Endpoint `/oauth/userinfo` ### Authentication - Bearer token required ### Response #### Success Response (200) - User information (JSON) #### Response Example ```json { "sub": "...", "email": "user@example.com", "name": "User Name" } ``` ``` -------------------------------- ### Verificar documento publicamente pelo hash da assinatura Source: https://github.com/assinafy/ruby-sdk/blob/main/README.md Verifica um documento assinado usando o hash da assinatura, sem autenticação. Retorna o resultado da Assinafy; não valida independentemente a assinatura do PDF nem a cadeia de certificação. ```ruby verificacao = Assinafy::Client.new.documents.verify('hash-da-assinatura') verificacao['is_valid'] # => true verificacao['agreement_code'] # código impresso no certificado do documento ``` -------------------------------- ### GET /accounts/{id}/webhooks/endpoints/{endpoint_id} Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/webhook_resource.md Retrieves a specific webhook endpoint. ```APIDOC ## [GET] /accounts/{id}/webhooks/endpoints/{endpoint_id} ### Description Retrieves a specific webhook endpoint. ### Method GET ### Endpoint /accounts/{id}/webhooks/endpoints/{endpoint_id} ### Parameters #### Path Parameters - **id** (string) - Required - The account identifier. - **endpoint_id** (string) - Required - The endpoint identifier. ### Response #### Success Response (200) - **endpoint** (object) - The endpoint details. ``` -------------------------------- ### Configuration class attributes and accessors Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/configuration.md Defines the SDK configuration value object. `Client` captures a copy when building the connection, so create a new client after changing configuration. Attributes include `api_key` (sent as `X-Api-Key`), `token` (legacy bearer used when `api_key` is nil), `account_id`, `base_url` (trailing slash stripped), `webhook_secret`, `timeout` (Faraday seconds), and `logger`. ```ruby # @!attribute [rw] api_key # @return [String, nil] sent as `X-Api-Key` # @!attribute [rw] token # @return [String, nil] legacy bearer token (used when `api_key` is nil) # @!attribute [rw] account_id # @return [String, nil] default workspace ID # @!attribute [rw] base_url # @return [String] API base URL (trailing slash stripped) # @!attribute [rw] webhook_secret # @return [String, nil] secret for {Support::WebhookVerifier} # @!attribute [rw] timeout # @return [Integer] Faraday timeout in seconds # @!attribute [rw] logger # @return [Logger, nil] receives SDK lifecycle messages attr_accessor :api_key, :token, :account_id, :webhook_secret, :logger attr_reader :base_url, :timeout ``` -------------------------------- ### get Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/api-reference/template_resource.md Retrieves a single template by ID. Includes default_document_tags which is omitted in list. ```APIDOC ## [GET] /accounts/{account_id}/templates/{template_id} ### Description Retrieves a single template by ID. Includes default_document_tags which is omitted in list. ### Method GET ### Endpoint /accounts/{account_id}/templates/{template_id} ### Parameters #### Path Parameters - **account_id** (string) - Required - The account ID. - **template_id** (string) - Required - The template ID. ### Response #### Success Response (200) - **resource** (string) - Resource type. - **id** (string) - Template ID. - **name** (string) - Template name. - **document_name** (string) - Document name. - **message** (string) - Message. - **status** (string) - Status (e.g., "Ready", "Uploaded"). - **pages** (array) - Array of page objects with id, number, height, width, download_url, fields. - **roles** (array) - Array of role objects with id, name, assignment_type. - **tags** (array) - Array of tags. - **default_document_tags** (array) - Default document tags (only in get). - **created_at** (string) - Creation timestamp. - **updated_at** (string) - Update timestamp. #### Response Example ```json { "resource": "template", "id": "template-id", "name": "Contract", "document_name": "contract.pdf", "message": "Please sign", "status": "Ready", "pages": [], "roles": [], "tags": [], "default_document_tags": [], "created_at": "2023-01-01T00:00:00Z", "updated_at": "2023-01-01T00:00:00Z" } ``` ``` -------------------------------- ### POST /signers/identity-verification Source: https://github.com/assinafy/ruby-sdk/blob/main/_autodocs/endpoints.md Starts identity verification for the current signer. Requires consent. ```APIDOC ## POST /signers/identity-verification ### Description Starts identity verification for the current signer. Requires consent. ### Method POST ### Endpoint `/signers/identity-verification` ### Parameters #### Query Parameters - **signer-access-code** (string) - Required - The signer access code. #### Request Body - **consent** (boolean) - Required - Must be `true` to proceed. ### Request Example ```json { "consent": true } ``` ### Response #### Success Response (200) - **verification** (object) - The started verification. #### Response Example ```json { "verification": {} } ``` ``` -------------------------------- ### Consultar estatísticas da conta com granularidade e mês Source: https://github.com/assinafy/ruby-sdk/blob/main/README.md Usado para obter KPIs de contas com parâmetros de granularidade ('daily' ou 'monthly') e mês no formato 'AAAA-MM', validados localmente. Exemplo: client.accounts.stats(granularity: 'daily', month: '2026-06'). ```ruby client.accounts.stats(granularity: 'daily', month: '2026-06') ```