class RS4::Document

A prepared document populates a reusable template with merge field values. The Document object is used to deserialize the JSON response

Constants

EXECUTED_STATE
INVESTOR_ROLE
ISSUER_ROLE

Attributes

audits[RW]
current_signer_id[RW]
embed_codes[RW]
executed_at[RW]
expired_at[RW]
filename[RW]
id[RW]
identity_method[RW]
in_person[RW]
merge_field_values[RW]
name[RW]
original_file_url[RW]
original_guid[RW]
page_image_urls[RW]
passcode_pin_enabled[RW]
recipients[RW]
sender[RW]
sent_at[RW]
shared_with[RW]
signed_pdf_url[RW]
state[RW]
tags[RW]
thumbnail_url[RW]

Public Class Methods

get_archive_document(document_guid) click to toggle source
# File lib/rs4/document.rb, line 86
def get_archive_document(document_guid)
  return unless document_guid.present?

  path = "/public/v1/archived_documents_by_original_guid/#{document_guid}"

  response = RS4.configuration.request_handler.execute(path, :get)

  unless response.is_a?(RS4::Error) || response.nil?
    archived_document = response.dig(:archived_document)

    Document.new(archived_document) if archived_document
  end
end
get_document(document_guid) click to toggle source
# File lib/rs4/document.rb, line 100
def get_document(document_guid)
  return unless document_guid.present?

  path = "/public/v1/documents/#{document_guid}"

  response = RS4.configuration.request_handler.execute(path, :get)

  unless response.is_a?(RS4::Error) || response.nil? # .class == Net::HTTPOK
    raw_document = response.dig(:document) # JSON.parse(response.body, symbolize_names: true)

    # Document.new(raw_document[:document])
    Document.new(raw_document) if raw_document
  end
end
get_documents() click to toggle source
# File lib/rs4/document.rb, line 115
def get_documents
  path = '/public/v1/documents'
  response = RS4.configuration.request_handler.execute(path, :get)

  unless response.is_a?(RS4::Error) || response.nil?
    documents = []

    response.dig(:documents).each do |document_hash|
      # document_hash = raw_document.pluck(:document)
      documents << Document.new(document_hash)
    end
  end

  documents
end
new(document_args = {}) click to toggle source
# File lib/rs4/document.rb, line 35
def initialize(document_args = {})
  @id = document_args[:id]
  @current_signer_id = document_args[:current_signer_id]
  @name = document_args[:name]
  @filename = document_args[:filename]
  @executed_at = document_args[:executed_at]
  @expired_at = document_args[:expired_at]
  @sent_at = document_args[:sent_at]
  @state = document_args[:state]
  @thumbnail_url = document_args[:thumbnail_url]
  @sender = document_args[:sender]
  @recipients = document_args[:recipients]
  @audits = document_args[:audits]
  @page_image_urls = document_args[:page_image_urls]
  @signed_pdf_url = document_args[:signed_pdf_url]
  @tags = document_args[:tags]
  @merge_field_values = document_args[:merge_field_values]
  @embed_codes = document_args[:embed_codes]
  @in_person = document_args[:in_person]
  @shared_with = document_args[:shared_with]
  @identity_method = document_args[:identity_method]
  @passcode_pin_enabled = document_args[:passcode_pin_enabled]
  @original_file_url = document_args[:original_file_url]
end

Public Instance Methods

get_signer_urls(roles = []) click to toggle source

There may be more than one signer URL associated with a given document. The exact amount depends on the template configuration: how many roles have been created.

For example, POA agreement will have two unique sign URLs and they must be delivered to their intended individual

# File lib/rs4/document.rb, line 66
def get_signer_urls(roles = [])
  signer_urls = {}

  filtered_recipients = roles.none? ? @recipients : @recipients.select { |role| roles.include? role[:role_name].to_sym }

  filtered_recipients.each do |recipient|
    role_name = recipient.dig(:role_name)
    sign_url = recipient.dig(:sign_url)

    if role_name
      signer_urls[role_name.to_sym] = sign_url
    else
      Rails.logger.error("No role name found. #{recipient.inspect}")
    end
  end

  signer_urls
end