class SignaturitClient

Signaturit client class

Public Class Methods

new(token, production = false) click to toggle source

Initialize the object with the token and environment

# File lib/signaturit_client.rb, line 11
def initialize(token, production = false)
    base = production ? 'https://api.signaturit.com' : 'https://api.sandbox.signaturit.com'

    @client = RestClient::Resource.new base, :headers => { :Authorization => "Bearer #{token}", :user_agent => 'signaturit-ruby-sdk 1.1.0' }, :ssl_version => :TLSv1_2
end

Public Instance Methods

add_manager_to_group(group_id, user_id) click to toggle source

Add a new manager to the group

Params:

group_id

Id of the group where to add the user

user_id

Id of the user to add

# File lib/signaturit_client.rb, line 523
def add_manager_to_group(group_id, user_id)
    request :post, "/v3/team/groups/#{group_id}/managers/#{user_id}.json"
end
add_member_to_group(group_id, user_id) click to toggle source

Add a new member to the group

Params:

group_id

Id of the group where to add the user

user_id

Id of the user to add

# File lib/signaturit_client.rb, line 541
def add_member_to_group(group_id, user_id)
    request :post, "/v3/team/groups/#{group_id}/members/#{user_id}.json"
end
cancel_signature(signature_id) click to toggle source

Cancel a signature request

Params

signature_id+

The id of the signature object

# File lib/signaturit_client.rb, line 104
def cancel_signature(signature_id)
    request :patch, "/v3/signatures/#{signature_id}/cancel.json"
end
change_user_role(user_id, role) click to toggle source

Update an existing user role

Params:

user_id

Id of the user to update

role

The new role

# File lib/signaturit_client.rb, line 452
def change_user_role(user_id, role)
    params = { role: role }

    request :patch, "/v3/team/users/#{user_id}.json", params
end
count_contacts(conditions = {}) click to toggle source

Count all contacts

Params:

conditions

Query conditions

# File lib/signaturit_client.rb, line 371
def count_contacts(conditions = {})
    params = extract_query_params conditions

    request :get, "/v3/contacts/count.json", params
end
count_emails(conditions = {}) click to toggle source

Count all emails

Params:

conditions

Query conditions

# File lib/signaturit_client.rb, line 176
def count_emails(conditions = {})
    params = extract_query_params conditions

    request :get, "/v3/emails/count.json", params
end
count_signatures(conditions = {}) click to toggle source

Get the number of signature objects

Params:

conditions

Filter conditions

# File lib/signaturit_client.rb, line 44
def count_signatures(conditions = {})
    params = extract_query_params conditions

    request :get, "/v3/signatures/count.json", params
end
count_sms(conditions = {}) click to toggle source

Count all SMS

Params:

conditions

Query conditions

# File lib/signaturit_client.rb, line 243
def count_sms(conditions = {})
    params = extract_query_params conditions

    request :get, "/v3/sms/count.json", params
end
count_subscriptions(conditions = {}) click to toggle source

Count all subscription

Params:

conditions

Query conditions

# File lib/signaturit_client.rb, line 310
def count_subscriptions(conditions = {})
    params = extract_query_params conditions

    request :get, "/v3/subscriptions/count.json", params
end
create_branding(params) click to toggle source

Create a new branding

Params:

params

An array of parameters for the branding object

# File lib/signaturit_client.rb, line 133
def create_branding(params)
    request :post, "/v3/brandings.json", params
end
create_contact(email, name) click to toggle source

Create a new contact

Params:

email

Contact email

name

Contact name

# File lib/signaturit_client.rb, line 390
def create_contact(email, name)
    params = { email: email, name: name }

    request :post, "/v3/contacts.json", params
end
create_email(files, recipients, subject, body, params = {}) click to toggle source

Create a new email

Params:

files

File or files to send with the email

recipients

Recipients for the email

subject

Email subject

body

Email body

params

Extra params

# File lib/signaturit_client.rb, line 198
def create_email(files, recipients, subject, body, params = {})
    params[:recipients] = {}

    [recipients].flatten.each_with_index do |recipient, index|
        params[:recipients][index] = recipient
    end

    params[:files] = [files].flatten.map do |filepath|
        File.new(filepath, 'rb')
    end

    params[:subject] = subject
    params[:body]    = body

    request :post, "/v3/emails.json", params
end
create_group(name) click to toggle source

Create a new group

Params:

name

Group name

# File lib/signaturit_client.rb, line 493
def create_group(name)
    params = { name: name }

    request :post, "/v3/team/groups.json", params
end
create_signature(filepath, recipients, params = {}) click to toggle source

Create a new Signature request

Params:

filepath

The pdf file to send or an array with multiple files.

recipients

A string with an email, a hash like

{:name => “a name”, :email => “me@domain.com”, :phone => “34655123456”} or an array of hashes.

params

An array of parameters for the signature object

# File lib/signaturit_client.rb, line 76
def create_signature(filepath, recipients, params = {})
    params[:recipients] = {}

    [recipients].flatten.each_with_index do |recipient, index|
        # if only email is given, transform it to a object
        recipient = { email: recipient, name: recipient } if recipient.is_a? String

        # workaround for a bug in rest_client not dealing with objects inside an array
        if recipient[:require_signature_in_coordinates]
            recipient[:require_signature_in_coordinates] = array2hash recipient[:require_signature_in_coordinates]
        end

        params[:recipients][index] = recipient
    end

    params[:files] = [filepath].flatten.map do |filepath|
        File.new(filepath, 'rb')
    end

    params[:templates] = [params[:templates]].flatten if params[:templates]

    request :post, "/v3/signatures.json", params
end
create_sms(files, recipients, body, params = {}) click to toggle source

Create a new SMS

Params:

files

File or files to send with the SMS

recipients

Recipients for the SMS

body

SMS body

params

Extra params

# File lib/signaturit_client.rb, line 264
def create_sms(files, recipients, body, params = {})
    params[:recipients] = {}

    [recipients].flatten.each_with_index do |recipient, index|
        params[:recipients][index] = recipient
    end

    if files
        params[:attachments] = [files].flatten.map do |filepath|
            File.new(filepath, 'rb')
        end
    end

    params[:body] = body

    request :post, "/v3/sms.json", params
end
create_subscription(url, events) click to toggle source

Create a new subscription

Params:

url

A url where to send the events.

events

The list of events to subscribe.

# File lib/signaturit_client.rb, line 329
def create_subscription(url, events)
    params = { url: url, events: events }

    request :post, "/v3/subscriptions.json", params
end
delete_contact(contact_id) click to toggle source

Delete an existing contact

Params:

contact_id

Id of the contact to update

# File lib/signaturit_client.rb, line 409
def delete_contact(contact_id)
    request :delete, "/v3/contacts/#{contact_id}.json"
end
delete_group(group_id) click to toggle source

Delete an existing group

Params:

group_id

Id of the group to delete

# File lib/signaturit_client.rb, line 514
def delete_group(group_id)
    request :delete, "/v3/team/groups/#{group_id}.json"
end
delete_subscription(subscription_id) click to toggle source

Delete an existing subscription

Params:

subscription_id

Id of the subscription to update

# File lib/signaturit_client.rb, line 348
def delete_subscription(subscription_id)
    request :delete, "/v3/subscriptions/#{subscription_id}.json"
end
download_audit_trail(signature_id, document_id) click to toggle source

Get the audit trail of concrete document

Params:

signature_id+

The id of the signature object

document_id+

The id of the document object

# File lib/signaturit_client.rb, line 55
def download_audit_trail(signature_id, document_id)
    request :get, "/v3/signatures/#{signature_id}/documents/#{document_id}/download/audit_trail", {}, false
end
download_email_audit_trail(email_id, certificate_id) click to toggle source

Get the audit trail of concrete certificate

Params:

email_id+

The id of the email object

certificate_id+

The id of the certificate object

# File lib/signaturit_client.rb, line 220
def download_email_audit_trail(email_id, certificate_id)
    request :get, "/v3/emails/#{email_id}/certificates/#{certificate_id}/download/audit_trail", {}, false
end
download_signed_document(signature_id, document_id) click to toggle source

Get the signed document

Params:

signature_id+

The id of the signature object

document_id+

The id of the document object

# File lib/signaturit_client.rb, line 64
def download_signed_document(signature_id, document_id)
    request :get, "/v3/signatures/#{signature_id}/documents/#{document_id}/download/signed", {}, false
end
download_sms_audit_trail(sms_id, certificate_id) click to toggle source

Get the audit trail of concrete certificate

Params:

sms_id+

The id of the SMS object

certificate_id+

The id of the certificate object

# File lib/signaturit_client.rb, line 287
def download_sms_audit_trail(sms_id, certificate_id)
    request :get, "/v3/sms/#{sms_id}/certificates/#{certificate_id}/download/audit_trail", {}, false
end
get_branding(branding_id) click to toggle source

Get a concrete branding

Params

branding_id

The id of the branding object

# File lib/signaturit_client.rb, line 120
def get_branding(branding_id)
    request :get, "/v3/brandings/#{branding_id}.json"
end
get_brandings() click to toggle source

Get all account brandings

# File lib/signaturit_client.rb, line 125
def get_brandings
    request :get, "/v3/brandings.json"
end
get_contact(contact_id) click to toggle source

Get a single contact

Params:

contact_id

Id of contact

# File lib/signaturit_client.rb, line 381
def get_contact(contact_id)
    request :get, "/v3/contacts/#{contact_id}.json"
end
get_contacts(limit = 100, offset = 0, conditions = {}) click to toggle source

Get all contacts

Params:

limit

Maximum number of results to return

offset

Offset of results to skip

conditions

Query conditions

# File lib/signaturit_client.rb, line 358
def get_contacts(limit = 100, offset = 0, conditions = {})
    params = extract_query_params conditions

    params['limit']  = limit
    params['offset'] = offset

    request :get, "/v3/contacts.json", params
end
get_email(email_id) click to toggle source

Get a single email

Params:

email_id

Id of email

# File lib/signaturit_client.rb, line 186
def get_email(email_id)
    request :get, "/v3/emails/#{email_id}.json"
end
get_emails(limit = 100, offset = 0, conditions = {}) click to toggle source

Get all emails

Params:

limit

Maximum number of results to return

offset

Offset of results to skip

conditions

Query conditions

# File lib/signaturit_client.rb, line 163
def get_emails(limit = 100, offset = 0, conditions = {})
    params = extract_query_params conditions

    params['limit']  = limit
    params['offset'] = offset

    request :get, "/v3/emails.json", params
end
get_group(group_id) click to toggle source

Get a single group

Params:

group_id

Id of group

# File lib/signaturit_client.rb, line 485
def get_group(group_id)
    request :get, "/v3/team/groups/#{group_id}.json"
end
get_groups(limit = 100, offset = 0, conditions = {}) click to toggle source

Get all groups

Params:

limit

Maximum number of results to return

offset

Offset of results to skip

conditions

Query conditions

# File lib/signaturit_client.rb, line 472
def get_groups(limit = 100, offset = 0, conditions = {})
    params = extract_query_params conditions

    params['limit']  = limit
    params['offset'] = offset

    request :get, "/v3/team/groups.json", params
end
get_seats(limit = 100, offset = 0, conditions = {}) click to toggle source

Get all seats

Params:

limit

Maximum number of results to return

offset

Offset of results to skip

conditions

Query conditions

# File lib/signaturit_client.rb, line 560
def get_seats(limit = 100, offset = 0, conditions = {})
    params = extract_query_params conditions

    params['limit']  = limit
    params['offset'] = offset

    request :get, "/v3/team/seats.json", params
end
get_signature(signature_id) click to toggle source

Get a concrete signature object

Params:

signature_id

The id of the signature object

# File lib/signaturit_client.rb, line 21
def get_signature(signature_id)
    request :get, "/v3/signatures/#{signature_id}.json"
end
get_signatures(limit = 100, offset = 0, conditions = {}) click to toggle source

Get a list of signature objects

Params:

limit

Maximum number of results to return

offset

Offset of results to skip

conditions

Filter conditions

# File lib/signaturit_client.rb, line 31
def get_signatures(limit = 100, offset = 0, conditions = {})
    params = extract_query_params conditions

    params['limit']  = limit
    params['offset'] = offset

    request :get, "/v3/signatures.json", params
end
get_single_sms(sms_id) click to toggle source

Get a single SMS

Params:

sms_id

Id of SMS

# File lib/signaturit_client.rb, line 253
def get_single_sms(sms_id)
    request :get, "/v3/sms/#{sms_id}.json"
end
get_sms(limit = 100, offset = 0, conditions = {}) click to toggle source

Get all SMS

Params:

limit

Maximum number of results to return

offset

Offset of results to skip

conditions

Query conditions

# File lib/signaturit_client.rb, line 230
def get_sms(limit = 100, offset = 0, conditions = {})
    params = extract_query_params conditions

    params['limit']  = limit
    params['offset'] = offset

    request :get, "/v3/sms.json", params
end
get_subscription(subscription_id) click to toggle source

Get a single subscription

Params:

subscription_id

Id of subscription

# File lib/signaturit_client.rb, line 320
def get_subscription(subscription_id)
    request :get, "/v3/subscriptions/#{subscription_id}.json"
end
get_subscriptions(limit = 100, offset = 0, conditions = {}) click to toggle source

Get all subscription

Params:

limit

Maximum number of results to return

offset

Offset of results to skip

conditions

Query conditions

# File lib/signaturit_client.rb, line 297
def get_subscriptions(limit = 100, offset = 0, conditions = {})
    params = extract_query_params conditions

    params['limit']  = limit
    params['offset'] = offset

    request :get, "/v3/subscriptions.json", params
end
get_templates(limit = 100, offset = 0) click to toggle source

Get a list of template objects

Params:

limit

Maximum number of results to return

offset

Offset of results to skip

# File lib/signaturit_client.rb, line 151
def get_templates(limit = 100, offset = 0)
    params = { :limit => limit, :offset => offset }

    request :get, "/v3/templates.json", params
end
get_user(user_id) click to toggle source

Get a single user

Params:

user_id

Id of user

# File lib/signaturit_client.rb, line 432
def get_user(user_id)
    request :get, "/v3/team/users/#{user_id}.json"
end
get_users(limit = 100, offset = 0, conditions = {}) click to toggle source

Get all users

Params:

limit

Maximum number of results to return

offset

Offset of results to skip

conditions

Query conditions

# File lib/signaturit_client.rb, line 419
def get_users(limit = 100, offset = 0, conditions = {})
    params = extract_query_params conditions

    params['limit']  = limit
    params['offset'] = offset

    request :get, "/v3/team/users.json", params
end
invite_user(email, role) click to toggle source

Invites a user to the team

Params:

email

User email

role

User role

# File lib/signaturit_client.rb, line 441
def invite_user(email, role)
    params = { email: email, role: role }

    request :post, "/v3/team/users.json", params
end
remove_manager_from_group(group_id, user_id) click to toggle source

Remove a manager from the group

Params:

group_id

Id of the group where to add the user

user_id

Id of the user to add

# File lib/signaturit_client.rb, line 532
def remove_manager_from_group(group_id, user_id)
    request :delete, "/v3/team/groups/#{group_id}/managers/#{user_id}.json"
end
remove_member_from_group(group_id, user_id) click to toggle source

Remove a member from the group

Params:

group_id

Id of the group where to add the user

user_id

Id of the user to add

# File lib/signaturit_client.rb, line 550
def remove_member_from_group(group_id, user_id)
    request :delete, "/v3/team/groups/#{group_id}/members/#{user_id}.json"
end
remove_seat(seat_id) click to toggle source

Remove a seat

Params:

seat_id

Id of the seat to remove

# File lib/signaturit_client.rb, line 573
def remove_seat(seat_id)
    request :delete, "/v3/team/seats/#{seat_id}.json"
end
remove_user(user_id) click to toggle source

Delete an existing user from the team

Params:

user_id

Id of the user to remove

# File lib/signaturit_client.rb, line 462
def remove_user(user_id)
    request :delete, "/v3/team/users/#{user_id}.json"
end
send_signature_reminder(signature_id) click to toggle source

Send a reminder for the given signature request document

Param

signature_id+

The id of the signature object

# File lib/signaturit_client.rb, line 112
def send_signature_reminder(signature_id)
    request :post, "/v3/signatures/#{signature_id}/reminder.json"
end
update_branding(branding_id, params) click to toggle source

Update an existing branding

Params:

branding_id

Id of the branding to update

params

Same params as method create_branding, see above

# File lib/signaturit_client.rb, line 142
def update_branding(branding_id, params)
    request :patch, "/v3/brandings/#{branding_id}.json", params
end
update_contact(contact_id, params) click to toggle source

Update an existing contact

Params:

contact_id

Id of the contact to update

params

Same params as method create_contact, see above

# File lib/signaturit_client.rb, line 401
def update_contact(contact_id, params)
    request :patch, "/v3/contacts/#{contact_id}.json", params
end
update_group(group_id, name) click to toggle source

Update an existing group

Params:

group_id

Id of the group to update

params

Same params as method create_group, see above

# File lib/signaturit_client.rb, line 504
def update_group(group_id, name)
    params = { name: name }

    request :patch, "/v3/team/groups/#{group_id}.json", params
end
update_subscription(subscription_id, params) click to toggle source

Update an existing subscription

Params:

subscription_id

Id of the subscription to update

params

Same params as method create_subscription, see above

# File lib/signaturit_client.rb, line 340
def update_subscription(subscription_id, params)
    request :patch, "/v3/subscriptions/#{subscription_id}.json", params
end

Private Instance Methods

array2hash(array) click to toggle source

convert array to hash recursively

# File lib/signaturit_client.rb, line 581
def array2hash(array)
    unless array.is_a?(Array)
        return array
    end

    Hash[
        array.map.with_index do |x, i|
            if x.is_a?(Array)
                x = array2hash(x)
            end

            [i, x]
        end
    ]
end
extract_query_params(conditions) click to toggle source

Parse query parameters

# File lib/signaturit_client.rb, line 598
def extract_query_params(conditions)
    params = {}

    conditions.each do |key, value|
        if key == 'ids'
            value = value.join(',')
        end

        params[key] = value
    end

    params
end
request(method, path, params = {}, to_json = true) click to toggle source

Common request method

# File lib/signaturit_client.rb, line 613
def request(method, path, params = {}, to_json = true)
    case method
        when :get, :delete
            encoded = URI.encode_www_form(params)

            path = "#{path}?#{encoded}" if encoded.length > 0

            body = @client[path].send method

        else
            body = @client[path].send method, params
    end

    body = JSON.parse body if to_json

    body
end