Skip to content

Commit 2089392

Browse files
Merge branch 'master' of github.com:docusign/code-examples-ruby-private
2 parents 7a50747 + 5a296be commit 2089392

File tree

12 files changed

+423
-26
lines changed

12 files changed

+423
-26
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ group :test do
6666
gem 'chromedriver-helper', '~> 2.1.1'
6767
end
6868

69-
gem 'docusign_esign', '~> 3.14.0'
69+
gem 'docusign_esign', '~> 3.15.0'
7070
gem 'docusign_monitor', '~> 1.0.0'
7171
gem 'docusign_rooms', '~> 1.2.0.rc1'
7272
gem 'docusign_click', '~> 1.0.0'
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# frozen_string_literal: true
2+
3+
class ESign::Eg035ScheduledSendingController < EgController
4+
before_action :check_auth
5+
6+
def create
7+
begin
8+
envelope_args = {
9+
signer_email: param_gsub(params['signer_email']),
10+
signer_name: param_gsub(params['signer_name']),
11+
resume_date: param_gsub(params['resume_date']),
12+
status: 'sent'
13+
}
14+
args = {
15+
account_id: session['ds_account_id'],
16+
base_path: session['ds_base_path'],
17+
access_token: session['ds_access_token'],
18+
envelope_args: envelope_args
19+
}
20+
results = ESign::Eg035ScheduledSendingService.new(args).worker
21+
session[:envelope_id] = results['envelope_id']
22+
@title = 'Envelope scheduled'
23+
@h1 = 'Envelope scheduled'
24+
@message = "The envelope has been created and scheduled!<br/>Envelope ID #{results['envelope_id']}."
25+
render 'ds_common/example_done'
26+
rescue DocuSign_eSign::ApiError => e
27+
handle_error(e)
28+
end
29+
end
30+
end
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# frozen_string_literal: true
2+
3+
class ESign::Eg036DelayedRoutingController < EgController
4+
before_action :check_auth
5+
6+
def create
7+
begin
8+
envelope_args = {
9+
signer1_email: param_gsub(params['signer1Email']),
10+
signer1_name: param_gsub(params['signer1Name']),
11+
signer2_email: param_gsub(params['signer2Email']),
12+
signer2_name: param_gsub(params['signer2Name']),
13+
delay: param_gsub(params['delay']),
14+
status: 'sent'
15+
}
16+
args = {
17+
account_id: session['ds_account_id'],
18+
base_path: session['ds_base_path'],
19+
access_token: session['ds_access_token'],
20+
envelope_args: envelope_args
21+
}
22+
results = ESign::Eg036DelayedRoutingService.new(args).worker
23+
session[:envelope_id] = results['envelope_id']
24+
@title = 'Envelope sent'
25+
@h1 = 'Envelope sent'
26+
@message = "The envelope has been created and sent!<br/>Envelope ID #{results['envelope_id']}."
27+
render 'ds_common/example_done'
28+
rescue DocuSign_eSign::ApiError => e
29+
handle_error(e)
30+
end
31+
end
32+
end

app/controllers/e_sign/eg035_sms_delivery_controller.rb renamed to app/controllers/e_sign/eg037_sms_delivery_controller.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
class ESign::Eg035SmsDeliveryController < EgController
3+
class ESign::Eg037SmsDeliveryController < EgController
44
before_action :check_auth
55

66
def create
@@ -23,7 +23,7 @@ def create
2323
envelope_args: envelope_args
2424
}
2525

26-
results = ESign::Eg035SmsDeliveryService.new(args).worker
26+
results = ESign::Eg037SmsDeliveryService.new(args).worker
2727
session[:envelope_id] = results['envelope_id']
2828
@title = 'Envelope sent'
2929
@h1 = 'Envelope sent'
@@ -34,4 +34,3 @@ def create
3434
end
3535
end
3636
end
37-
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# frozen_string_literal: true
2+
3+
class ESign::Eg035ScheduledSendingService
4+
attr_reader :args
5+
include ApiCreator
6+
7+
def initialize(args)
8+
@args = args
9+
end
10+
11+
def worker
12+
# 1. Create the envelope request object
13+
envelope_definition = make_envelope args[:envelope_args]
14+
# 2. Call Envelopes::create API method
15+
# Exceptions will be caught by the calling function
16+
envelope_api = create_envelope_api(args)
17+
18+
results = envelope_api.create_envelope args[:account_id], envelope_definition
19+
envelope_id = results.envelope_id
20+
{ 'envelope_id' => envelope_id }
21+
end
22+
23+
private
24+
25+
def make_envelope(envelope_args)
26+
# document (PDF) has tag /sn1/
27+
# The envelope has one recipient
28+
29+
# Create the envelope definition
30+
envelope_definition = DocuSign_eSign::EnvelopeDefinition.new
31+
32+
envelope_definition.email_subject = 'Please sign this document'
33+
34+
# Add the document
35+
# Read file from a local directory
36+
# The reads could raise an exception if the file is not available!
37+
doc_pdf = Rails.application.config.doc_pdf
38+
doc_b64 = Base64.encode64(File.binread(File.join('data', doc_pdf)))
39+
40+
# Create the document model
41+
document = DocuSign_eSign::Document.new(
42+
# Create the DocuSign document object
43+
documentBase64: doc_b64,
44+
name: 'Lorem Ipsum', # Can be different from actual file name
45+
fileExtension: 'pdf', # Many different document types are accepted
46+
documentId: '1' # A label used to reference the doc
47+
)
48+
49+
# The order in the docs array determines the order in the envelope
50+
envelope_definition.documents = [document]
51+
52+
# Create the signer recipient model
53+
signer1 = DocuSign_eSign::Signer.new
54+
signer1.email = envelope_args[:signer_email]
55+
signer1.name = envelope_args[:signer_name]
56+
signer1.recipient_id = '1'
57+
signer1.routing_order = '1'
58+
## routingOrder (lower means earlier) determines the order of deliveries
59+
# to the recipients. Parallel routing order is supported by using the
60+
# same integer as the order for two or more recipients
61+
62+
# Create a signHere field (also known as a tab) on the document
63+
# We're using anchor (autoPlace) positioning
64+
#
65+
# The DocuSign platform searches throughout your envelope's documents for matching
66+
# anchor strings.
67+
sign_here = DocuSign_eSign::SignHere.new(
68+
anchorString: '/sn1/',
69+
anchorYOffset: '10',
70+
anchorUnits: 'pixels',
71+
anchorXOffset: '20'
72+
)
73+
# Add the tabs model (including the sign_here tabs) to the signer
74+
# The Tabs object takes arrays of the different field/tab types
75+
signer1_tabs = DocuSign_eSign::Tabs.new({
76+
signHereTabs: [sign_here]
77+
})
78+
79+
signer1.tabs = signer1_tabs
80+
81+
# Add the recipients to the envelope object
82+
recipients = DocuSign_eSign::Recipients.new(
83+
signers: [signer1]
84+
)
85+
envelope_definition.recipients = recipients
86+
87+
# Create recipientRules model
88+
rule = DocuSign_eSign::EnvelopeDelayRuleApiModel.new(
89+
resumeDate: envelope_args[:resume_date].to_s
90+
)
91+
92+
scheduled_sending = DocuSign_eSign::ScheduledSendingApiModel.new(
93+
status: "pending",
94+
rules: [rule]
95+
)
96+
97+
workflow = DocuSign_eSign::Workflow.new(scheduledSending: scheduled_sending)
98+
# Add the workflow to the envelope object
99+
envelope_definition.workflow = workflow
100+
101+
# Request that the envelope be sent by setting status to "sent".
102+
# To request that the envelope be created as a draft, set status to "created"
103+
envelope_definition.status = envelope_args[:status]
104+
envelope_definition
105+
end
106+
end
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# frozen_string_literal: true
2+
3+
class ESign::Eg036DelayedRoutingService
4+
attr_reader :args
5+
include ApiCreator
6+
7+
def initialize(args)
8+
@args = args
9+
end
10+
11+
def worker
12+
# 1. Create the envelope request object
13+
envelope_definition = make_envelope args[:envelope_args]
14+
# 2. Call Envelopes::create API method
15+
# Exceptions will be caught by the calling function
16+
envelope_api = create_envelope_api(args)
17+
18+
results = envelope_api.create_envelope args[:account_id], envelope_definition
19+
envelope_id = results.envelope_id
20+
{ 'envelope_id' => envelope_id }
21+
end
22+
23+
private
24+
25+
def make_envelope(envelope_args)
26+
27+
# Create the envelope definition
28+
envelope_definition = DocuSign_eSign::EnvelopeDefinition.new
29+
30+
envelope_definition.email_subject = 'Please sign this document'
31+
32+
# Add the document
33+
# Read file from a local directory
34+
# The reads could raise an exception if the file is not available!
35+
doc_pdf = Rails.application.config.doc_pdf
36+
doc_b64 = Base64.encode64(File.binread(File.join('data', doc_pdf)))
37+
38+
# Create the document model
39+
document = DocuSign_eSign::Document.new(
40+
# Create the DocuSign document object
41+
documentBase64: doc_b64,
42+
name: 'Lorem Ipsum', # Can be different from actual file name
43+
fileExtension: 'pdf', # Many different document types are accepted
44+
documentId: '1' # A label used to reference the doc
45+
)
46+
47+
# The order in the docs array determines the order in the envelope
48+
envelope_definition.documents = [document]
49+
50+
# Create the signer recipient model
51+
signer1 = DocuSign_eSign::Signer.new
52+
signer1.email = envelope_args[:signer1_email]
53+
signer1.name = envelope_args[:signer1_name]
54+
signer1.recipient_id = '1'
55+
signer1.routing_order = '1'
56+
## routingOrder (lower means earlier) determines the order of deliveries
57+
# to the recipients. Parallel routing order is supported by using the
58+
# same integer as the order for two or more recipients
59+
60+
signer2 = DocuSign_eSign::Signer.new
61+
signer2.email = envelope_args[:signer2_email]
62+
signer2.name = envelope_args[:signer2_name]
63+
signer2.recipient_id = '2'
64+
signer2.routing_order = '2'
65+
66+
# Create signHere fields (also known as tabs) on the document
67+
# We're using anchor (autoPlace) positioning for the sign_here1 tab
68+
# and we're using absolute positioning for the sign_here2 tab.
69+
#
70+
# The DocuSign platform searches throughout your envelope's documents for matching
71+
# anchor strings.
72+
sign_here1 = DocuSign_eSign::SignHere.new(
73+
anchorString: '/sn1/',
74+
anchorYOffset: '10',
75+
anchorUnits: 'pixels',
76+
anchorXOffset: '20'
77+
)
78+
79+
sign_here2 = DocuSign_eSign::SignHere.new(
80+
xPosition: "320",
81+
yPosition: "175",
82+
pageNumber: "1",
83+
documentId: "1"
84+
)
85+
86+
# Add the tabs model (including the sign_here tabs) to the signer
87+
# The Tabs object takes arrays of the different field/tab types
88+
signer1_tabs = DocuSign_eSign::Tabs.new({
89+
signHereTabs: [sign_here1]
90+
})
91+
92+
signer2_tabs = DocuSign_eSign::Tabs.new({
93+
signHereTabs: [sign_here2]
94+
})
95+
96+
signer1.tabs = signer1_tabs
97+
signer2.tabs = signer2_tabs
98+
99+
# Add the recipients to the envelope object
100+
recipients = DocuSign_eSign::Recipients.new(
101+
signers: [signer1, signer2]
102+
)
103+
104+
envelope_definition.recipients = recipients
105+
106+
# Create recipientRules model
107+
delay_time = "0." + envelope_args[:delay].to_s + ":00:00";
108+
rule = DocuSign_eSign::EnvelopeDelayRuleApiModel.new(delay: delay_time)
109+
110+
delayed_routing = DocuSign_eSign::DelayedRoutingApiModel.new(rules: [rule])
111+
112+
# Create a workflow model
113+
workflow_step = DocuSign_eSign::WorkflowStep.new(
114+
action: 'pause_before',
115+
triggerOnItem: 'routing_order',
116+
itemId: 2,
117+
status: 'pending',
118+
delayedRouting: delayed_routing
119+
)
120+
workflow = DocuSign_eSign::Workflow.new(workflowSteps: [workflow_step])
121+
# Add the workflow to the envelope object
122+
envelope_definition.workflow = workflow
123+
124+
# Request that the envelope be sent by setting status to "sent".
125+
# To request that the envelope be created as a draft, set status to "created"
126+
envelope_definition.status = envelope_args[:status]
127+
envelope_definition
128+
end
129+
end

0 commit comments

Comments
 (0)