Class: SignaturitClient

Inherits:
Object
  • Object
show all
Defined in:
lib/signaturit_client.rb

Overview

Signaturit client class

Instance Method Summary collapse

Constructor Details

#initialize(token, production = false) ⇒ SignaturitClient

Initialize the object with the token and environment



11
12
13
14
15
# 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

Instance Method Details

#add_manager_to_group(group_id, user_id) ⇒ Object

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



523
524
525
# 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) ⇒ Object

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



541
542
543
# 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) ⇒ Object

Cancel a signature request

Params

signature_id+

The id of the signature object



104
105
106
# 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) ⇒ Object

Update an existing user role

Params:

user_id

Id of the user to update

role

The new role



452
453
454
455
456
# 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 = {}) ⇒ Object

Count all contacts

Params:

conditions

Query conditions



371
372
373
374
375
# 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 = {}) ⇒ Object

Count all emails

Params:

conditions

Query conditions



176
177
178
179
180
# 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 = {}) ⇒ Object

Get the number of signature objects

Params:

conditions

Filter conditions



44
45
46
47
48
# 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 = {}) ⇒ Object

Count all SMS

Params:

conditions

Query conditions



243
244
245
246
247
# 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 = {}) ⇒ Object

Count all subscription

Params:

conditions

Query conditions



310
311
312
313
314
# 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) ⇒ Object

Create a new branding

Params:

params

An array of parameters for the branding object



133
134
135
# File 'lib/signaturit_client.rb', line 133

def create_branding(params)
    request :post, "/v3/brandings.json", params
end

#create_contact(email, name) ⇒ Object

Create a new contact

Params:

email

Contact email

name

Contact name



390
391
392
393
394
# 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 = {}) ⇒ Object

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



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# 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) ⇒ Object

Create a new group

Params:

name

Group name



493
494
495
496
497
# 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 = {}) ⇒ Object

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

=> “a name”, :email => “[email protected]”, :phone => “34655123456” or an array of hashes.

params

An array of parameters for the signature object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# 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 = {}) ⇒ Object

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



264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# 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) ⇒ Object

Create a new subscription

Params:

url

A url where to send the events.

events

The list of events to subscribe.



329
330
331
332
333
# 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) ⇒ Object

Delete an existing contact

Params:

contact_id

Id of the contact to update



409
410
411
# File 'lib/signaturit_client.rb', line 409

def delete_contact(contact_id)
    request :delete, "/v3/contacts/#{contact_id}.json"
end

#delete_group(group_id) ⇒ Object

Delete an existing group

Params:

group_id

Id of the group to delete



514
515
516
# 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) ⇒ Object

Delete an existing subscription

Params:

subscription_id

Id of the subscription to update



348
349
350
# 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) ⇒ Object

Get the audit trail of concrete document

Params:

signature_id+

The id of the signature object

document_id+

The id of the document object



55
56
57
# 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) ⇒ Object

Get the audit trail of concrete certificate

Params:

email_id+

The id of the email object

certificate_id+

The id of the certificate object



220
221
222
# 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) ⇒ Object

Get the signed document

Params:

signature_id+

The id of the signature object

document_id+

The id of the document object



64
65
66
# 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) ⇒ Object

Get the audit trail of concrete certificate

Params:

sms_id+

The id of the SMS object

certificate_id+

The id of the certificate object



287
288
289
# 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) ⇒ Object

Get a concrete branding

Params

branding_id

The id of the branding object



120
121
122
# File 'lib/signaturit_client.rb', line 120

def get_branding(branding_id)
    request :get, "/v3/brandings/#{branding_id}.json"
end

#get_brandingsObject

Get all account brandings



125
126
127
# File 'lib/signaturit_client.rb', line 125

def get_brandings
    request :get, "/v3/brandings.json"
end

#get_contact(contact_id) ⇒ Object

Get a single contact

Params:

contact_id

Id of contact



381
382
383
# 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 = {}) ⇒ Object

Get all contacts

Params:

limit

Maximum number of results to return

offset

Offset of results to skip

conditions

Query conditions



358
359
360
361
362
363
364
365
# 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) ⇒ Object

Get a single email

Params:

email_id

Id of email



186
187
188
# 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 = {}) ⇒ Object

Get all emails

Params:

limit

Maximum number of results to return

offset

Offset of results to skip

conditions

Query conditions



163
164
165
166
167
168
169
170
# 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) ⇒ Object

Get a single group

Params:

group_id

Id of group



485
486
487
# 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 = {}) ⇒ Object

Get all groups

Params:

limit

Maximum number of results to return

offset

Offset of results to skip

conditions

Query conditions



472
473
474
475
476
477
478
479
# 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 = {}) ⇒ Object

Get all seats

Params:

limit

Maximum number of results to return

offset

Offset of results to skip

conditions

Query conditions



560
561
562
563
564
565
566
567
# 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) ⇒ Object

Get a concrete signature object

Params:

signature_id

The id of the signature object



21
22
23
# 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 = {}) ⇒ Object

Get a list of signature objects

Params:

limit

Maximum number of results to return

offset

Offset of results to skip

conditions

Filter conditions



31
32
33
34
35
36
37
38
# 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) ⇒ Object

Get a single SMS

Params:

sms_id

Id of SMS



253
254
255
# 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 = {}) ⇒ Object

Get all SMS

Params:

limit

Maximum number of results to return

offset

Offset of results to skip

conditions

Query conditions



230
231
232
233
234
235
236
237
# 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) ⇒ Object

Get a single subscription

Params:

subscription_id

Id of subscription



320
321
322
# 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 = {}) ⇒ Object

Get all subscription

Params:

limit

Maximum number of results to return

offset

Offset of results to skip

conditions

Query conditions



297
298
299
300
301
302
303
304
# 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) ⇒ Object

Get a list of template objects

Params:

limit

Maximum number of results to return

offset

Offset of results to skip



151
152
153
154
155
# 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) ⇒ Object

Get a single user

Params:

user_id

Id of user



432
433
434
# 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 = {}) ⇒ Object

Get all users

Params:

limit

Maximum number of results to return

offset

Offset of results to skip

conditions

Query conditions



419
420
421
422
423
424
425
426
# 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) ⇒ Object

Invites a user to the team

Params:

email

User email

role

User role



441
442
443
444
445
# 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) ⇒ Object

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



532
533
534
# 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) ⇒ Object

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



550
551
552
# 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) ⇒ Object

Remove a seat

Params:

seat_id

Id of the seat to remove



573
574
575
# 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) ⇒ Object

Delete an existing user from the team

Params:

user_id

Id of the user to remove



462
463
464
# 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) ⇒ Object

Send a reminder for the given signature request document

Param

signature_id+

The id of the signature object



112
113
114
# 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) ⇒ Object

Update an existing branding

Params:

branding_id

Id of the branding to update

params

Same params as method create_branding, see above



142
143
144
# 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) ⇒ Object

Update an existing contact

Params:

contact_id

Id of the contact to update

params

Same params as method create_contact, see above



401
402
403
# 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) ⇒ Object

Update an existing group

Params:

group_id

Id of the group to update

params

Same params as method create_group, see above



504
505
506
507
508
# 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) ⇒ Object

Update an existing subscription

Params:

subscription_id

Id of the subscription to update

params

Same params as method create_subscription, see above



340
341
342
# File 'lib/signaturit_client.rb', line 340

def update_subscription(subscription_id, params)
    request :patch, "/v3/subscriptions/#{subscription_id}.json", params
end