From 81bf9a4fae6a10b21d7adea744258c5a1a32bc73 Mon Sep 17 00:00:00 2001 From: Mike Pence Date: Wed, 6 Nov 2013 21:53:56 -0500 Subject: [PATCH 1/6] Delete envelope recipient Conflicts: lib/docusign_rest/client.rb test/docusign_rest/client_test.rb --- lib/docusign_rest/client.rb | 27 ++++++++++++++++++++++++++- test/docusign_rest/client_test.rb | 2 +- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/docusign_rest/client.rb b/lib/docusign_rest/client.rb index cd24ffb5..a9bd158a 100644 --- a/lib/docusign_rest/client.rb +++ b/lib/docusign_rest/client.rb @@ -789,7 +789,7 @@ def get_console_view(options={}) # # include_tabs - boolean, determines if the tabs for each signer will be # returned in the response, defaults to false. - # envelope_id - ID of the envelope for which you want to retrive the + # envelope_id - ID of the envelope for which you want to retrieve the # signer info # headers - optional hash of headers to merge into the existing # required headers for a multipart request. @@ -1067,5 +1067,30 @@ def get_envelope(envelope_id) response = http.request(request) JSON.parse(response.body) end + + # Public deletes a recipient for a given envelope + # + # envelope_id - ID of the envelope for which you want to retrieve the + # signer info + # recipient_id - ID of the recipient to delete + # + # Returns a hash of recipients with an error code for any recipients that + # were not successfully deleted. + def delete_envelope_recipient(options={}) + content_type = {'Content-Type' => 'application/json'} + content_type.merge(options[:headers]) if options[:headers] + + uri = build_uri("/accounts/#{@acct_id}/envelopes/#{options[:envelope_id]}/recipients") + post_body = "{ + \"signers\" : [{\"recipientId\" : \"#{options[:recipient_id]}\"}] + }" + + http = initialize_net_http_ssl(uri) + request = Net::HTTP::Delete.new(uri.request_uri, headers(content_type)) + request.body = post_body + + response = http.request(request) + parsed_response = JSON.parse(response.body) + end end end diff --git a/test/docusign_rest/client_test.rb b/test/docusign_rest/client_test.rb index bfc122c5..b028694d 100644 --- a/test/docusign_rest/client_test.rb +++ b/test/docusign_rest/client_test.rb @@ -263,4 +263,4 @@ end end end -end +end \ No newline at end of file From 23fe8d8881e713f29ceabffdf6ac9d4ae1122b98 Mon Sep 17 00:00:00 2001 From: Mike Pence Date: Sun, 6 Apr 2014 10:08:56 -0400 Subject: [PATCH 2/6] add support for numberTabs in get_template_roles to allow pre-filling numeric values in envelope creation from templates --- lib/docusign_rest/client.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/docusign_rest/client.rb b/lib/docusign_rest/client.rb index a9bd158a..31a87c6a 100644 --- a/lib/docusign_rest/client.rb +++ b/lib/docusign_rest/client.rb @@ -221,7 +221,8 @@ def get_template_roles(signers) roleName: signer[:role_name], tabs: { textTabs: get_signer_tabs(signer[:text_tabs]), - checkboxTabs: get_signer_tabs(signer[:checkbox_tabs]) + checkboxTabs: get_signer_tabs(signer[:checkbox_tabs]), + numberTabs: get_signer_tabs(signer[:number_tabs]) } } From b51555e4d08c78c66614ff6dfb8581cf5e8faea0 Mon Sep 17 00:00:00 2001 From: Mike Pence Date: Sun, 27 Apr 2014 17:40:05 -0400 Subject: [PATCH 3/6] add ability to void an envelope --- lib/docusign_rest/client.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/docusign_rest/client.rb b/lib/docusign_rest/client.rb index 31a87c6a..c5876540 100644 --- a/lib/docusign_rest/client.rb +++ b/lib/docusign_rest/client.rb @@ -1093,5 +1093,29 @@ def delete_envelope_recipient(options={}) response = http.request(request) parsed_response = JSON.parse(response.body) end + + # Public voids an in-process envelope + # + # envelope_id - ID of the envelope to be voided + # voided_reason - Optional reason for the envelope being voided + # + # Returns the response (success or failure). + def void_envelope(options = {}) + content_type = { 'Content-Type' => 'application/json' } + content_type.merge(options[:headers]) if options[:headers] + + post_body = { + "status" =>"voided", + "voidedReason" => options[:voided_reason] || "No reason provided." + }.to_json + + uri = build_uri("/accounts/#{acct_id}/envelopes/#{options[:folder_id]}") + + http = initialize_net_http_ssl(uri) + request = Net::HTTP::Put.new(uri.request_uri, headers(content_type)) + request.body = post_body + response = http.request(request) + response + end end end From 97d28fba8304e78f9de98d35f36a7899817cc344 Mon Sep 17 00:00:00 2001 From: seanwooj Date: Wed, 5 Feb 2014 13:50:10 -0800 Subject: [PATCH 4/6] added #get_envelope_audit_events method --- lib/docusign_rest/client.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/docusign_rest/client.rb b/lib/docusign_rest/client.rb index c5876540..59f5944d 100644 --- a/lib/docusign_rest/client.rb +++ b/lib/docusign_rest/client.rb @@ -949,6 +949,28 @@ def move_envelope_to_folder(options = {}) response end + # Public returns a hash of audit events for a given envelope + # + # envelope_id - ID of the envelope to get audit events from + # + # + # Example + # client.get_envelope_audit_events( + # envelope_id: "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx" + # ) + # Returns a hash of the events that have happened to the envelope. + def get_envelope_audit_events(options = {}) + content_type = { 'Content-Type' => 'application/json' } + content_type.merge(options[:headers]) if options[:headers] + + uri = build_uri("/accounts/#{acct_id}/envelopes/#{options[:envelope_id]}/audit_events") + + http = initialize_net_http_ssl(uri) + request = Net::HTTP::Get.new(uri.request_uri, headers(content_type)) + response = http.request(request) + + JSON.parse(response.body) + end # Public retrieves the envelope(s) from a specific folder based on search params. # From e062caa92f0ab21d86d96f5f218ea9baee5cc4a3 Mon Sep 17 00:00:00 2001 From: Patrick Logan Date: Wed, 12 Feb 2014 14:02:42 -0800 Subject: [PATCH 5/6] API for the combined PDF for a given envelope ID Needed this. Didn't see that is was provided. --- lib/docusign_rest/client.rb | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lib/docusign_rest/client.rb b/lib/docusign_rest/client.rb index 59f5944d..f2e852a7 100644 --- a/lib/docusign_rest/client.rb +++ b/lib/docusign_rest/client.rb @@ -914,7 +914,45 @@ def get_documents_from_envelope(options={}) JSON.parse(response.body) end + + # Public retrieves a PDF containing the combined content of all + # documents and the certificate for the given envelope. + # + # envelope_id - ID of the envelope from which the doc will be retrieved + # local_save_path - Local absolute path to save the doc to including the + # filename itself + # headers - Optional hash of headers to merge into the existing + # required headers for a multipart request. + # + # Example + # + # client.get_combined_document_from_envelope( + # envelope_id: @envelope_response['envelopeId'], + # local_save_path: 'docusign_docs/file_name.pdf', + # return_stream: true/false # will return the bytestream instead of saving doc to file system. + # ) + # + # Returns the PDF document as a byte stream. + def get_combined_document_from_envelope(options={}) + content_type = { 'Content-Type' => 'application/json' } + content_type.merge(options[:headers]) if options[:headers] + + uri = build_uri("/accounts/#{acct_id}/envelopes/#{options[:envelope_id]}/documents/combined") + + http = initialize_net_http_ssl(uri) + request = Net::HTTP::Get.new(uri.request_uri, headers(content_type)) + response = http.request(request) + return response.body if options[:return_stream] + + split_path = options[:local_save_path].split('/') + split_path.pop #removes the document name and extension from the array + path = split_path.join("/") #rejoins the array to form path to the folder that will contain the file + FileUtils.mkdir_p(path) + File.open(options[:local_save_path], 'wb') do |output| + output << response.body + end + end # Public moves the specified envelopes to the given folder # From 87cead4d60d0766f0deb73dd4475b26bb8fe6589 Mon Sep 17 00:00:00 2001 From: lbspen Date: Tue, 18 Mar 2014 15:28:21 -0700 Subject: [PATCH 6/6] Add creation of an envelope from a composite template of server templates --- lib/docusign_rest/client.rb | 97 ++++++++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 2 deletions(-) diff --git a/lib/docusign_rest/client.rb b/lib/docusign_rest/client.rb index f2e852a7..8b1d1af7 100644 --- a/lib/docusign_rest/client.rb +++ b/lib/docusign_rest/client.rb @@ -222,7 +222,9 @@ def get_template_roles(signers) tabs: { textTabs: get_signer_tabs(signer[:text_tabs]), checkboxTabs: get_signer_tabs(signer[:checkbox_tabs]), - numberTabs: get_signer_tabs(signer[:number_tabs]) + numberTabs: get_signer_tabs(signer[:number_tabs]), + fullNameTabs: get_signer_tabs(signer[:fullname_tabs]), + dateTabs: get_signer_tabs(signer[:date_tabs]) } } @@ -493,6 +495,40 @@ def get_documents(ios) end + # Internal: takes in an array of server template ids and an array of the signers + # and sets up the composite template + # + # Returns an array of server template hashes + def get_composite_template(server_template_ids, signers) + composite_array = [] + index = 0 + server_template_ids.each do |template_id| + server_template_hash = Hash[:sequence, index += 1, \ + :templateId, template_id] + templates_hash = Hash[:serverTemplates, [server_template_hash], \ + :inlineTemplates, get_inline_signers(signers, index += 1)] + composite_array << templates_hash + end + composite_array + end + + # Internal: takes signer info and the inline template sequence number + # and sets up the inline template + # + # Returns an array of signers + def get_inline_signers(signers, sequence) + signers_array = [] + signers.each do |signer| + signers_hash = Hash[:email, signer[:email], :name, signer[:name], \ + :recipientId, signer[:recipient_id], :roleName, signer[:role_name], \ + :clientUserId, signer[:email]] + signers_array << signers_hash + end + template_hash = Hash[:sequence, sequence, :recipients, { signers: signers_array }] + [template_hash] + end + + # Internal sets up the Net::HTTP request # # uri - The fully qualified final URI @@ -700,6 +736,50 @@ def create_envelope_from_template(options={}) end + # Public: create an envelope for delivery from a composite template + # + # headers - Optional hash of headers to merge into the existing + # required headers for a POST request. + # status - Options include: 'sent', or 'created' and + # determine if the envelope is sent out immediately or + # stored for sending at a later time + # email/body - Sets the text in the email body + # email/subject - Sets the text in the email subject line + # template_roles - See the get_template_roles method definition for a list + # of options to pass. Note: for consistency sake we call + # this 'signers' and not 'templateRoles' when we build up + # the request in client code. + # headers - Optional hash of headers to merge into the existing + # required headers for a multipart request. + # server_template_ids - Array of ids for templates uploaded to DocuSign. Templates + # will be added in the order they appear in the array. + # + # Returns a JSON parsed response body containing the envelope's: + # envelopeId - autogenerated ID provided by Docusign + # uri - the URI where the template is located on the DocuSign servers + # statusDateTime - The date/time the envelope was created + # status - Sent, created, or voided + def create_envelope_from_composite_template(options={}) + content_type = { 'Content-Type' => 'application/json' } + content_type.merge(options[:headers]) if options[:headers] + + post_body = { + status: options[:status], + compositeTemplates: get_composite_template(options[:server_template_ids], options[:signers]) + }.to_json + + uri = build_uri("/accounts/#{acct_id}/envelopes") + + http = initialize_net_http_ssl(uri) + + request = Net::HTTP::Post.new(uri.request_uri, headers(content_type)) + request.body = post_body + + response = http.request(request) + JSON.parse(response.body) + end + + # Public returns the names specified for a given email address (existing docusign user) # # email - the email of the recipient @@ -914,7 +994,7 @@ def get_documents_from_envelope(options={}) JSON.parse(response.body) end - + # Public retrieves a PDF containing the combined content of all # documents and the certificate for the given envelope. # @@ -1113,6 +1193,19 @@ def get_templates JSON.parse(http.request(request).body) end + # Public: Retrieves a list of templates used in an envelope + # + # Returns templateId, name and uri for each template found. + # + # envelope_id - DS id of envelope with templates. + def get_templates_in_envelope(envelope_id) + uri = build_uri("/accounts/#{acct_id}/envelopes/#{envelope_id}/templates") + + http = initialize_net_http_ssl(uri) + request = Net::HTTP::Get.new(uri.request_uri, headers({ 'Content-Type' => 'application/json' })) + JSON.parse(http.request(request).body) + end + # Grabs envelope data. # Equivalent to the following call in the API explorer: