forked from docusign/code-examples-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eg019_service.rb
78 lines (68 loc) · 2.71 KB
/
eg019_service.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# frozen_string_literal: true
class ESign::Eg019Service
include ApiCreator
attr_reader :args, :envelope_args, :request, :session
def initialize(request, session)
@envelope_args = {
signer_email: request.params['signerEmail'].gsub(/([^\w \-\@\.\,])+/, ''),
signer_name: request.params['signerName'].gsub(/([^\w \-\@\.\,])+/, ''),
status: 'sent'
}
@args = {
account_id: session['ds_account_id'],
base_path: session['ds_base_path'],
access_token: session['ds_access_token'],
envelope_args: @envelope_args
}
@request = request
@session = session
end
def call
# ***DS.snippet.0.start
envelope_api = create_envelope_api(args)
# Step 3: Construct your envelope JSON body
envelope_definition = DocuSign_eSign::EnvelopeDefinition.new
envelope_definition.email_subject = 'Please sign this document set'
# Add the documents and create the document models
pdf_filename = 'World_Wide_Corp_lorem.pdf'
document1 = DocuSign_eSign::Document.new(
# Create the DocuSign Document object
documentBase64: Base64.encode64(File.binread(File.join('data', pdf_filename))),
name: 'NDA', # Can be different from actual file name
fileExtension: 'pdf', # Many different document types are accepted
documentId: '1' # A label used to reference the doc
)
envelope_definition.documents = [document1]
# Create the signer recipient model
signer1 = DocuSign_eSign::Signer.new
signer1.email = envelope_args[:signer_email]
signer1.name = envelope_args[:signer_name]
signer1.recipient_id = '1'
signer1.routing_order = '1'
signer1.access_code = request.params['accessCode']
sign_here1 = DocuSign_eSign::SignHere.new
sign_here1.anchor_string = '/sn1/'
sign_here1.anchor_units = 'pixels'
sign_here1.anchor_x_offset = '20'
sign_here1.anchor_y_offset = '10'
# Add the tabs model (including the sign_here tabs) to the signer
# The Tabs object takes arrays of the different field/tab types
signer1_tabs = DocuSign_eSign::Tabs.new ({
signHereTabs: [sign_here1]
})
signer1.tabs = signer1_tabs
# Add the recipients to the Envelope object
recipients = DocuSign_eSign::Recipients.new(
signers: [signer1]
)
# Request that the envelope be sent by setting |status| to "sent"
# To request that the envelope be created as a draft, set to "created"
envelope_definition.recipients = recipients
envelope_definition.status = envelope_args[:status]
# Step 4. Call the eSignature REST API
results = envelope_api.create_envelope(args[:account_id], envelope_definition)
session[:envelope_id] = results.envelope_id
results
# ***DS.snippet.0.end
end
end