/quick_acg
+$ bundler install
+$ rails s
+```
+
+Open a browser to http://localhost:3000
+
+### JWT grant remote signing example:
+Run in Windows Command Prompt (CMD):
+```
+$ cd jwt_console_project
+$ ruby jwt_console.rb
+```
### Troubleshooting Windows SSL issue
When using the Ruby launcher on a Windows machine you may get the following error:
**SSL peer certificate or SSH remote key was not OK**
-This error occurs because you’re attempting to use the Ruby launcher with a self-signed certificate or without SSL/HTTP security. The API calls from Ruby SDKs are using a built-in Curl tool that is enforcing the SSL requirement. You can disable this security check to run the launcher in an insecure manner on your developer machine.
+This error occurs because you’re attempting to use the Ruby launcher with a self-signed certificate or without SSL/HTTP security. The API calls from Ruby SDKs are using a built-in Curl tool that is enforcing the SSL requirement. You can disable this security check to run the launcher in an insecure manner on your developer machine.
```diff
-- It is highly recommended that you don’t disable this security check
-- in a production environment or in your integration.
-- This method is offered here solely as a means to enable you to
+- It is highly recommended that you don’t disable this security check
+- in a production environment or in your integration.
+- This method is offered here solely as a means to enable you to
- develop quickly by lowering the security bar on your local machine.
```
Find the root folder for your Ruby gems (in this case, a 64-bit version of Ruby 2.7.0):
C:\Ruby27-x64\lib\ruby\gems\2.7.0\gems\
-Find the relevant DocuSign Ruby SDK you are using. The name always starts with “docusign”; for instance, DocuSign Click SDK version 1.0.0:
+Find the relevant Docusign Ruby SDK you are using. The name always starts with “docusign”; for instance, Docusign Click SDK version 1.0.0:
C:\Ruby27-x64\lib\ruby\gems\2.7.0\gems\docusign_click-1.0.0\lib\docusign_click
@@ -304,13 +187,23 @@ Modify the following two lines in the **configuration.rb** file, replacing `true
Once this is complete, you can run your Ruby on Rails application again and you should be able to make API calls on your localhost.
+### Troubleshooting macOS SSL issue
+When using the Ruby launcher on OSX you may get the following error:
+
+```
+Faraday::SSLError (SSL_connect returned=1 errno=0 state=error: certificate verify failed (self signed certificate in certificate chain))
+```
+Please update SSL certificates if rvm is your version manager. Or check [other steps for different scenarios](https://gemfury.com/help/could-not-verify-ssl-certificate/#updating-ssl-certificates).
+```
+$ rvm osx-ssl-certs status all
+$ rvm osx-ssl-certs update all
+```
## Payments code example
To use the payments code example, create a test payment gateway on the [**Payments**](https://admindemo.docusign.com/authenticate?goTo=payments) page in your developer account. See [Configure a payment gateway](./PAYMENTS_INSTALLATION.md) for details.
Once you've created a payment gateway, save the **Gateway Account ID** GUID to appsettings.yml.
-
## License and additional information
### License
diff --git a/app/assets/images/favicon.ico b/app/assets/images/favicon.ico
deleted file mode 100644
index b3b2dc4..0000000
Binary files a/app/assets/images/favicon.ico and /dev/null differ
diff --git a/app/assets/images/favicon.png b/app/assets/images/favicon.png
new file mode 100644
index 0000000..fefff55
Binary files /dev/null and b/app/assets/images/favicon.png differ
diff --git a/app/assets/javascripts/search.js b/app/assets/javascripts/search.js
new file mode 100644
index 0000000..c539995
--- /dev/null
+++ b/app/assets/javascripts/search.js
@@ -0,0 +1,295 @@
+const DS_SEARCH = (function () {
+ const API_TYPES = {
+ ESIGNATURE: "esignature",
+ MONITOR: "monitor",
+ CLICK: "click",
+ ROOMS: "rooms",
+ ADMIN: "admin",
+ CONNECT: "connect",
+ WEBFORMS: "webforms",
+ NOTARY: "notary",
+ CONNECTED_FIELDS: "connectedfields"
+ }
+
+ const processJSONData = function () {
+ const json_raw = $("#api_json_data").text();
+ const json = json_raw ? JSON.parse(json_raw) : false;
+
+ return json;
+ }
+
+ const processCFR11Value = function () {
+ const cfr11_data = $("#cfr11_data");
+ return cfr11_data.text();
+ }
+
+ function shouldAppendExample(element, example, cfrPart11) {
+ const isEsignature = element.Name.toLowerCase() === API_TYPES.ESIGNATURE.toLowerCase();
+ const isCFREnabledForAll = example.CFREnabled === "AllAccounts";
+ const isCFREnabledForCFROnly = cfrPart11 === "enabled" && example.CFREnabled === "CFROnly";
+ const isCFREnabledForNonCFR = cfrPart11 !== "enabled" && example.CFREnabled === "NonCFR";
+
+ return !isEsignature || isCFREnabledForAll || isCFREnabledForCFROnly || isCFREnabledForNonCFR;
+ }
+
+ function checkIfExampleMatches(example, matches) {
+ const name = example.ExampleName;
+ const description = example.ExampleDescription;
+
+ let pathNames = [];
+ if (example.LinksToAPIMethod) {
+ pathNames = example.LinksToAPIMethod.map((a) => a.PathName);
+ }
+
+ for (let i = 0; i < matches.length; i++) {
+ if (
+ name === matches[i].value ||
+ description === matches[i].value ||
+ pathNames && pathNames.indexOf(matches[i].value) > -1
+ ) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ function clearNonMatchingExamples(examples, matches) {
+ for (let i = examples.length - 1; i >= 0; i--) {
+ if (!checkIfExampleMatches(examples[i], matches)) {
+ examples.splice(i, 1);
+ }
+ }
+ }
+
+ function clearResultsAfterMatching(api, matches) {
+ const groups = api.Groups;
+
+ for (let i = groups.length - 1; i >= 0; i--) {
+ const group = groups[i];
+ clearNonMatchingExamples(group.Examples, matches);
+
+ if (group.Examples.length === 0) {
+ groups.splice(i, 1);
+ }
+ }
+ }
+
+ const findCodeExamplesByKeywords = function(json, pattern) {
+ const options = {
+ isCaseSensitive: false,
+ minMatchCharLength: pattern.length,
+ threshold: -0.0,
+ includeMatches: true,
+ ignoreLocation: true,
+ useExtendedSearch: true,
+ keys: [
+ "Groups.Examples.ExampleName",
+ "Groups.Examples.ExampleDescription",
+ "Groups.Examples.LinksToAPIMethod.PathName",
+ ],
+ };
+
+ const clearJSON = JSON.stringify(json).replace(/<\/?[^>]+(>|$)/g, "");
+ const fuse = new Fuse(JSON.parse(clearJSON), options);
+
+ const searchResults = fuse.search(JSON.stringify(pattern));
+
+ searchResults.forEach((searchResult) =>
+ clearResultsAfterMatching(searchResult.item, searchResult.matches)
+ );
+
+ return searchResults;
+ }
+
+ const getExamplesByAPIType = function (apiType, codeExamples) {
+ let codeExamplesByAPI = codeExamples.find(
+ (x) => x.Name.toLowerCase() === apiType
+ );
+
+ if (codeExamplesByAPI != null) {
+ return [codeExamplesByAPI];
+ } else {
+ return null;
+ }
+ };
+
+ const getEnteredAPIType = function (inputValue) {
+ const inputLength = inputValue.length;
+
+ for (const key in API_TYPES) {
+ if (Object.hasOwnProperty.call(API_TYPES, key)) {
+ const apiType = API_TYPES[key];
+ const comparedValue = apiType.substr(0, inputLength);
+
+ if (inputValue === comparedValue) {
+ return apiType;
+ }
+ }
+ }
+
+ return null;
+ };
+
+ function getLinkForApiType(apiName) {
+ switch (apiName) {
+ case API_TYPES.ADMIN:
+ return "aeg";
+ case API_TYPES.CLICK:
+ return "ceg";
+ case API_TYPES.ROOMS:
+ return "reg";
+ case API_TYPES.MONITOR:
+ return "meg";
+ case API_TYPES.ESIGNATURE:
+ return "eeg";
+ case API_TYPES.CONNECT:
+ return "cneg";
+ case API_TYPES.WEBFORMS:
+ return "weg";
+ case API_TYPES.NOTARY:
+ return "neg";
+ case API_TYPES.CONNECTED_FIELDS:
+ return "feg";
+ }
+ }
+
+ const addCodeExampleToHomepage = function (codeExamples) {
+ var cfrPart11 = processCFR11Value();
+
+ codeExamples.forEach((element) => {
+ let linkToCodeExample = getLinkForApiType(element.Name.toLowerCase());
+
+ element.Groups.forEach((group) => {
+ $("#filtered_code_examples").append("" + group.Name + "
");
+
+ group.Examples.forEach((example) => {
+ if (
+ !example.SkipForLanguages ||
+ !example.SkipForLanguages.toLowerCase().includes("ruby")
+ ) {
+ if (shouldAppendExample(element, example, cfrPart11))
+ {
+ $("#filtered_code_examples").append(
+ ""
+ );
+
+ $("#filtered_code_examples").append(
+ "" + example.ExampleDescription + "
"
+ );
+
+ $("#filtered_code_examples").append("");
+ const links = example.LinksToAPIMethod || [];
+ if (links.length > 0) {
+ if (links.length == 1) {
+ $("#filtered_code_examples").append(
+ processJSONData().SupportingTexts.APIMethodUsed
+ );
+ } else {
+ $("#filtered_code_examples").append(
+ processJSONData().SupportingTexts.APIMethodUsedPlural
+ );
+ }
+
+ links.forEach((link, index) => {
+ $("#filtered_code_examples").append(`${link.PathName}`);
+
+ if (index + 1 === links.length) {
+ $("#filtered_code_examples").append("");
+ } else if (index + 1 === links.length - 1) {
+ $("#filtered_code_examples").append(" and ");
+ } else {
+ $("#filtered_code_examples").append(", ");
+ }
+ })
+
+ }
+
+ $("#filtered_code_examples").append("
");
+ }
+ }
+ });
+ });
+ });
+ };
+
+ const textCouldNotBeFound = function () {
+ $("#filtered_code_examples").append(
+ processJSONData().SupportingTexts.SearchFailed
+ );
+ };
+
+ return {
+ processJSONData,
+ getEnteredAPIType,
+ getExamplesByAPIType,
+ findCodeExamplesByKeywords,
+ textCouldNotBeFound,
+ addCodeExampleToHomepage,
+ shouldAppendExample,
+ };
+})();
+
+const input = document.getElementById("code_example_search");
+const log = document.getElementById("values");
+
+input.addEventListener("input", updateValue);
+
+function updateValue(esearchPattern) {
+ document.getElementById("filtered_code_examples").innerHTML = "";
+
+ const inputValue = esearchPattern.target.value.toLowerCase();
+ const json = DS_SEARCH.processJSONData().APIs;
+
+ if (inputValue === "") {
+ DS_SEARCH.addCodeExampleToHomepage(json);
+ } else {
+ const apiType = DS_SEARCH.getEnteredAPIType(inputValue);
+
+ if (apiType !== null) {
+ const adminExamples = DS_SEARCH.getExamplesByAPIType(apiType, json);
+ DS_SEARCH.addCodeExampleToHomepage(adminExamples);
+ } else {
+ const result = DS_SEARCH.findCodeExamplesByKeywords(json, inputValue);
+ if (result.length < 1) {
+ DS_SEARCH.textCouldNotBeFound();
+ } else {
+ result.forEach((x) => {
+ const api = json.filter((api) => {
+ return api.Name === x.item.Name;
+ })[0];
+
+ x.item.Groups.forEach((group, groupIndex) => {
+ const unfilteredGroup = api.Groups.filter((apiGroup) => {
+ return apiGroup.Name === group.Name;
+ })[0];
+
+ group.Examples.forEach((example, index) => {
+ const clearedExamples = unfilteredGroup.Examples.filter((apiExample) => {
+ return apiExample.ExampleNumber === example.ExampleNumber;
+ })
+ x.item.Groups[groupIndex].Examples[index] = clearedExamples[0];
+ });
+ });
+
+ DS_SEARCH.addCodeExampleToHomepage([x.item]);
+ });
+ }
+ }
+ }
+}
diff --git a/app/controllers/admin_api/aeg001_create_user_controller.rb b/app/controllers/admin_api/aeg001_create_user_controller.rb
new file mode 100644
index 0000000..76eaf0f
--- /dev/null
+++ b/app/controllers/admin_api/aeg001_create_user_controller.rb
@@ -0,0 +1,67 @@
+class AdminApi::Aeg001CreateUserController < EgController
+ include ApiCreator
+ before_action -> { check_auth('Admin') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 1, 'Admin') }
+
+ def create
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ organization_id: session['organization_id']
+ }
+ #ds-snippet-start:Admin1Step5
+ user_data = {
+ user_name: param_gsub(params['user_name']),
+ first_name: param_gsub(params['first_name']),
+ last_name: param_gsub(params['last_name']),
+ email: param_gsub(params['email']),
+ auto_activate_memberships: true,
+ accounts: [
+ {
+ id: args[:account_id],
+ permission_profile: {
+ id: param_gsub(params['permission_profile_id'])
+ },
+ groups: [
+ {
+ id: param_gsub(params['group_id'])
+ }
+ ]
+ }
+ ]
+ }
+ #ds-snippet-end:Admin1Step5
+
+ begin
+ results = AdminApi::Eg001CreateUserService.new(args, user_data).worker
+
+ @title = @example['ExampleName']
+ @message = @example['ResultsPageText']
+ @json = results.to_json.to_json
+ render 'ds_common/example_done'
+ rescue DocuSign_Admin::ApiError => e
+ handle_error(e)
+ end
+ end
+
+ def get
+ super
+ session[:organization_id] = AdminApi::GetDataService.new(session).get_organization_id if session[:organization_id].nil?
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token']
+ }
+
+ #ds-snippet-start:Admin1Step3
+ accounts_api = create_account_api(args)
+ @permission_profiles = accounts_api.list_permissions(args[:account_id]).permission_profiles
+ #ds-snippet-end:Admin1Step3
+
+ #ds-snippet-start:Admin1Step4
+ groups_api = create_group_api(args)
+ @groups = groups_api.list_groups(args[:account_id]).groups
+ #ds-snippet-end:Admin1Step4
+ end
+end
diff --git a/app/controllers/admin_api/aeg002_create_active_clm_esign_user_controller.rb b/app/controllers/admin_api/aeg002_create_active_clm_esign_user_controller.rb
new file mode 100644
index 0000000..dce0b8e
--- /dev/null
+++ b/app/controllers/admin_api/aeg002_create_active_clm_esign_user_controller.rb
@@ -0,0 +1,51 @@
+class AdminApi::Aeg002CreateActiveClmEsignUserController < EgController
+ before_action -> { check_auth('Admin') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 2, 'Admin') }
+
+ def create
+ args = {
+ user_name: params[:user_name],
+ first_name: params[:first_name],
+ last_name: params[:last_name],
+ email: params[:email],
+ clm_permission_profile_id: params[:clm_permission_profile_id],
+ esign_permission_profile_id: params[:esign_permission_profile_id],
+ clm_product_id: params[:clm_product_id],
+ esign_product_id: params[:esign_product_id],
+ ds_group_id: params[:ds_group_id],
+ account_id: session[:ds_account_id],
+ organization_id: session['organization_id'],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token]
+ }
+
+ results = AdminApi::Eg002CreateActiveClmEsignUserService.new(args).worker
+
+ session[:clm_email] = params[:email]
+
+ @title = @example['ExampleName']
+ @message = @example['ResultsPageText']
+ @json = results.to_json.to_json
+
+ render 'ds_common/example_done'
+ rescue DocuSign_Admin::ApiError => e
+ handle_error(e)
+ end
+
+ def get
+ super
+ session[:organization_id] = AdminApi::GetDataService.new(session).get_organization_id if session[:organization_id].nil?
+ product_permission_profiles = AdminApi::GetDataService.new(session).get_product_permission_profiles
+
+ product_permission_profiles.each do |product_permission_profile|
+ if product_permission_profile['product_name'] == 'CLM'
+ @clm_permission_profiles = product_permission_profile['permission_profiles']
+ @clm_product_id = product_permission_profile['product_id']
+ else
+ @esign_permission_profiles = product_permission_profile['permission_profiles']
+ @esign_product_id = product_permission_profile['product_id']
+ end
+ end
+ @ds_groups = AdminApi::GetDataService.new(session).get_ds_groups
+ end
+end
diff --git a/app/controllers/admin_api/aeg003_bulk_export_user_data_controller.rb b/app/controllers/admin_api/aeg003_bulk_export_user_data_controller.rb
new file mode 100644
index 0000000..d79423a
--- /dev/null
+++ b/app/controllers/admin_api/aeg003_bulk_export_user_data_controller.rb
@@ -0,0 +1,33 @@
+class AdminApi::Aeg003BulkExportUserDataController < EgController
+ before_action -> { check_auth('Admin') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 3, 'Admin') }
+
+ def create
+ session[:organization_id] = AdminApi::GetDataService.new(session).get_organization_id if session[:organization_id].nil?
+
+ file_path = File.expand_path(File.join(File.dirname(__FILE__), '../../../data/exportedUserData.csv'))
+
+ begin
+ request_body = {
+ type: 'organization_memberships_export'
+ }
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ organization_id: session['organization_id'],
+ file_path: file_path,
+ request_body: request_body
+ }
+
+ results = AdminApi::Eg003BulkExportUserDataService.new(args).worker
+
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], file_path)
+ @json = results.to_json.to_json
+ render 'ds_common/example_done'
+ rescue DocuSign_Admin::ApiError => e
+ handle_error(e)
+ end
+ end
+end
diff --git a/app/controllers/admin_api/aeg004_import_user_controller.rb b/app/controllers/admin_api/aeg004_import_user_controller.rb
new file mode 100644
index 0000000..1d3e3d2
--- /dev/null
+++ b/app/controllers/admin_api/aeg004_import_user_controller.rb
@@ -0,0 +1,51 @@
+class AdminApi::Aeg004ImportUserController < EgController
+ before_action -> { check_auth('Admin') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 4, 'Admin') }
+
+ def create
+ session[:organization_id] = AdminApi::GetDataService.new(session).get_organization_id if session[:organization_id].nil?
+
+ file_path = File.expand_path(File.join(File.dirname(__FILE__), '../../../data/userData.csv'))
+
+ begin
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ organization_id: session['organization_id'],
+ csv_file_path: file_path
+ }
+
+ results = AdminApi::Eg004ImportUserService.new(args).worker
+ session[:import_id] = results.id
+
+ @title = @example['ExampleName']
+ @check_status = true,
+ @message = @example['ResultsPageText']
+ @json = results.to_json.to_json
+ render 'ds_common/example_done'
+ rescue DocuSign_Admin::ApiError => e
+ handle_error(e)
+ end
+ end
+
+ def check_status
+ session[:organization_id] = AdminApi::GetDataService.new(session).get_organization_id if session[:organization_id].nil?
+
+ begin
+ import_id = session[:import_id]
+ results = AdminApi::GetDataService.new(session).check_import_status(import_id)
+
+ @status = results.status
+ @title = @example['ExampleName']
+ @message = @example['AdditionalPage'][0]['ResultsPageText']
+ @json = results.to_json.to_json
+ render 'admin_api/aeg004_import_user/get_status.html.erb'
+ rescue DocuSign_Admin::ApiError => e
+ error = JSON.parse e.response_body
+ @error_code = e.code
+ @error_message = error['error_description']
+ render 'ds_common/error'
+ end
+ end
+end
diff --git a/app/controllers/admin_api/aeg005_audit_users_controller.rb b/app/controllers/admin_api/aeg005_audit_users_controller.rb
new file mode 100644
index 0000000..4b65c56
--- /dev/null
+++ b/app/controllers/admin_api/aeg005_audit_users_controller.rb
@@ -0,0 +1,27 @@
+class AdminApi::Aeg005AuditUsersController < EgController
+ before_action -> { check_auth('Admin') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 5, 'Admin') }
+
+ def create
+ session[:organization_id] = AdminApi::GetDataService.new(session).get_organization_id if session[:organization_id].nil?
+
+ begin
+ args = {
+ account_id: session[:ds_account_id],
+ organization_id: session['organization_id'],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token]
+ }
+
+ results = AdminApi::Eg005AuditUsersService.new(args).worker
+
+ @title = @example['ExampleName']
+ @message = @example['ResultsPageText']
+ @json = results.to_json.to_json
+
+ render 'ds_common/example_done'
+ rescue DocuSign_Admin::ApiError => e
+ handle_error(e)
+ end
+ end
+end
diff --git a/app/controllers/admin_api/aeg006_get_user_profile_by_email_controller.rb b/app/controllers/admin_api/aeg006_get_user_profile_by_email_controller.rb
new file mode 100644
index 0000000..0af11c3
--- /dev/null
+++ b/app/controllers/admin_api/aeg006_get_user_profile_by_email_controller.rb
@@ -0,0 +1,24 @@
+class AdminApi::Aeg006GetUserProfileByEmailController < EgController
+ include ApiCreator
+ before_action -> { check_auth('Admin') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 6, 'Admin') }
+
+ def create
+ session[:organization_id] = AdminApi::GetDataService.new(session).get_organization_id if session[:organization_id].nil?
+
+ args = {
+ access_token: session['ds_access_token'],
+ organization_id: session['organization_id'],
+ email: param_gsub(params['email'])
+ }
+
+ results = AdminApi::Eg006GetUserProfileByEmailService.new(args).worker
+
+ @title = @example['ExampleName']
+ @message = @example['ResultsPageText']
+ @json = results.to_json.to_json
+ render 'ds_common/example_done'
+ rescue DocuSign_Admin::ApiError => e
+ handle_error(e)
+ end
+end
diff --git a/app/controllers/admin_api/aeg007_get_user_profile_by_user_id_controller.rb b/app/controllers/admin_api/aeg007_get_user_profile_by_user_id_controller.rb
new file mode 100644
index 0000000..d21f01e
--- /dev/null
+++ b/app/controllers/admin_api/aeg007_get_user_profile_by_user_id_controller.rb
@@ -0,0 +1,24 @@
+class AdminApi::Aeg007GetUserProfileByUserIdController < EgController
+ include ApiCreator
+ before_action -> { check_auth('Admin') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 7, 'Admin') }
+
+ def create
+ session[:organization_id] = AdminApi::GetDataService.new(session).get_organization_id if session[:organization_id].nil?
+
+ args = {
+ access_token: session['ds_access_token'],
+ organization_id: session['organization_id'],
+ user_id: param_gsub(params['user_id'])
+ }
+
+ results = AdminApi::Eg007GetUserProfileByUserIdService.new(args).worker
+
+ @title = @example['ExampleName']
+ @message = @example['ResultsPageText']
+ @json = results.to_json.to_json
+ render 'ds_common/example_done'
+ rescue DocuSign_Admin::ApiError => e
+ handle_error(e)
+ end
+end
diff --git a/app/controllers/admin_api/aeg008_update_user_product_permission_profile_controller.rb b/app/controllers/admin_api/aeg008_update_user_product_permission_profile_controller.rb
new file mode 100644
index 0000000..e5fef15
--- /dev/null
+++ b/app/controllers/admin_api/aeg008_update_user_product_permission_profile_controller.rb
@@ -0,0 +1,82 @@
+class AdminApi::Aeg008UpdateUserProductPermissionProfileController < EgController
+ before_action -> { check_auth('Admin') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 8, 'Admin') }
+
+ def create
+ clm_email = session[:clm_email]
+ get_data_service = AdminApi::GetDataService.new(session)
+
+ unless clm_email && get_data_service.check_user_exists_by_email(clm_email)
+ @email_ok = false
+ return
+ end
+
+ begin
+ product_permission_profiles = get_data_service.get_product_permission_profiles
+ product_id = params[:product_id]
+ permission_profile_id = nil
+
+ product_permission_profiles.each do |profile|
+ next unless product_id == profile['product_id']
+
+ permission_profile_id = if profile['product_name'] == 'CLM'
+ params[:clm_permission_profile_id]
+ else
+ params[:esign_permission_profile_id]
+ end
+ end
+
+ args = {
+ email: clm_email,
+ permission_profile_id: permission_profile_id,
+ product_id: product_id,
+ account_id: session[:ds_account_id],
+ organization_id: session['organization_id'],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token]
+ }
+
+ results = AdminApi::Eg008UpdateUserProductPermissionProfileService.new(args).worker
+
+ @title = @example['ExampleName']
+ @message = @example['ResultsPageText']
+ @json = results.to_json.to_json
+
+ render 'ds_common/example_done'
+ rescue DocuSign_Admin::ApiError => e
+ handle_error(e)
+ end
+ end
+
+ def get
+ super
+ get_data_service = AdminApi::GetDataService.new(session)
+
+ session[:organization_id] = get_data_service.get_organization_id if session[:organization_id].nil?
+
+ clm_email = session[:clm_email]
+
+ unless clm_email && get_data_service.check_user_exists_by_email(clm_email)
+ @email_ok = false
+ return
+ end
+
+ product_permission_profiles = get_data_service.get_product_permission_profiles
+
+ product_permission_profiles.each do |product_permission_profile|
+ if product_permission_profile['product_name'] == 'CLM'
+ @clm_permission_profiles = product_permission_profile['permission_profiles']
+ @clm_product_id = product_permission_profile['product_id']
+ else
+ @esign_permission_profiles = product_permission_profile['permission_profiles']
+ @esign_product_id = product_permission_profile['product_id']
+ end
+ end
+ product_list = []
+ product_list.push({ 'product_id' => @clm_product_id, 'product_name' => 'CLM' })
+ product_list.push({ 'product_id' => @esign_product_id, 'product_name' => 'eSignature' })
+ @product_list = product_list
+ @email_ok = true
+ @email = clm_email
+ end
+end
diff --git a/app/controllers/admin_api/aeg009_delete_user_product_permission_profile_controller.rb b/app/controllers/admin_api/aeg009_delete_user_product_permission_profile_controller.rb
new file mode 100644
index 0000000..e5fb322
--- /dev/null
+++ b/app/controllers/admin_api/aeg009_delete_user_product_permission_profile_controller.rb
@@ -0,0 +1,83 @@
+class AdminApi::Aeg009DeleteUserProductPermissionProfileController < EgController
+ before_action -> { check_auth('Admin') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 9, 'Admin') }
+
+ def create
+ clm_email = session[:clm_email]
+ get_data_service = AdminApi::GetDataService.new(session)
+
+ unless clm_email && get_data_service.check_user_exists_by_email(clm_email)
+ @email_ok = false
+ return
+ end
+
+ begin
+ args = {
+ email: clm_email,
+ product_id: params[:product_id],
+ account_id: session[:ds_account_id],
+ organization_id: session['organization_id'],
+ access_token: session[:ds_access_token]
+ }
+
+ results = AdminApi::Eg009DeleteUserProductPermissionProfileService.new(args).worker
+
+ @title = @example['ExampleName']
+ @message = @example['ResultsPageText']
+ @json = results.to_json.to_json
+
+ render 'ds_common/example_done'
+ rescue DocuSign_Admin::ApiError => e
+ handle_error(e)
+ end
+ end
+
+ def get
+ super
+ get_data_service = AdminApi::GetDataService.new(session)
+
+ session[:organization_id] = get_data_service.get_organization_id if session[:organization_id].nil?
+
+ clm_email = session[:clm_email]
+
+ unless clm_email && get_data_service.check_user_exists_by_email(clm_email)
+ @email_ok = false
+ return
+ end
+
+ args = {
+ email: clm_email,
+ account_id: session[:ds_account_id],
+ organization_id: session['organization_id'],
+ access_token: session[:ds_access_token]
+ }
+
+ product_permission_profiles = AdminApi::Eg009DeleteUserProductPermissionProfileService.new(args).get_permission_profiles_by_email
+ permission_profile_list = []
+ clm_product_id = nil
+ clm_permission_profile_name = nil
+ esign_product_id = nil
+ esign_permission_profile_name = nil
+
+ product_permission_profiles.each do |product_permission_profile|
+ permission_profiles = product_permission_profile['permission_profiles']
+ permission_profiles.each do |permission_profile|
+ if product_permission_profile['product_name'] == 'CLM'
+ clm_permission_profile_name = permission_profile['permission_profile_name']
+ clm_product_id = product_permission_profile['product_id']
+ else
+ esign_permission_profile_name = permission_profile['permission_profile_name']
+ esign_product_id = product_permission_profile['product_id']
+ end
+ end
+ end
+
+ permission_profile_list.push({ 'product_id' => clm_product_id, 'permission_name' => "CLM - #{clm_permission_profile_name}" }) if clm_product_id
+
+ permission_profile_list.push({ 'product_id' => esign_product_id, 'permission_name' => "eSignature - #{esign_permission_profile_name}" }) if esign_product_id
+
+ @permission_profile_list = permission_profile_list
+ @email_ok = true
+ @email = clm_email
+ end
+end
diff --git a/app/controllers/admin_api/aeg010_delete_user_data_from_organization_controller.rb b/app/controllers/admin_api/aeg010_delete_user_data_from_organization_controller.rb
new file mode 100644
index 0000000..3ac5113
--- /dev/null
+++ b/app/controllers/admin_api/aeg010_delete_user_data_from_organization_controller.rb
@@ -0,0 +1,23 @@
+class AdminApi::Aeg010DeleteUserDataFromOrganizationController < EgController
+ before_action -> { check_auth('Admin') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 10, 'Admin') }
+
+ def create
+ session[:organization_id] = AdminApi::GetDataService.new(session).get_organization_id if session[:organization_id].nil?
+
+ args = {
+ access_token: session['ds_access_token'],
+ email: param_gsub(params['email']),
+ organization_id: session['organization_id']
+ }
+
+ results = AdminApi::Eg010DeleteUserDataFromOrganizationService.new(args).worker
+
+ @title = @example['ExampleName']
+ @message = @example['ResultsPageText']
+ @json = results.to_json.to_json
+ render 'ds_common/example_done'
+ rescue DocuSign_Admin::ApiError => e
+ handle_error(e)
+ end
+end
diff --git a/app/controllers/admin_api/aeg011_delete_user_data_from_account_controller.rb b/app/controllers/admin_api/aeg011_delete_user_data_from_account_controller.rb
new file mode 100644
index 0000000..1dd5273
--- /dev/null
+++ b/app/controllers/admin_api/aeg011_delete_user_data_from_account_controller.rb
@@ -0,0 +1,21 @@
+class AdminApi::Aeg011DeleteUserDataFromAccountController < EgController
+ before_action -> { check_auth('Admin') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 11, 'Admin') }
+
+ def create
+ args = {
+ account_id: session['ds_account_id'],
+ access_token: session['ds_access_token'],
+ user_id: param_gsub(params['user_id'])
+ }
+
+ results = AdminApi::Eg011DeleteUserDataFromAccountService.new(args).worker
+
+ @title = @example['ExampleName']
+ @message = @example['ResultsPageText']
+ @json = results.to_json.to_json
+ render 'ds_common/example_done'
+ rescue DocuSign_Admin::ApiError => e
+ handle_error(e)
+ end
+end
diff --git a/app/controllers/admin_api/aeg012_clone_account_controller.rb b/app/controllers/admin_api/aeg012_clone_account_controller.rb
new file mode 100644
index 0000000..80a7baf
--- /dev/null
+++ b/app/controllers/admin_api/aeg012_clone_account_controller.rb
@@ -0,0 +1,35 @@
+class AdminApi::Aeg012CloneAccountController < EgController
+ before_action -> { check_auth('Admin') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 12, 'Admin') }
+
+ def create
+ args = {
+ access_token: session['ds_access_token'],
+ organization_id: session['organization_id'],
+ source_account_id: param_gsub(params['source_account_id']),
+ target_account_name: param_gsub(params['target_account_name']),
+ target_account_first_name: param_gsub(params['target_account_first_name']),
+ target_account_last_name: param_gsub(params['target_account_last_name']),
+ target_account_email: param_gsub(params['target_account_email'])
+ }
+
+ results = AdminApi::Eg012CloneAccountService.new(args).worker
+
+ @title = @example['ExampleName']
+ @message = @example['ResultsPageText']
+ @json = results.to_json.to_json
+ render 'ds_common/example_done'
+ rescue DocuSign_Admin::ApiError => e
+ handle_error(e)
+ end
+
+ def get
+ super
+ session[:organization_id] = AdminApi::GetDataService.new(session).get_organization_id if session[:organization_id].nil?
+ args = {
+ access_token: session['ds_access_token'],
+ organization_id: session['organization_id']
+ }
+ @accounts = AdminApi::Eg012CloneAccountService.new(args).get_account.asset_group_accounts
+ end
+end
diff --git a/app/controllers/admin_api/aeg013_create_account_controller.rb b/app/controllers/admin_api/aeg013_create_account_controller.rb
new file mode 100644
index 0000000..c3bd95c
--- /dev/null
+++ b/app/controllers/admin_api/aeg013_create_account_controller.rb
@@ -0,0 +1,38 @@
+class AdminApi::Aeg013CreateAccountController < EgController
+ before_action -> { check_auth('Admin') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 13, 'Admin') }
+
+ def create
+ args = {
+ access_token: session['ds_access_token'],
+ organization_id: session['organization_id'],
+ subscription_id: session['subscription_id'],
+ plan_id: session['plan_id'],
+ email: param_gsub(params['email']),
+ first_name: param_gsub(params['first_name']),
+ last_name: param_gsub(params['last_name'])
+ }
+
+ results = AdminApi::Eg013CreateAccountService.new(args).worker
+
+ @title = @example['ExampleName']
+ @message = @example['ResultsPageText']
+ @json = results.to_json.to_json
+ render 'ds_common/example_done'
+ rescue DocuSign_Admin::ApiError => e
+ handle_error(e)
+ end
+
+ def get
+ super
+ session[:organization_id] = AdminApi::GetDataService.new(session).get_organization_id if session[:organization_id].nil?
+ args = {
+ access_token: session['ds_access_token'],
+ organization_id: session['organization_id']
+ }
+ plan_items = AdminApi::Eg013CreateAccountService.new(args).get_organization_plan_items
+ print plan_items
+ session['subscription_id'] = plan_items[0].subscription_id
+ session['plan_id'] = plan_items[0].plan_id
+ end
+end
diff --git a/app/controllers/clickwrap/ceg001_create_clickwrap_controller.rb b/app/controllers/clickwrap/ceg001_create_clickwrap_controller.rb
new file mode 100644
index 0000000..83b3ce9
--- /dev/null
+++ b/app/controllers/clickwrap/ceg001_create_clickwrap_controller.rb
@@ -0,0 +1,24 @@
+class Clickwrap::Ceg001CreateClickwrapController < EgController
+ before_action -> { check_auth('Click') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 1, 'Click') }
+
+ def create
+ args = {
+ account_id: session[:ds_account_id],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token],
+ doc_pdf: File.join('data', Rails.configuration.doc_terms_pdf),
+ clickwrap_name: param_gsub(params[:clickwrapName])
+ }
+
+ results = Clickwrap::Eg001CreateClickwrapService.new(args).worker
+
+ session[:clickwrap_id] = results.clickwrap_id
+ session[:clickwrap_name] = results.clickwrap_name
+
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results.clickwrap_name)
+ @json = results.to_json.to_json
+ render 'ds_common/example_done'
+ end
+end
diff --git a/app/controllers/clickwrap/ceg002_activate_clickwrap_controller.rb b/app/controllers/clickwrap/ceg002_activate_clickwrap_controller.rb
new file mode 100644
index 0000000..38664f3
--- /dev/null
+++ b/app/controllers/clickwrap/ceg002_activate_clickwrap_controller.rb
@@ -0,0 +1,24 @@
+class Clickwrap::Ceg002ActivateClickwrapController < EgController
+ before_action -> { check_auth('Click') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 2, 'Click') }
+
+ def create
+ args = {
+ account_id: session[:ds_account_id],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token],
+ clickwrap_id: params[:clickwrapId]
+ }
+
+ Clickwrap::Eg002ActivateClickwrapService.new(args).worker
+
+ @title = @example['ExampleName']
+ @message = @example['ResultsPageText']
+ render 'ds_common/example_done'
+ end
+
+ def get
+ statuses = %w[inactive draft]
+ @clickwraps = Clickwrap::Eg002ActivateClickwrapService.new(session).get_inactive_clickwraps(statuses).as_json
+ end
+end
diff --git a/app/controllers/clickwrap/ceg003_create_new_clickwrap_version_controller.rb b/app/controllers/clickwrap/ceg003_create_new_clickwrap_version_controller.rb
new file mode 100644
index 0000000..73f5f6a
--- /dev/null
+++ b/app/controllers/clickwrap/ceg003_create_new_clickwrap_version_controller.rb
@@ -0,0 +1,20 @@
+class Clickwrap::Ceg003CreateNewClickwrapVersionController < EgController
+ before_action -> { check_auth('Click') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 3, 'Click') }
+
+ def create
+ args = {
+ account_id: session[:ds_account_id],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token],
+ clickwrap_id: session[:clickwrap_id],
+ clickwrap_name: session[:clickwrap_name]
+ }
+
+ results = Clickwrap::Eg003CreateNewClickwrapVersionService.new(args).worker
+ puts results.to_json.to_json
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results.version_number, results.clickwrap_name)
+ render 'ds_common/example_done'
+ end
+end
diff --git a/app/controllers/clickwrap/ceg004_list_clickwraps_controller.rb b/app/controllers/clickwrap/ceg004_list_clickwraps_controller.rb
new file mode 100644
index 0000000..a734dc0
--- /dev/null
+++ b/app/controllers/clickwrap/ceg004_list_clickwraps_controller.rb
@@ -0,0 +1,19 @@
+class Clickwrap::Ceg004ListClickwrapsController < EgController
+ before_action -> { check_auth('Click') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 4, 'Click') }
+
+ def create
+ args = {
+ account_id: session[:ds_account_id],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token]
+ }
+
+ results = Clickwrap::Eg004ListClickwrapsService.new(args).worker
+
+ @title = @example['ExampleName']
+ @message = @example['ResultsPageText']
+ @json = results.to_json.to_json
+ render 'ds_common/example_done'
+ end
+end
diff --git a/app/controllers/clickwrap/ceg005_clickwrap_responses_controller.rb b/app/controllers/clickwrap/ceg005_clickwrap_responses_controller.rb
new file mode 100644
index 0000000..cf2f3a9
--- /dev/null
+++ b/app/controllers/clickwrap/ceg005_clickwrap_responses_controller.rb
@@ -0,0 +1,21 @@
+class Clickwrap::Ceg005ClickwrapResponsesController < EgController
+ before_action -> { check_auth('Click') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 5, 'Click') }
+
+ def create
+ args = {
+ account_id: session[:ds_account_id],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token],
+ clickwrap_id: session[:clickwrap_id],
+ client_user_id: param_gsub(params[:client_user_id])
+ }
+
+ results = Clickwrap::Eg005ClickwrapResponsesService.new(args).worker
+
+ @title = @example['ExampleName']
+ @message = @example['ResultsPageText']
+ @json = results.to_json.to_json
+ render 'ds_common/example_done'
+ end
+end
diff --git a/app/controllers/clickwrap/ceg006_embed_clickwrap_controller.rb b/app/controllers/clickwrap/ceg006_embed_clickwrap_controller.rb
new file mode 100644
index 0000000..3d739a6
--- /dev/null
+++ b/app/controllers/clickwrap/ceg006_embed_clickwrap_controller.rb
@@ -0,0 +1,38 @@
+class Clickwrap::Ceg006EmbedClickwrapController < EgController
+ before_action -> { check_auth('Click') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 6, 'Click') }
+
+ def create
+ args = {
+ account_id: session[:ds_account_id],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token],
+ clickwrap_id: params[:clickwrapId],
+ full_name: params[:fullName],
+ email: params[:email],
+ company: params[:company],
+ title: params[:title],
+ date: params[:date]
+ }
+
+ results = Clickwrap::Eg006EmbedClickwrapService.new(args).worker
+
+ if results.nil?
+ @error_code = '200'
+ @error_message = 'The email address was already used to agree to this elastic template. Provide a different email address if you want to view the agreement and agree to it.'
+ render 'ds_common/error'
+ else
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'])
+ @agreementUrl = results['agreementUrl']
+ render 'clickwrap/ceg006_embed_clickwrap/results'
+ end
+ rescue DocuSign_Click::ApiError => e
+ handle_error(e)
+ end
+
+ def get
+ @clickwraps = Clickwrap::Eg006EmbedClickwrapService.new(session).get_active_clickwraps
+ @inactive_clickwraps = Clickwrap::Eg006EmbedClickwrapService.new(session).get_inactive_clickwraps
+ end
+end
diff --git a/app/controllers/clickwrap/eg001_create_clickwrap_controller.rb b/app/controllers/clickwrap/eg001_create_clickwrap_controller.rb
deleted file mode 100644
index 454396e..0000000
--- a/app/controllers/clickwrap/eg001_create_clickwrap_controller.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-class Clickwrap::Eg001CreateClickwrapController < EgController
- before_action :check_auth
-
- def create
- results = Clickwrap::Eg001CreateClickwrapService.new(session, request).call
-
- session[:clickwrap_id] = results.clickwrap_id
- session[:clickwrap_name] = results.clickwrap_name
-
- @title = 'Creating a new clickwrap'
- @h1 = 'Creating a new clickwrap'
- @message = "The clickwrap #{results.clickwrap_name} has been created!"
- @json = results.to_json.to_json
- render 'ds_common/example_done'
- end
-
- private
-
- def check_auth
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
- unless token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/clickwrap/eg002_activate_clickwrap_controller.rb b/app/controllers/clickwrap/eg002_activate_clickwrap_controller.rb
deleted file mode 100644
index 239733f..0000000
--- a/app/controllers/clickwrap/eg002_activate_clickwrap_controller.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-class Clickwrap::Eg002ActivateClickwrapController < EgController
- before_action :check_auth
-
- def create
- results = Clickwrap::Eg002ActivateClickwrapService.new(session).call
-
- @title = 'Activating a new clickwrap'
- @h1 = 'Activating a new clickwrap'
- @message = "The clickwrap #{results.clickwrap_name} has been activated"
- render 'ds_common/example_done'
- end
-
- private
-
- def check_auth
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
- unless token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/clickwrap/eg003_create_new_clickwrap_version_controller.rb b/app/controllers/clickwrap/eg003_create_new_clickwrap_version_controller.rb
deleted file mode 100644
index 456078b..0000000
--- a/app/controllers/clickwrap/eg003_create_new_clickwrap_version_controller.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-class Clickwrap::Eg003CreateNewClickwrapVersionController < EgController
- before_action :check_auth
-
- def create
- results = Clickwrap::Eg003CreateNewClickwrapVersionService.new(session).call
- puts results.to_json.to_json
- @title = 'Creating a new clickwrap version'
- @h1 = 'Creating a new clickwrap version'
- @message = "Version #{results.version_number} of clickwrap #{results.clickwrap_name} has been created"
- render 'ds_common/example_done'
- end
-
- private
-
- def check_auth
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
- unless token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/clickwrap/eg004_list_clickwraps_controller.rb b/app/controllers/clickwrap/eg004_list_clickwraps_controller.rb
deleted file mode 100644
index d345013..0000000
--- a/app/controllers/clickwrap/eg004_list_clickwraps_controller.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-class Clickwrap::Eg004ListClickwrapsController < EgController
- before_action :check_auth
-
- def create
- results = Clickwrap::Eg004ListClickwrapsService.new(session, request).call
-
- @title = 'List clickwraps results'
- @h1 = 'List clickwraps results'
- @message = "Results from the ClickWraps::getClickwraps method:"
- @json = results.to_json.to_json
- render 'ds_common/example_done'
- end
-
- private
-
- def check_auth
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
- unless token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/clickwrap/eg005_clickwrap_responses_controller.rb b/app/controllers/clickwrap/eg005_clickwrap_responses_controller.rb
deleted file mode 100644
index c639807..0000000
--- a/app/controllers/clickwrap/eg005_clickwrap_responses_controller.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-class Clickwrap::Eg005ClickwrapResponsesController < EgController
- before_action :check_auth
-
- def create
- results = Clickwrap::Eg005ClickwrapResponsesService.new(session, request).call
-
- @title = 'Getting clickwrap responses'
- @h1 = 'Getting clickwrap responses'
- @message = "Results from the ClickWraps::getClickwrapAgreements method:"
- @json = results.to_json.to_json
- render 'ds_common/example_done'
- end
-
- private
-
- def check_auth
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
- unless token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/connect/cneg001_validate_webhook_message_controller.rb b/app/controllers/connect/cneg001_validate_webhook_message_controller.rb
new file mode 100644
index 0000000..9da1522
--- /dev/null
+++ b/app/controllers/connect/cneg001_validate_webhook_message_controller.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+require_relative '../../services/utils'
+
+class Connect::Cneg001ValidateWebhookMessageController < EgController
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 1, 'Connect') }
+
+ def create
+ args = {
+ secret: params['secret'],
+ payload: params['payload']
+ }
+ results = Connect::Eg001ValidateWebhookMessageService.new(args).worker
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results)
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+end
diff --git a/app/controllers/connected_fields/feg001_set_connected_fields_controller.rb b/app/controllers/connected_fields/feg001_set_connected_fields_controller.rb
new file mode 100644
index 0000000..954dec8
--- /dev/null
+++ b/app/controllers/connected_fields/feg001_set_connected_fields_controller.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+require_relative '../../services/utils'
+
+class ConnectedFields::Feg001SetConnectedFieldsController < EgController
+ before_action -> { check_auth('ConnectedFields') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 1, 'ConnectedFields') }
+
+ def get
+ super
+ args = {
+ account_id: session['ds_account_id'],
+ access_token: session['ds_access_token'],
+ extensions_base_path: 'https://api-d.docusign.com'
+ }
+
+ example_service = ConnectedFields::Eg001SetConnectedFieldsService.new(args)
+ @apps = example_service.get_tab_groups
+
+ return unless @apps.nil? || @apps.empty?
+
+ additional_page_data = example['AdditionalPage'].find { |p| p['Name'] == 'no_verification_app' }
+
+ @title = @example['ExampleName']
+ @message = additional_page_data['ResultsPageText']
+ render 'ds_common/example_done'
+ end
+
+ def create
+ envelope_args = {
+ signer_email: param_gsub(params['signerEmail']),
+ signer_name: param_gsub(params['signerName']),
+ doc_pdf: File.join('data', Rails.application.config.doc_pdf)
+ }
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ extensions_base_path: 'https://api-d.docusign.com',
+ access_token: session['ds_access_token'],
+ selected_app_id: param_gsub(params['appId']),
+ envelope_args: envelope_args
+ }
+
+ example_service = ConnectedFields::Eg001SetConnectedFieldsService.new(args)
+ apps = example_service.get_tab_groups
+ selected_app = apps.find { |app| app['appId'] == args[:selected_app_id] }
+
+ results = example_service.send_envelope selected_app
+ session[:envelope_id] = results['envelope_id']
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results['envelope_id'])
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+end
diff --git a/app/controllers/ds_common_controller.rb b/app/controllers/ds_common_controller.rb
index 9d366c4..dc350a3 100644
--- a/app/controllers/ds_common_controller.rb
+++ b/app/controllers/ds_common_controller.rb
@@ -6,64 +6,122 @@ class DsCommonController < ApplicationController
def index
@show_doc = Rails.application.config.documentation
- if Rails.configuration.examples_API['Rooms'] == true
- render 'room_api/index'
- elsif Rails.configuration.examples_API['Click'] == true
- render 'clickwrap/index'
+ handle_redirects
+ end
+
+ def handle_redirects
+ if Rails.configuration.quickstart
+ @manifest = Utils::ManifestUtils.new.get_manifest(Rails.configuration.example_manifest_url)
+
+ if session[:quickstarted].nil?
+ session[:api] = 'eSignature'
+ session[:quickstarted] = true
+ redirect_to '/auth/docusign'
+ elsif session[:been_here].nil?
+ return redirect_to '/auth/docusign' if session[:ds_access_token].nil? || session[:ds_base_path].nil?
+
+ enableCFR = ESign::GetDataService.new(session[:ds_access_token], session[:ds_base_path]).cfr?(session[:ds_account_id])
+ if enableCFR == 'enabled'
+ session[:status_cfr] = 'enabled'
+ @status_cfr = session[:status_cfr]
+ redirect_to '/eeg041'
+ else
+ redirect_to '/eeg001'
+ end
+ else
+ render_examples
+ end
+ elsif check_token
+ if !session[:api] || session[:api] == 'eSignature'
+ enableCFR = ESign::GetDataService.new(session[:ds_access_token], session[:ds_base_path]).cfr?(session[:ds_account_id])
+ session[:status_cfr] = 'enabled' if enableCFR == 'enabled'
+ end
+ render_examples
else
- @show_doc = Rails.application.config.documentation
- if Rails.configuration.quickstart == true && session[:been_here].nil?
- redirect_to '/eg001'
+ render_examples
+ end
+ end
+
+ def render_examples
+ if check_token && !session[:status_cfr] && (!session[:api] || session[:api] == 'eSignature')
+ enableCFR = ESign::GetDataService.new(session[:ds_access_token], session[:ds_base_path]).cfr?(session[:ds_account_id])
+ if enableCFR == 'enabled'
+ @status_cfr = 'enabled'
+ session[:status_cfr] = 'enabled'
end
+ else
+ @status_cfr = session[:status_cfr]
end
+ load_manifest
end
def ds_return
# To break out of the Quickstart loop an example has been completed
session[:been_here] = true
- @title = 'Return from DocuSign'
+ @title = 'Return from Docusign'
@event = request.params['event']
@state = request.params['state']
@envelope_id = request.params['envelopeId']
end
def ds_must_authenticate
- if Rails.configuration.quickstart == "true"
- redirect_to('auth/docusign')
- end
- @title = 'Authenticate with DocuSign'
+ load_manifest
+
+ jwt_auth if session[:api] == 'Monitor'
+ redirect_to '/auth/docusign' if Rails.configuration.quickstart && session[:been_here].nil?
+ @title = 'Authenticate with Docusign'
@show_doc = Rails.application.config.documentation
- if params[:auth] == 'grand-auth'
- redirect_to('/auth/docusign')
- elsif params[:auth] == 'jwt-auth'
- if JwtAuth::JwtCreator.new(session).check_jwt_token
- if session[:eg]
- url = "/" + session[:eg]
- else
- url = root_path
- end
- else
- url = JwtAuth::JwtCreator.consent_url
+ case params[:auth]
+ when 'grand-auth'
+ redirect_to '/auth/docusign'
+ when 'jwt-auth'
+ jwt_auth
+ end
+ end
+
+ def jwt_auth
+ if JwtAuth::JwtCreator.new(session).check_jwt_token
+ url = if session[:eg]
+ "/#{session[:eg]}"
+ else
+ root_path
+ end
+ else
+ session['omniauth.state'] = SecureRandom.hex
+ url = JwtAuth::JwtCreator.consent_url(session['omniauth.state'], session['api'])
redirect_to root_path if session[:token].present?
- end
- if Rails.configuration.examples_API['Rooms'] == true
- configuration = DocuSign_Rooms::Configuration.new
- api_client = DocuSign_Rooms::ApiClient.new(configuration)
- elsif Rails.configuration.examples_API['Click'] == true
- configuration = DocuSign_Click::Configuration.new
- api_client = DocuSign_Click::ApiClient.new configuration
- end
- resp = ::JwtAuth::JwtCreator.new(session).check_jwt_token
- if resp.is_a? String
- redirect_to resp
- end
- redirect_to url
end
+ case session[:api]
+ when 'Rooms'
+ configuration = DocuSign_Rooms::Configuration.new
+ DocuSign_Rooms::ApiClient.new(configuration)
+ when 'Click'
+ configuration = DocuSign_Click::Configuration.new
+ DocuSign_Click::ApiClient.new configuration
+ when 'Admin'
+ configuration = DocuSign_Admin::Configuration.new
+ DocuSign_Admin::ApiClient.new configuration
+ end
+ resp = ::JwtAuth::JwtCreator.new(session).check_jwt_token
+ redirect_to resp if resp.is_a? String
+ redirect_to url
end
def example_done; end
def error; end
+ private
+
+ def load_manifest
+ @manifest = Utils::ManifestUtils.new.get_manifest(Rails.configuration.example_manifest_url)
+ end
+
+ def check_token(buffer_in_min = 10)
+ buffer = buffer_in_min * 60
+ expires_at = session[:ds_expires_at]
+ remaining_duration = expires_at.nil? ? 0 : expires_at - buffer.seconds.from_now.to_i
+ remaining_duration.positive?
+ end
end
diff --git a/app/controllers/e_sign/eeg002_signing_via_email_controller.rb b/app/controllers/e_sign/eeg002_signing_via_email_controller.rb
new file mode 100644
index 0000000..a606a2c
--- /dev/null
+++ b/app/controllers/e_sign/eeg002_signing_via_email_controller.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+require_relative '../../services/utils'
+
+class ESign::Eeg002SigningViaEmailController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 2, 'eSignature') }
+
+ def create
+ envelope_args = {
+ signer_email: param_gsub(params['signerEmail']),
+ signer_name: param_gsub(params['signerName']),
+ cc_email: param_gsub(params['ccEmail']),
+ cc_name: param_gsub(params['ccName']),
+ status: 'sent',
+ doc_docx: File.join('data', Rails.application.config.doc_docx),
+ doc_pdf: File.join('data', Rails.application.config.doc_pdf)
+ }
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ envelope_args: envelope_args
+ }
+ results = ESign::Eg002SigningViaEmailService.new(args).worker
+ session[:envelope_id] = results['envelope_id']
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results['envelope_id'])
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+end
diff --git a/app/controllers/e_sign/eeg003_list_envelopes_controller.rb b/app/controllers/e_sign/eeg003_list_envelopes_controller.rb
new file mode 100644
index 0000000..459a242
--- /dev/null
+++ b/app/controllers/e_sign/eeg003_list_envelopes_controller.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class ESign::Eeg003ListEnvelopesController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 3, 'eSignature') }
+
+ def create
+ args = {
+ account_id: session[:ds_account_id],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token]
+ }
+ results = ESign::Eg003ListEnvelopesService.new(args).worker
+ @title = @example['ExampleName']
+ @message = @example['ResultsPageText']
+ @json = results.to_json.to_json
+ render 'ds_common/example_done'
+ end
+end
diff --git a/app/controllers/e_sign/eeg004_envelope_info_controller.rb b/app/controllers/e_sign/eeg004_envelope_info_controller.rb
new file mode 100644
index 0000000..ea10ea1
--- /dev/null
+++ b/app/controllers/e_sign/eeg004_envelope_info_controller.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+class ESign::Eeg004EnvelopeInfoController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 4, 'eSignature') }
+
+ def create
+ envelope_id = session[:envelope_id]
+
+ if envelope_id
+ begin
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ envelope_id: envelope_id
+ }
+ results = ESign::Eg004EnvelopeInfoService.new(args).worker
+ # results is an object that implements ArrayAccess. Convert to a regular array:
+ @title = @example['ExampleName']
+ @message = @example['ResultsPageText']
+ @json = results.to_json.to_json
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+ elsif !envelope_id
+ @title = @example['ExampleName']
+ @envelope_ok = false
+ end
+ end
+end
diff --git a/app/controllers/e_sign/eeg005_envelope_recipients_controller.rb b/app/controllers/e_sign/eeg005_envelope_recipients_controller.rb
new file mode 100644
index 0000000..a5d962d
--- /dev/null
+++ b/app/controllers/e_sign/eeg005_envelope_recipients_controller.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+class ESign::Eeg005EnvelopeRecipientsController < EgController
+ include ApiCreator
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 5, 'eSignature') }
+ skip_before_action :set_meta
+
+ def create
+ envelope_id = session[:envelope_id] || nil
+
+ if envelope_id
+ # 2. Call the worker method
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ envelope_id: envelope_id
+ }
+
+ begin
+ results = ESign::Eg005EnvelopeRecipientsService.new(args).worker
+ @title = @example['ExampleName']
+ @message = 'Results from the EnvelopesRecipients::list method:'
+ @json = results.to_json.to_json
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+ elsif !envelope_id
+ @title = @example['ExampleName']
+ @envelope_ok = false
+ end
+ end
+end
diff --git a/app/controllers/e_sign/eeg006_envelope_docs_controller.rb b/app/controllers/e_sign/eeg006_envelope_docs_controller.rb
new file mode 100644
index 0000000..4eb859d
--- /dev/null
+++ b/app/controllers/e_sign/eeg006_envelope_docs_controller.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+class ESign::Eeg006EnvelopeDocsController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 6, 'eSignature') }
+
+ def create
+ envelope_id = session[:envelope_id]
+
+ if envelope_id
+ begin
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ envelope_id: envelope_id
+ }
+
+ standart_doc_items = [
+ { name: 'Combined', type: 'content', document_id: 'combined' },
+ { name: 'Zip archive', type: 'zip', document_id: 'archive' },
+ { name: 'PDF Portfolio', type: 'content', document_id: 'portfolio' }
+ ]
+
+ results = ESign::Eg006EnvelopeDocsService.new(args).worker
+ # The certificate of completion is named "summary"
+ # We give it a better name below.
+ envelope_doc_items = results.envelope_documents.map do |doc|
+ new = if doc.document_id == 'certificate'
+ { document_id: doc.document_id, name: 'Certificate of completion', type: doc.type }
+ else
+ { document_id: doc.document_id, name: doc.name, type: doc.type }
+ end
+ new
+ end
+
+ documents = standart_doc_items + envelope_doc_items
+ envelope_documents = { envelope_id: args[:envelope_id], documents: documents }
+ session[:envelope_documents] = envelope_documents
+
+ @title = @example['ExampleName']
+ @message = @example['ResultsPageText']
+ @json = results.to_json.to_json
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+ elsif !envelope_id
+ @title = @example['ExampleName']
+ @envelope_ok = false
+ end
+ end
+end
diff --git a/app/controllers/e_sign/eeg007_envelope_get_doc_controller.rb b/app/controllers/e_sign/eeg007_envelope_get_doc_controller.rb
new file mode 100644
index 0000000..59303a8
--- /dev/null
+++ b/app/controllers/e_sign/eeg007_envelope_get_doc_controller.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+class ESign::Eeg007EnvelopeGetDocController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 7, 'eSignature') }
+
+ def create
+ envelope_id = session[:envelope_id]
+ envelope_documents = session[:envelope_documents]
+ if envelope_id && envelope_documents
+ begin
+ document_id = param_gsub(params['docSelect'])
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ envelope_id: envelope_id,
+ document_id: document_id,
+ envelope_documents: envelope_documents
+ }
+ results = ESign::Eg007EnvelopeGetDocService.new(args).worker
+ send_data results['data'], filename: results['doc_name'],
+ content_type: results['mime_type'],
+ disposition: "attachment; filename=\"#{results['doc_name']}\""
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+ elsif !envelope_id || !envelope_documents
+ @title = @example['ExampleName']
+ @envelope_ok = false
+ @documents_ok = false
+ end
+ end
+end
diff --git a/app/controllers/e_sign/eeg008_create_template_controller.rb b/app/controllers/e_sign/eeg008_create_template_controller.rb
new file mode 100644
index 0000000..4a38528
--- /dev/null
+++ b/app/controllers/e_sign/eeg008_create_template_controller.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class ESign::Eeg008CreateTemplateController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 8, 'eSignature') }
+
+ def create
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ template_name: 'Example Signer and CC template v2'
+ }
+ results = ESign::Eg008CreateTemplateService.new(args).worker
+ session[:template_id] = results[:template_id]
+ session[:workflow_template_id] = results[:template_id]
+ msg = if results.fetch(:created_new_template)
+ 'The template has been created!'
+ else
+ 'Done. The template already existed in your account.'
+ end
+ @title = @example['ExampleName']
+ @message = "#{msg} #{format_string(@example['ResultsPageText'], results[:template_name], results[:template_id])}"
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+end
diff --git a/app/controllers/e_sign/eeg009_use_template_controller.rb b/app/controllers/e_sign/eeg009_use_template_controller.rb
new file mode 100644
index 0000000..9e4f625
--- /dev/null
+++ b/app/controllers/e_sign/eeg009_use_template_controller.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+class ESign::Eeg009UseTemplateController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 9, 'eSignature') }
+
+ def create
+ template_id = session[:template_id]
+
+ if template_id
+ begin
+ envelope_args = {
+ signer_email: params['signerEmail'],
+ signer_name: params['signerName'],
+ cc_email: params['ccEmail'],
+ cc_name: params['ccName'],
+ template_id: template_id
+ }
+
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ envelope_args: envelope_args
+ }
+
+ results = ESign::Eg009UseTemplateService.new(args).worker
+
+ session[:envelope_id] = results[:envelope_id]
+ # results is an object that implements ArrayAccess. Convert to a regular array:
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results[:envelope_id])
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+ elsif !template_id
+ @title = @example['ExampleName']
+ @template_ok = false
+ end
+ end
+end
diff --git a/app/controllers/e_sign/eeg010_send_binary_docs_controller.rb b/app/controllers/e_sign/eeg010_send_binary_docs_controller.rb
new file mode 100644
index 0000000..4039f64
--- /dev/null
+++ b/app/controllers/e_sign/eeg010_send_binary_docs_controller.rb
@@ -0,0 +1,36 @@
+class ESign::Eeg010SendBinaryDocsController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 10, 'eSignature') }
+
+ def create
+ envelope_args = {
+ # Validation: Delete any non-usual characters
+ signer_email: param_gsub(params['signerEmail']),
+ signer_name: param_gsub(params['signerName']),
+ cc_email: param_gsub(params['ccEmail']),
+ cc_name: param_gsub(params['ccName'])
+ }
+
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ envelope_args: envelope_args
+ }
+
+ results = ESign::Eg010SendBinaryDocsService.new(args).worker
+ session[:envelope_id] = results['envelope_id']
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results['envelope_id'])
+ render 'ds_common/example_done'
+ rescue Net::HTTPError => e
+ if !e.response.nil?
+ json_response = JSON.parse e.response
+ @error_code = json_response['errorCode']
+ @error_message = json_response['message']
+ else
+ @error_code = 'API request problem'
+ @error_message = e.to_s
+ end
+ end
+end
diff --git a/app/controllers/e_sign/eeg011_embedded_sending_controller.rb b/app/controllers/e_sign/eeg011_embedded_sending_controller.rb
new file mode 100644
index 0000000..ad1f9ac
--- /dev/null
+++ b/app/controllers/e_sign/eeg011_embedded_sending_controller.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+class ESign::Eeg011EmbeddedSendingController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 11, 'eSignature') }
+
+ def create
+ envelope_args = {
+ signer_email: param_gsub(params['signerEmail']),
+ signer_name: param_gsub(params['signerName']),
+ cc_email: param_gsub(params['ccEmail']),
+ cc_name: param_gsub(params['ccName']),
+ status: 'created'
+ }
+
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ starting_view: param_gsub(params['starting_view']),
+ envelope_args: envelope_args,
+ ds_return_url: "#{Rails.application.config.app_url}/ds_common-return"
+ }
+
+ results = ESign::Eg011EmbeddedSendingService.new(args).worker
+ redirect_to results['redirect_url']
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+end
diff --git a/app/controllers/e_sign/eeg012_embedded_console_controller.rb b/app/controllers/e_sign/eeg012_embedded_console_controller.rb
new file mode 100644
index 0000000..b2dc4cf
--- /dev/null
+++ b/app/controllers/e_sign/eeg012_embedded_console_controller.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class ESign::Eeg012EmbeddedConsoleController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 12, 'eSignature') }
+
+ def create
+ envelope_id = session[:envelope_id]
+
+ begin
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ envelope_id: envelope_id,
+ starting_view: params['starting_view'],
+ ds_return_url: "#{Rails.application.config.app_url}/ds_common-return"
+ }
+
+ results = ESign::Eg012EmbeddedConsoleService.new(args).worker
+ redirect_to results['redirect_url']
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+ end
+end
diff --git a/app/controllers/e_sign/eeg013_add_doc_to_template_controller.rb b/app/controllers/e_sign/eeg013_add_doc_to_template_controller.rb
new file mode 100644
index 0000000..7bc2333
--- /dev/null
+++ b/app/controllers/e_sign/eeg013_add_doc_to_template_controller.rb
@@ -0,0 +1,52 @@
+# frozen_string_literal: true
+
+class ESign::Eeg013AddDocToTemplateController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 13, 'eSignature') }
+
+ def create
+ template_id = session[:template_id]
+
+ if template_id
+ # 2. Call the worker method
+ # More data validation would be a good idea here
+ # Strip anything other than characters listed
+ begin
+ envelope_args = {
+ signer_email: param_gsub(params['signerEmail']),
+ signer_name: param_gsub(params['signerName']),
+ cc_email: param_gsub(params['ccEmail']),
+ cc_name: param_gsub(params['ccName']),
+ item: param_gsub(params['item']),
+ quantity: param_gsub(params['quantity']).to_i,
+ signer_client_id: 1000,
+ template_id: template_id,
+ ds_return_url: "#{Rails.application.config.app_url}/ds_common-return"
+ }
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ envelope_args: envelope_args
+ }
+ results = ESign::Eg013AddDocToTemplateService.new(args).worker
+ # Save for use by other examples
+ # which need an envelopeId
+ session[:envelope_id] = results[:envelope_id]
+ # Redirect the user to the embedded signing
+ # Don't use an iFrame!
+ # State can be stored/recovered using the framework's session or a
+ # query parameter on the returnUrl
+ redirect_to results[:redirect_url]
+ rescue DocuSign_eSign::ApiError => e
+ error = JSON.parse e.response_body
+ @error_code = error['errorCode']
+ @error_message = error['message']
+ render 'ds_common/error'
+ end
+ elsif !template_id
+ @title = @example['ExampleName']
+ @template_ok = false
+ end
+ end
+end
diff --git a/app/controllers/e_sign/eeg014_collect_payment_controller.rb b/app/controllers/e_sign/eeg014_collect_payment_controller.rb
new file mode 100644
index 0000000..f3dd68b
--- /dev/null
+++ b/app/controllers/e_sign/eeg014_collect_payment_controller.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+class ESign::Eeg014CollectPaymentController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 14, 'eSignature') }
+
+ def create
+ envelope_args = {
+ signer_email: param_gsub(params['signerEmail']),
+ signer_name: param_gsub(params['signerName']),
+ cc_email: param_gsub(params['ccEmail']),
+ cc_name: param_gsub(params['ccName']),
+ gateway_account_id: Rails.application.config.gateway_account_id,
+ gateway_name: Rails.application.config.gateway_name,
+ gateway_display_name: Rails.application.config.gateway_display_name
+ }
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ envelope_args: envelope_args
+ }
+
+ results = ESign::Eg014CollectPaymentService.new(args).worker
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results[:envelope_id])
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+
+ def get
+ enableCFR = ESign::GetDataService.new(session[:ds_access_token], session[:ds_base_path]).cfr?(session[:ds_account_id])
+ if enableCFR == 'enabled'
+ session[:status_cfr] = 'enabled'
+ @title = 'Not CFR Part 11 compatible'
+ @error_information = @manifest['SupportingTexts']['CFRError']
+ render 'ds_common/error'
+ end
+ super
+ end
+end
diff --git a/app/controllers/e_sign/eeg015_get_envelope_tab_data_controller.rb b/app/controllers/e_sign/eeg015_get_envelope_tab_data_controller.rb
new file mode 100644
index 0000000..f47566b
--- /dev/null
+++ b/app/controllers/e_sign/eeg015_get_envelope_tab_data_controller.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class ESign::Eeg015GetEnvelopeTabDataController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 15, 'eSignature') }
+
+ def create
+ envelope_id = session[:envelope_id]
+
+ args = {
+ access_token: session['ds_access_token'],
+ base_path: session['ds_base_path'],
+ account_id: session['ds_account_id'],
+ envelope_id: envelope_id
+ }
+
+ results = ESign::Eg015GetEnvelopeTabDataService.new(args).worker
+ @title = @example['ExampleName']
+ @message = 'Results from the EnvelopeFormData::get method:'
+ @json = results.to_json.to_json
+ render 'ds_common/example_done'
+ end
+end
diff --git a/app/controllers/e_sign/eeg016_set_envelope_tab_data_controller.rb b/app/controllers/e_sign/eeg016_set_envelope_tab_data_controller.rb
new file mode 100644
index 0000000..bdcb013
--- /dev/null
+++ b/app/controllers/e_sign/eeg016_set_envelope_tab_data_controller.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class ESign::Eeg016SetEnvelopeTabDataController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 16, 'eSignature') }
+
+ def create
+ args = {
+ # Validation: Delete any non-usual characters
+ signer_email: params['signerEmail'].gsub(/([^\w\-.+@, ])+/, ''),
+ signer_name: params['signerName'].gsub(/([^\w\-., ])+/, ''),
+ access_token: session['ds_access_token'],
+ base_path: session['ds_base_path'],
+ account_id: session['ds_account_id']
+ }
+
+ begin
+ results = ESign::Eg016SetEnvelopeTabDataService.new(args).worker
+
+ # Save for future use within the example launcher
+ session[:envelope_id] = results[:envelope_id]
+
+ redirect_to results[:url]
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+ end
+end
diff --git a/app/controllers/e_sign/eeg017_set_template_tab_values_controller.rb b/app/controllers/e_sign/eeg017_set_template_tab_values_controller.rb
new file mode 100644
index 0000000..e024a70
--- /dev/null
+++ b/app/controllers/e_sign/eeg017_set_template_tab_values_controller.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+class ESign::Eeg017SetTemplateTabValuesController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 17, 'eSignature') }
+
+ def create
+ template_id = session[:template_id]
+
+ if template_id
+ envelope_args = {
+ signer_email: params['signerEmail'],
+ signer_name: params['signerName'],
+ cc_email: params['ccEmail'],
+ cc_name: params['ccName'],
+ ds_ping_url: Rails.application.config.app_url,
+ template_id: template_id
+ }
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ envelope_args: envelope_args
+ }
+ begin
+ redirect_url = ESign::Eg017SetTemplateTabValuesService.new(args).worker
+ redirect_to redirect_url
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+ elsif !template_id
+ @title = @example['ExampleName']
+ @template_ok = false
+ end
+ end
+end
diff --git a/app/controllers/e_sign/eeg018_get_envelope_custom_field_data_controller.rb b/app/controllers/e_sign/eeg018_get_envelope_custom_field_data_controller.rb
new file mode 100644
index 0000000..cd05b28
--- /dev/null
+++ b/app/controllers/e_sign/eeg018_get_envelope_custom_field_data_controller.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class ESign::Eeg018GetEnvelopeCustomFieldDataController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 18, 'eSignature') }
+
+ def create
+ envelope_id = session[:envelope_id]
+
+ args = {
+ access_token: session['ds_access_token'],
+ base_path: session['ds_base_path'],
+ account_id: session['ds_account_id'],
+ envelope_id: envelope_id
+ }
+
+ results = ESign::Eg018GetEnvelopeCustomFieldDataService.new(args).worker
+ @title = @example['ExampleName']
+ @message = 'Results from the Envelopes::listStatusChanges method:'
+ @json = results.to_json.to_json
+ render 'ds_common/example_done'
+ end
+end
diff --git a/app/controllers/e_sign/eeg019_access_code_authentication_controller.rb b/app/controllers/e_sign/eeg019_access_code_authentication_controller.rb
new file mode 100644
index 0000000..eb02c89
--- /dev/null
+++ b/app/controllers/e_sign/eeg019_access_code_authentication_controller.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+class ESign::Eeg019AccessCodeAuthenticationController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 19, 'eSignature') }
+
+ def create
+ # ***DS.snippet.0.start
+ envelope_args = {
+ signer_email: param_gsub(params['signerEmail']),
+ signer_name: param_gsub(params['signerName']),
+ accessCode: params['accessCode'],
+ 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
+ }
+
+ results = ESign::Eg019AccessCodeAuthenticationService.new(args).worker
+ session[:envelope_id] = results.envelope_id
+
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results.envelope_id)
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+ # ***DS.snippet.0.end
+end
diff --git a/app/controllers/e_sign/eeg020_phone_authentication_controller.rb b/app/controllers/e_sign/eeg020_phone_authentication_controller.rb
new file mode 100644
index 0000000..92aa261
--- /dev/null
+++ b/app/controllers/e_sign/eeg020_phone_authentication_controller.rb
@@ -0,0 +1,59 @@
+# frozen_string_literal: true
+
+class ESign::Eeg020PhoneAuthenticationController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 20, 'eSignature') }
+
+ def create
+ envelope_args = {
+ signer_email: param_gsub(params['signer_email']),
+ signer_name: param_gsub(params['signer_name']),
+ country_code: param_gsub(params['country_code']),
+ phone_number: param_gsub(params['phone_number']),
+ 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
+ }
+
+ if Rails.application.config.signer_email == envelope_args[:signer_email]
+ @error_code = 400
+ @error_message = @manifest['SupportingTexts']['IdenticalEmailsNotAllowedErrorMessage']
+ return render 'ds_common/error'
+ end
+
+ phone_auth_service = ESign::Eg020PhoneAuthenticationService.new(args)
+
+ # Retrieve the workflow id
+ workflow_id = phone_auth_service.get_workflow
+ session[:workflow_id] = workflow_id
+
+ results = phone_auth_service.worker(workflow_id)
+
+ if results.to_s == 'phone_auth_not_enabled'
+ @error_code = 'IDENTITY_WORKFLOW_INVALID_ID'
+ @error_message = 'The identity workflow ID specified is not valid.'
+ @error_information = @example['CustomErrorTexts'][0]['ErrorMessage']
+ render 'ds_common/error'
+ else
+ session[:envelope_id] = results.envelope_id
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results.envelope_id)
+ render 'ds_common/example_done'
+ end
+ end
+
+ def get
+ enableCFR = ESign::GetDataService.new(session[:ds_access_token], session[:ds_base_path]).cfr?(session[:ds_account_id])
+ if enableCFR == 'enabled'
+ session[:status_cfr] = 'enabled'
+ @title = 'Not CFR Part 11 compatible'
+ @error_information = @manifest['SupportingTexts']['CFRError']
+ render 'ds_common/error'
+ end
+ super
+ end
+end
diff --git a/app/controllers/e_sign/eeg022_kba_authentication_controller.rb b/app/controllers/e_sign/eeg022_kba_authentication_controller.rb
new file mode 100644
index 0000000..3601b79
--- /dev/null
+++ b/app/controllers/e_sign/eeg022_kba_authentication_controller.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+class ESign::Eeg022KbaAuthenticationController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 22, 'eSignature') }
+
+ def create
+ envelope_args = {
+ signer_email: param_gsub(params['signerEmail']),
+ signer_name: param_gsub(params['signerName']),
+ 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
+ }
+
+ if Rails.application.config.signer_email == envelope_args[:signer_email]
+ @error_code = 400
+ @error_message = @manifest['SupportingTexts']['IdenticalEmailsNotAllowedErrorMessage']
+ return render 'ds_common/error'
+ end
+
+ results = ESign::Eg022KbaAuthenticationService.new(args).worker
+ session[:envelope_id] = results.envelope_id
+
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results.envelope_id)
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+end
diff --git a/app/controllers/e_sign/eeg023_idv_authentication_controller.rb b/app/controllers/e_sign/eeg023_idv_authentication_controller.rb
new file mode 100644
index 0000000..ccc50c2
--- /dev/null
+++ b/app/controllers/e_sign/eeg023_idv_authentication_controller.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+class ESign::Eeg023IdvAuthenticationController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 23, 'eSignature') }
+
+ def create
+ envelope_args = {
+ signer_email: param_gsub(params['signerEmail']),
+ signer_name: param_gsub(params['signerName']),
+ 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
+ }
+
+ if Rails.application.config.signer_email == envelope_args[:signer_email]
+ @error_code = 400
+ @error_message = @manifest['SupportingTexts']['IdenticalEmailsNotAllowedErrorMessage']
+ return render 'ds_common/error'
+ end
+
+ results = ESign::Eg023IdvAuthenticationService.new(args).worker
+
+ if results.to_s == 'idv_not_enabled'
+ @error_code = 'IDENTITY_WORKFLOW_INVALID_ID'
+ @error_message = 'The identity workflow ID specified is not valid.'
+ @error_information = @example['CustomErrorTexts'][0]['ErrorMessage']
+ render 'ds_common/error'
+ else
+ session[:envelope_id] = results.envelope_id
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results.envelope_id)
+ render 'ds_common/example_done'
+ end
+ rescue DocuSign_eSign::ApiError => e
+ error = JSON.parse e.response_body
+ @error_code = error['errorCode']
+ @error_message = error['message']
+ render 'ds_common/error'
+ end
+
+ # ***DS.snippet.0.end
+end
diff --git a/app/controllers/e_sign/eeg024_permission_create_controller.rb b/app/controllers/e_sign/eeg024_permission_create_controller.rb
new file mode 100644
index 0000000..d477569
--- /dev/null
+++ b/app/controllers/e_sign/eeg024_permission_create_controller.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class ESign::Eeg024PermissionCreateController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 24, 'eSignature') }
+
+ def create
+ args = {
+ account_id: session[:ds_account_id],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token],
+ permission_profile_name: params[:permission_profile_name]
+ }
+
+ results = ESign::Eg024PermissionCreateService.new(args).worker
+ # Step 4. a) Call the eSignature API
+ # b) Display the JSON response
+ @title = @example['ExampleName']
+ @message = 'Permission profile was created'
+ @json = results.to_json.to_json
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+end
diff --git a/app/controllers/e_sign/eeg025_permissions_set_user_group_controller.rb b/app/controllers/e_sign/eeg025_permissions_set_user_group_controller.rb
new file mode 100644
index 0000000..505dd15
--- /dev/null
+++ b/app/controllers/e_sign/eeg025_permissions_set_user_group_controller.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+class ESign::Eeg025PermissionsSetUserGroupController < EgController
+ include ApiCreator
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 25, 'eSignature') }
+
+ def get
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token']
+ }
+ accounts_api = create_account_api(args)
+ permissions = accounts_api.list_permissions(args[:account_id], DocuSign_eSign::ListPermissionsOptions.default)
+ @permissions_lists = permissions.permission_profiles
+ # Get a user group
+ group_api = create_group_api(args)
+ @group_lists = group_api.list_groups(args[:account_id], DocuSign_eSign::ListGroupsOptions.default)
+ super
+ end
+
+ def create
+ args = {
+ account_id: session[:ds_account_id],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token],
+ permission_profile_id: params[:lists],
+ group_id: params[:group_lists]
+ }
+
+ results = ESign::Eg025PermissionsSetUserGroupService.new(args).worker
+ # Step 4. a) Call the eSignature API
+ # b) Display the JSON response
+ @title = @example['ExampleName']
+ @json = results.to_json.to_json
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+end
diff --git a/app/controllers/e_sign/eeg026_permissions_change_single_setting_controller.rb b/app/controllers/e_sign/eeg026_permissions_change_single_setting_controller.rb
new file mode 100644
index 0000000..9929a49
--- /dev/null
+++ b/app/controllers/e_sign/eeg026_permissions_change_single_setting_controller.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+class ESign::Eeg026PermissionsChangeSingleSettingController < EgController
+ include ApiCreator
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 26, 'eSignature') }
+
+ def get
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token']
+ }
+ accounts_api = create_account_api(args)
+ permissions = accounts_api.list_permissions(args[:account_id], DocuSign_eSign::ListPermissionsOptions.default)
+ @permissions_lists = permissions.permission_profiles
+ super
+ end
+
+ def create
+ args = {
+ account_id: session[:ds_account_id],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token],
+ permission_profile_id: params[:lists]
+ }
+
+ results = ESign::Eg026PermissionsChangeSingleSettingService.new(args).worker
+ # Step 4. a) Call the eSignature API
+ # b) Display the JSON response
+ @title = @example['ExampleName']
+ @message = 'Existing permission profile was changed'
+ @json = results.to_json.to_json
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+end
diff --git a/app/controllers/e_sign/eeg027_permissions_delete_controller.rb b/app/controllers/e_sign/eeg027_permissions_delete_controller.rb
new file mode 100644
index 0000000..95291b4
--- /dev/null
+++ b/app/controllers/e_sign/eeg027_permissions_delete_controller.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+class ESign::Eeg027PermissionsDeleteController < EgController
+ include ApiCreator
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 27, 'eSignature') }
+
+ def get
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token']
+ }
+ accounts_api = create_account_api(args)
+ permissions = accounts_api.list_permissions(args[:account_id], DocuSign_eSign::ListPermissionsOptions.default)
+ @permissions_lists = permissions.permission_profiles
+ super
+ end
+
+ def create
+ args = {
+ account_id: session[:ds_account_id],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token],
+ permission_profile_id: params[:lists]
+ }
+
+ ESign::Eg027PermissionsDeleteService.new(args).worker
+ # Step 4. a) Call the eSignature API
+ # b) Display the JSON response
+ @title = @example['ExampleName']
+ @message = "Permission profile #{params[:lists]} was deleted"
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+end
diff --git a/app/controllers/e_sign/eeg028_brands_creating_controller.rb b/app/controllers/e_sign/eeg028_brands_creating_controller.rb
new file mode 100644
index 0000000..6de5bec
--- /dev/null
+++ b/app/controllers/e_sign/eeg028_brands_creating_controller.rb
@@ -0,0 +1,25 @@
+class ESign::Eeg028BrandsCreatingController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 28, 'eSignature') }
+
+ def create
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ brandName: params[:brandName],
+ defaultBrandLanguage: params[:defaultBrandLanguage]
+ }
+
+ results = ESign::Eg028BrandsCreatingService.new(args).worker
+ # Step 4. a) Call the eSignature API
+ # b) Display the JSON response
+ brand_id = results.brands[0].brand_id
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], brand_id)
+ @json = results.to_json.to_json
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+end
diff --git a/app/controllers/e_sign/eeg029_brands_apply_to_envelope_controller.rb b/app/controllers/e_sign/eeg029_brands_apply_to_envelope_controller.rb
new file mode 100644
index 0000000..5b13850
--- /dev/null
+++ b/app/controllers/e_sign/eeg029_brands_apply_to_envelope_controller.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+class ESign::Eeg029BrandsApplyToEnvelopeController < EgController
+ include ApiCreator
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 29, 'eSignature') }
+
+ def get
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token']
+ }
+ accounts_api = create_account_api(args)
+ brand_lists = accounts_api.list_brands(args[:account_id], DocuSign_eSign::ListBrandsOptions.default)
+ @brand_names = brand_lists.brands
+ super
+ end
+
+ def create
+ envelope_args = {
+ signer_email: param_gsub(params[:signerEmail]),
+ signer_name: param_gsub(params[:signerName]),
+ brand_id: params[:brands],
+ 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
+ }
+
+ results = ESign::Eg029BrandsApplyToEnvelopeService.new(args).worker
+ session[:envelope_id] = results.envelope_id
+
+ # Step 4. a) Call the eSignature API
+ # b) Display the JSON response
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results.envelope_id)
+ @json = results.to_json.to_json
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+end
diff --git a/app/controllers/e_sign/eeg030_brands_apply_to_template_controller.rb b/app/controllers/e_sign/eeg030_brands_apply_to_template_controller.rb
new file mode 100644
index 0000000..0bdbc01
--- /dev/null
+++ b/app/controllers/e_sign/eeg030_brands_apply_to_template_controller.rb
@@ -0,0 +1,60 @@
+# frozen_string_literal: truebrand_lists = accounts_api.list_brands(args[:account_id], options = DocuSign_eSign::ListBrandsOptions.default)
+
+class ESign::Eeg030BrandsApplyToTemplateController < EgController
+ include ApiCreator
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 30, 'eSignature') }
+
+ def get
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token']
+ }
+ accounts_api = create_account_api(args)
+ brand_lists = accounts_api.list_brands(args[:account_id], DocuSign_eSign::ListBrandsOptions.default)
+ @brand_names = brand_lists.brands
+ super
+ end
+
+ def create
+ template_id = session[:template_id]
+
+ if template_id
+ begin
+ envelope_args = {
+ signer_email: param_gsub(params[:signerEmail]),
+ signer_name: param_gsub(params[:signerName]),
+ cc_email: param_gsub(params[:ccEmail]),
+ cc_name: param_gsub(params[:ccName]),
+ brand_id: params[:brands],
+ template_id: template_id,
+ 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
+ }
+
+ results = ESign::Eg030BrandsApplyToTemplateService.new(args).worker
+ session[:envelope_id] = results.envelope_id
+
+ # Step 4. a) Call the eSignature API
+ # b) Display the JSON response
+ # brand_id = results.brands[0].brand_id
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results.envelope_id)
+ @json = results.to_json.to_json
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+ elsif !template_id
+ @title = @example['ExampleName']
+ @template_ok = false
+ end
+ end
+end
diff --git a/app/controllers/e_sign/eeg031_bulk_sending_envelopes_controller.rb b/app/controllers/e_sign/eeg031_bulk_sending_envelopes_controller.rb
new file mode 100644
index 0000000..a4b4e84
--- /dev/null
+++ b/app/controllers/e_sign/eeg031_bulk_sending_envelopes_controller.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+class ESign::Eeg031BulkSendingEnvelopesController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 31, 'eSignature') }
+
+ def create
+ signers = {
+ signer_email: param_gsub(params['signerEmail1']),
+ signer_name: param_gsub(params['signerName1']),
+ cc_email: param_gsub(params['ccEmail1']),
+ cc_name: param_gsub(params['ccName1']),
+ status: 'created',
+
+ signer_email1: param_gsub(params['signerEmail2']),
+ signer_name1: param_gsub(params['signerName2']),
+ cc_email1: param_gsub(params['ccEmail2']),
+ cc_name1: param_gsub(params['ccName2'])
+ }
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token']
+ }
+
+ results = ESign::Eg031BulkSendingEnvelopesService.new(args, signers).worker
+ # Step 4. a) Call the eSignature API
+ # b) Display the JSON response
+ @title = @example['ExampleName']
+ @message = @example['ResultsPageText']
+ @json = results.to_json.to_json
+
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+end
diff --git a/app/controllers/e_sign/eeg032_pauses_signature_workflow_controller.rb b/app/controllers/e_sign/eeg032_pauses_signature_workflow_controller.rb
new file mode 100644
index 0000000..cf7e25c
--- /dev/null
+++ b/app/controllers/e_sign/eeg032_pauses_signature_workflow_controller.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+class ESign::Eeg032PausesSignatureWorkflowController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 32, 'eSignature') }
+
+ def create
+ signers = {
+ signerEmail1: param_gsub(params['signerEmail1']),
+ signerName1: param_gsub(params['signerName1']),
+ signerEmail2: param_gsub(params['signerEmail2']),
+ signerName2: param_gsub(params['signerName2'])
+ }
+ args = {
+ accountId: session['ds_account_id'],
+ basePath: session['ds_base_path'],
+ accessToken: session['ds_access_token'],
+ status: 'sent'
+ }
+
+ results = ESign::Eg032PausesSignatureWorkflowService.new(args, signers).worker
+
+ @envelop_id = results.to_hash[:envelopeId].to_s
+ session[:envelope_id] = @envelop_id
+
+ render 'e_sign/eeg032_pauses_signature_workflow/return'
+ end
+
+ def get
+ enableCFR = ESign::GetDataService.new(session[:ds_access_token], session[:ds_base_path]).cfr?(session[:ds_account_id])
+ if enableCFR == 'enabled'
+ session[:status_cfr] = 'enabled'
+ @title = 'Not CFR Part 11 compatible'
+ @error_information = @manifest['SupportingTexts']['CFRError']
+ render 'ds_common/error'
+ end
+ super
+ end
+end
diff --git a/app/controllers/e_sign/eeg033_unpauses_signature_workflow_controller.rb b/app/controllers/e_sign/eeg033_unpauses_signature_workflow_controller.rb
new file mode 100644
index 0000000..001a3bc
--- /dev/null
+++ b/app/controllers/e_sign/eeg033_unpauses_signature_workflow_controller.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+class ESign::Eeg033UnpausesSignatureWorkflowController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 33, 'eSignature') }
+
+ def update
+ args = {
+ accountId: session['ds_account_id'],
+ basePath: session['ds_base_path'],
+ accessToken: session['ds_access_token'],
+ envelopeId: session['envelope_id'],
+ status: 'in_progress'
+ }
+
+ results = ESign::Eg033UnpausesSignatureWorkflowService.new(args).worker
+
+ @envelop_id = results.to_hash[:envelopeId].to_s
+ render 'e_sign/eeg033_unpauses_signature_workflow/return'
+ end
+
+ def get
+ enableCFR = ESign::GetDataService.new(session[:ds_access_token], session[:ds_base_path]).cfr?(session[:ds_account_id])
+ if enableCFR == 'enabled'
+ session[:status_cfr] = 'enabled'
+ @title = 'Not CFR Part 11 compatible'
+ @error_information = @manifest['SupportingTexts']['CFRError']
+ render 'ds_common/error'
+ end
+ super
+ end
+end
diff --git a/app/controllers/e_sign/eeg034_use_conditional_recipients_controller.rb b/app/controllers/e_sign/eeg034_use_conditional_recipients_controller.rb
new file mode 100644
index 0000000..ab7e5a2
--- /dev/null
+++ b/app/controllers/e_sign/eeg034_use_conditional_recipients_controller.rb
@@ -0,0 +1,50 @@
+# frozen_string_literal: true
+
+class ESign::Eeg034UseConditionalRecipientsController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 34, 'eSignature') }
+
+ def create
+ signers = {
+ signerEmail1: param_gsub(params['signerEmail1']),
+ signerName1: param_gsub(params['signerName1']),
+
+ signerEmailNotChecked: param_gsub(params['signerEmailNotChecked']),
+ signerNameNotChecked: param_gsub(params['signerNameNotChecked']),
+
+ signerEmailChecked: param_gsub(params['signerEmailChecked']),
+ signerNameChecked: param_gsub(params['signerNameChecked'])
+ }
+
+ args = {
+ accountId: session['ds_account_id'],
+ basePath: session['ds_base_path'],
+ accessToken: session['ds_access_token']
+ }
+
+ results = ESign::Eg034UseConditionalRecipientsService.new(args, signers).worker
+ @envelop_id = results.to_hash[:envelopeId].to_s
+ render 'e_sign/eeg034_use_conditional_recipients/return'
+ rescue DocuSign_eSign::ApiError => e
+ error = JSON.parse e.response_body
+ @error_code = error['errorCode']
+ if error['errorCode']['WORKFLOW_UPDATE_RECIPIENTROUTING_NOT_ALLOWED']
+ @error_message = @example['CustomErrorTexts'][0]['ErrorMessage']
+ @error_information = @example['CustomErrorTexts'][0]['ErrorMessage']
+ else
+ @error_message = error['message']
+ end
+ render 'ds_common/error'
+ end
+
+ def get
+ enableCFR = ESign::GetDataService.new(session[:ds_access_token], session[:ds_base_path]).cfr?(session[:ds_account_id])
+ if enableCFR == 'enabled'
+ session[:status_cfr] = 'enabled'
+ @title = 'Not CFR Part 11 compatible'
+ @error_information = @manifest['SupportingTexts']['CFRError']
+ render 'ds_common/error'
+ end
+ super
+ end
+end
diff --git a/app/controllers/e_sign/eeg035_scheduled_sending_controller.rb b/app/controllers/e_sign/eeg035_scheduled_sending_controller.rb
new file mode 100644
index 0000000..ee6a766
--- /dev/null
+++ b/app/controllers/e_sign/eeg035_scheduled_sending_controller.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class ESign::Eeg035ScheduledSendingController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 35, 'eSignature') }
+
+ def create
+ envelope_args = {
+ signer_email: param_gsub(params['signer_email']),
+ signer_name: param_gsub(params['signer_name']),
+ resume_date: param_gsub(params['resume_date']),
+ 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
+ }
+ results = ESign::Eg035ScheduledSendingService.new(args).worker
+ session[:envelope_id] = results['envelope_id']
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results['envelope_id'])
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+end
diff --git a/app/controllers/e_sign/eeg036_delayed_routing_controller.rb b/app/controllers/e_sign/eeg036_delayed_routing_controller.rb
new file mode 100644
index 0000000..e863437
--- /dev/null
+++ b/app/controllers/e_sign/eeg036_delayed_routing_controller.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+class ESign::Eeg036DelayedRoutingController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 36, 'eSignature') }
+
+ def create
+ envelope_args = {
+ signer1_email: param_gsub(params['signer1Email']),
+ signer1_name: param_gsub(params['signer1Name']),
+ signer2_email: param_gsub(params['signer2Email']),
+ signer2_name: param_gsub(params['signer2Name']),
+ delay: param_gsub(params['delay']),
+ 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
+ }
+ results = ESign::Eg036DelayedRoutingService.new(args).worker
+ session[:envelope_id] = results['envelope_id']
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results['envelope_id'])
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+
+ def get
+ enableCFR = ESign::GetDataService.new(session[:ds_access_token], session[:ds_base_path]).cfr?(session[:ds_account_id])
+ if enableCFR == 'enabled'
+ session[:status_cfr] = 'enabled'
+ @title = 'Not CFR Part 11 compatible'
+ @error_information = @manifest['SupportingTexts']['CFRError']
+ render 'ds_common/error'
+ end
+ super
+ end
+end
diff --git a/app/controllers/e_sign/eeg037_sms_delivery_controller.rb b/app/controllers/e_sign/eeg037_sms_delivery_controller.rb
new file mode 100644
index 0000000..dc82fa9
--- /dev/null
+++ b/app/controllers/e_sign/eeg037_sms_delivery_controller.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+class ESign::Eeg037SmsDeliveryController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 37, 'eSignature') }
+
+ def create
+ envelope_args = {
+ delivery_method: param_gsub(params['delivery_method']),
+ signer_name: param_gsub(params['signer_name']),
+ cc_name: param_gsub(params['cc_name']),
+ cc_phone_number: param_gsub(params['cc_phone_number']),
+ cc_country_code: param_gsub(params['cc_country_code']),
+ phone_number: param_gsub(params['phone_number']),
+ country_code: param_gsub(params['country_code']),
+ 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
+ }
+
+ results = ESign::Eg037SmsDeliveryService.new(args).worker
+ session[:envelope_id] = results['envelope_id']
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results['envelope_id'])
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+
+ def get
+ enableCFR = ESign::GetDataService.new(session[:ds_access_token], session[:ds_base_path]).cfr?(session[:ds_account_id])
+ if enableCFR == 'enabled'
+ session[:status_cfr] = 'enabled'
+ @title = 'Not CFR Part 11 compatible'
+ @error_information = @manifest['SupportingTexts']['CFRError']
+ render 'ds_common/error'
+ end
+ super
+ end
+end
diff --git a/app/controllers/e_sign/eeg038_responsive_signing_controller.rb b/app/controllers/e_sign/eeg038_responsive_signing_controller.rb
new file mode 100644
index 0000000..cd05084
--- /dev/null
+++ b/app/controllers/e_sign/eeg038_responsive_signing_controller.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class ESign::Eeg038ResponsiveSigningController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 38, 'eSignature') }
+
+ def create
+ args = {
+ account_id: session[:ds_account_id],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token],
+ signer_email: param_gsub(params[:signerEmail]),
+ signer_name: param_gsub(params[:signerName]),
+ cc_email: param_gsub(params[:ccEmail]),
+ cc_name: param_gsub(params[:ccName]),
+ ds_ping_url: Rails.application.config.app_url,
+ signer_client_id: 1000,
+ doc_file: 'data/order_form.html'
+ }
+
+ redirect_url = ESign::Eg038ResponsiveSigningService.new(args).worker
+ redirect_to redirect_url
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+end
diff --git a/app/controllers/e_sign/eeg039_signing_in_person_controller.rb b/app/controllers/e_sign/eeg039_signing_in_person_controller.rb
new file mode 100644
index 0000000..d6e2222
--- /dev/null
+++ b/app/controllers/e_sign/eeg039_signing_in_person_controller.rb
@@ -0,0 +1,49 @@
+# frozen_string_literal: true
+
+class ESign::Eeg039SigningInPersonController < EgController
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 39, 'eSignature') }
+
+ def create
+ minimum_buffer_min = 10
+ token_ok = check_token(minimum_buffer_min)
+ unless token_ok
+ flash[:messages] = 'Sorry, you need to re-authenticate.'
+ # We could store the parameters of the requested operation
+ # so it could be restarted automatically.
+ # But since it should be rare to have a token issue here,
+ # we'll make the user re-enter the form data after
+ # authentication.
+ return redirect_to '/ds/mustAuthenticate'
+ end
+
+ access_token = session[:ds_access_token]
+ base_path = session[:ds_base_path]
+ email = ESign::GetDataService.new(access_token, base_path).get_current_user_email
+ name = ESign::GetDataService.new(access_token, base_path).get_current_user_name
+
+ args = {
+ account_id: session[:ds_account_id],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token],
+ host_email: param_gsub(email),
+ host_name: param_gsub(name),
+ signer_name: param_gsub(params[:signer_name]),
+ ds_ping_url: Rails.application.config.app_url,
+ pdf_filename: 'data/World_Wide_Corp_lorem.pdf'
+ }
+
+ redirect_url = ESign::Eg039SigningInPersonService.new(args).worker
+ redirect_to redirect_url
+ end
+
+ def get
+ enableCFR = ESign::GetDataService.new(session[:ds_access_token], session[:ds_base_path]).cfr?(session[:ds_account_id])
+ if enableCFR == 'enabled'
+ session[:status_cfr] = 'enabled'
+ @title = 'Not CFR Part 11 compatible'
+ @error_information = @manifest['SupportingTexts']['CFRError']
+ render 'ds_common/error'
+ end
+ super
+ end
+end
diff --git a/app/controllers/e_sign/eeg040_set_document_visibility_controller.rb b/app/controllers/e_sign/eeg040_set_document_visibility_controller.rb
new file mode 100644
index 0000000..0e75106
--- /dev/null
+++ b/app/controllers/e_sign/eeg040_set_document_visibility_controller.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+class ESign::Eeg040SetDocumentVisibilityController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 40, 'eSignature') }
+
+ def create
+ envelope_args = {
+ signer1_email: param_gsub(params['signer1Email']),
+ signer1_name: param_gsub(params['signer1Name']),
+ signer2_email: param_gsub(params['signer2Email']),
+ signer2_name: param_gsub(params['signer2Name']),
+ cc_email: param_gsub(params['ccEmail']),
+ cc_name: param_gsub(params['ccName']),
+ status: 'sent',
+ doc_docx: File.join('data', Rails.application.config.doc_docx),
+ doc_pdf: File.join('data', Rails.application.config.doc_pdf)
+ }
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ envelope_args: envelope_args
+ }
+ results = ESign::Eg040SetDocumentVisibilityService.new(args).worker
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results['envelope_id'])
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ error = JSON.parse e.response_body
+
+ if error['errorCode'] == 'ACCOUNT_LACKS_PERMISSIONS'
+ @error_information = @example['CustomErrorTexts'][0]['ErrorMessage']
+
+ @error_code = error['errorCode']
+ @error_message = error['error_description'] || error['message']
+
+ return render 'ds_common/error'
+ end
+
+ handle_error(e)
+ end
+
+ def get
+ enableCFR = ESign::GetDataService.new(session[:ds_access_token], session[:ds_base_path]).cfr?(session[:ds_account_id])
+ if enableCFR == 'enabled'
+ session[:status_cfr] = 'enabled'
+ @title = 'Not CFR Part 11 compatible'
+ @error_information = @manifest['SupportingTexts']['CFRError']
+ render 'ds_common/error'
+ end
+ super
+ end
+end
diff --git a/app/controllers/e_sign/eeg041_cfr_embedded_signing_controller.rb b/app/controllers/e_sign/eeg041_cfr_embedded_signing_controller.rb
new file mode 100644
index 0000000..99357c6
--- /dev/null
+++ b/app/controllers/e_sign/eeg041_cfr_embedded_signing_controller.rb
@@ -0,0 +1,52 @@
+# frozen_string_literal: true
+
+require_relative '../../services/utils'
+
+class ESign::Eeg041CfrEmbeddedSigningController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 41, 'eSignature') }
+
+ def create
+ pdf_file_path = 'data/World_Wide_Corp_lorem.pdf'
+
+ pdf_file_path = '../data/World_Wide_Corp_lorem.pdf' unless File.exist?(pdf_file_path)
+
+ envelope_args = {
+ signer_email: param_gsub(params['signerEmail']),
+ signer_name: param_gsub(params['signerName']),
+ country_code: param_gsub(params['countryCode']),
+ phone_number: param_gsub(params['phoneNumber']),
+ signer_client_id: 1000,
+ ds_return_url: "#{Rails.application.config.app_url}/ds_common-return",
+ ds_ping_url: "#{Rails.application.config.app_url}/",
+ pdf_filename: pdf_file_path
+ }
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ envelope_args: envelope_args
+ }
+ redirect_url = ESign::Eg041CfrEmbeddedSigningService.new(args).worker
+
+ if redirect_url.to_s == 'invalid_workflow_id'
+ @error_code = 'IDENTITY_WORKFLOW_INVALID_ID'
+ @error_message = 'The identity workflow ID specified is not valid.'
+ render 'ds_common/error'
+ else
+ redirect_to redirect_url
+ end
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+
+ def get
+ enableCFR = ESign::GetDataService.new(session[:ds_access_token], session[:ds_base_path]).cfr?(session[:ds_account_id])
+ if enableCFR != 'enabled'
+ @title = 'Must use a CFR Part 11 enabled account'
+ @error_information = 'This example requires a CFR Part 11 account. Please return to the homepage to run one of the examples that is compatible or authenticate with a different account.'
+ render 'ds_common/error'
+ end
+ super
+ end
+end
diff --git a/app/controllers/e_sign/eeg042_document_generation_controller.rb b/app/controllers/e_sign/eeg042_document_generation_controller.rb
new file mode 100644
index 0000000..3a12f3f
--- /dev/null
+++ b/app/controllers/e_sign/eeg042_document_generation_controller.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+require_relative '../../services/utils'
+
+class ESign::Eeg042DocumentGenerationController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 42, 'eSignature') }
+
+ def create
+ envelope_args = {
+ candidate_email: param_gsub(params['candidate_email']),
+ candidate_name: param_gsub(params['candidate_name']),
+ manager_name: param_gsub(params['manager_name']),
+ job_title: param_gsub(params['job_title']),
+ salary: param_gsub(params['salary']),
+ rsus: param_gsub(params['rsus']),
+ start_date: param_gsub(params['start_date']),
+ doc_file: File.join('data', Rails.application.config.offer_letter_dynamic_table)
+ }
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ envelope_args: envelope_args
+ }
+ results = ESign::Eg042DocumentGenerationService.new(args).worker
+ session[:envelope_id] = results['envelope_id']
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results['envelope_id'])
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+end
diff --git a/app/controllers/e_sign/eeg043_shared_access_controller.rb b/app/controllers/e_sign/eeg043_shared_access_controller.rb
new file mode 100644
index 0000000..35ce36b
--- /dev/null
+++ b/app/controllers/e_sign/eeg043_shared_access_controller.rb
@@ -0,0 +1,107 @@
+# frozen_string_literal: true
+
+require_relative '../../services/utils'
+
+class ESign::Eeg043SharedAccessController < EgController
+ before_action :authenticate_agent, only: [:list_envelopes]
+ before_action -> { check_auth('eSignature') }, except: %i[reauthenticate list_envelopes]
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 43, 'eSignature') }
+
+ def create_agent
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ email: params['email'],
+ user_name: param_gsub(params['user_name']),
+ activation: param_gsub(params['activation'])
+ }
+ results = ESign::Eg043SharedAccessService.new(args).create_agent
+ session[:agent_user_id] = results.user_id
+ @title = @example['ExampleName']
+ @message = @example['ResultsPageText']
+ @json = results.to_json.to_json
+ @redirect_url = '/eeg043auth'
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+
+ def create_authorization
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ agent_user_id: session['agent_user_id']
+ }
+ args[:user_id] = Utils::DocuSignUtils.new.get_user_id args
+ session[:principal_user_id] = args[:user_id]
+
+ ESign::Eg043SharedAccessService.new(args).create_authorization
+
+ additional_page_data = @example['AdditionalPage'].find { |p| p['Name'] == 'authenticate_as_agent' }
+ @title = 'Authenticate as the agent'
+ @message = additional_page_data['ResultsPageText']
+ @redirect_url = '/eeg043reauthenticate'
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ error = JSON.parse e.response_body
+ if error['errorCode'] == 'USER_NOT_FOUND'
+ additional_page_data = @example['AdditionalPage'].find { |p| p['Name'] == 'user_not_found' }
+ @title = 'Authenticate as the agent'
+ @message = additional_page_data['ResultsPageText']
+ @redirect_url = '/eeg043auth'
+ return render 'ds_common/example_done'
+ end
+ handle_error(e)
+ end
+
+ def reauthenticate
+ logout
+ redirect_to '/eeg043envelopes'
+ end
+
+ def list_envelopes
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ user_id: session[:principal_user_id]
+ }
+ results = ESign::Eg043SharedAccessService.new(args).get_envelopes
+
+ if results.result_set_size.to_i.positive?
+ additional_page_data = @example['AdditionalPage'].find { |p| p['Name'] == 'list_status_successful' }
+ @title = "Principal's envelopes visible in the agent's Shared Access UI"
+ @json = results.to_json.to_json
+ else
+ additional_page_data = @example['AdditionalPage'].find { |p| p['Name'] == 'list_status_unsuccessful' }
+ @title = "No envelopes in the principal user's account"
+ end
+
+ @message = additional_page_data['ResultsPageText']
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+
+ private
+
+ def logout
+ session.delete :ds_access_token
+ session.delete :ds_account_id
+ session.delete :ds_expires_at
+ session.delete 'omniauth.state'
+ session.delete 'omniauth.params'
+ session.delete 'omniauth.origin'
+ end
+
+ def authenticate_agent
+ minimum_buffer_min = 10
+ token_ok = check_token(minimum_buffer_min)
+ return if token_ok
+
+ session[:eg] = 'eeg043envelopes'
+ redirect_to '/ds/mustAuthenticate'
+ end
+end
diff --git a/app/controllers/e_sign/eeg044_focused_view_controller.rb b/app/controllers/e_sign/eeg044_focused_view_controller.rb
new file mode 100644
index 0000000..a4f391c
--- /dev/null
+++ b/app/controllers/e_sign/eeg044_focused_view_controller.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class ESign::Eeg044FocusedViewController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 44) }
+
+ def create
+ pdf_file_path = 'data/World_Wide_Corp_lorem.pdf'
+
+ pdf_file_path = '../data/World_Wide_Corp_lorem.pdf' unless File.exist?(pdf_file_path)
+
+ args = {
+ account_id: session[:ds_account_id],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token],
+ signer_email: param_gsub(params[:signerEmail]),
+ signer_name: param_gsub(params[:signerName]),
+ ds_ping_url: Rails.application.config.app_url,
+ signer_client_id: 1000,
+ pdf_filename: pdf_file_path
+ }
+
+ @integration_key = Rails.application.config.integration_key
+ @url = ESign::Eg044FocusedViewService.new(args).worker
+ render 'e_sign/eeg044_focused_view/embed'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+end
diff --git a/app/controllers/e_sign/eeg045_delete_restore_envelope_controller.rb b/app/controllers/e_sign/eeg045_delete_restore_envelope_controller.rb
new file mode 100644
index 0000000..dfb3dd7
--- /dev/null
+++ b/app/controllers/e_sign/eeg045_delete_restore_envelope_controller.rb
@@ -0,0 +1,82 @@
+# frozen_string_literal: true
+
+require_relative '../../services/utils'
+
+class ESign::Eeg045DeleteRestoreEnvelopeController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 45, 'eSignature') }
+
+ DELETE_FOLDER_ID = 'recyclebin'
+
+ def delete_envelope
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ envelope_id: param_gsub(params['envelope_id']),
+ delete_folder_id: DELETE_FOLDER_ID
+ }
+
+ delete_restore_envelope_service = ESign::Eg045DeleteRestoreEnvelopeService.new
+
+ delete_restore_envelope_service.delete_envelope args
+
+ session[:envelope_id] = args[:envelope_id]
+ additional_page_data = @example['AdditionalPage'].find { |p| p['Name'] == 'envelope_is_deleted' }
+ @title = @example['ExampleName']
+ @message = format_string(additional_page_data['ResultsPageText'], args[:envelope_id])
+ @redirect_url = "/#{session[:eg]}restore"
+
+ render 'ds_common/example_done'
+ end
+
+ def restore_envelope
+ folder_name = param_gsub(params['folder_name'])
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ envelope_id: param_gsub(session[:envelope_id]),
+ from_folder_id: DELETE_FOLDER_ID
+ }
+
+ delete_restore_envelope_service = ESign::Eg045DeleteRestoreEnvelopeService.new
+
+ folders = delete_restore_envelope_service.get_folders args
+ args[:folder_id] = Utils::DocuSignUtils.new.get_folder_id_by_name(folders.folders, folder_name)
+
+ if args[:folder_id].nil? || args[:folder_id].empty?
+ additional_page_data = @example['AdditionalPage'].find { |p| p['Name'] == 'folder_does_not_exist' }
+ @title = @example['ExampleName']
+ @message = format_string(additional_page_data['ResultsPageText'], folder_name)
+ @redirect_url = "/#{session[:eg]}restore"
+
+ return render 'ds_common/example_done'
+ end
+
+ delete_restore_envelope_service.move_envelope_to_folder args
+
+ session[:envelope_id] = args[:envelope_id]
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], session[:envelope_id], args[:folder_id], folder_name)
+ render 'ds_common/example_done'
+ end
+
+ def get_delete_envelope
+ get
+ @envelope_id = session[:envelope_id]
+ @submit_button_text = @manifest['SupportingTexts']['HelpingTexts']['SubmitButtonDeleteText']
+
+ render 'e_sign/eeg045_delete_restore_envelope/delete'
+ end
+
+ def get_restore_envelope
+ return redirect_to "/#{session[:eg]}" if session[:envelope_id].nil?
+
+ get
+ @envelope_id = session[:envelope_id]
+ @submit_button_text = @manifest['SupportingTexts']['HelpingTexts']['SubmitButtonRestoreText']
+
+ render 'e_sign/eeg045_delete_restore_envelope/restore'
+ end
+end
diff --git a/app/controllers/e_sign/eeg046_multiple_delivery_controller.rb b/app/controllers/e_sign/eeg046_multiple_delivery_controller.rb
new file mode 100644
index 0000000..6d391b8
--- /dev/null
+++ b/app/controllers/e_sign/eeg046_multiple_delivery_controller.rb
@@ -0,0 +1,55 @@
+# frozen_string_literal: true
+
+class ESign::Eeg046MultipleDeliveryController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 46, 'eSignature') }
+
+ def create
+ envelope_args = {
+ delivery_method: param_gsub(params['delivery_method']),
+ signer_name: param_gsub(params['signer_name']),
+ signer_email: param_gsub(params['signer_email']),
+ cc_name: param_gsub(params['cc_name']),
+ cc_email: param_gsub(params['cc_email']),
+ cc_phone_number: param_gsub(params['cc_phone_number']),
+ cc_country_code: param_gsub(params['cc_country_code']),
+ phone_number: param_gsub(params['phone_number']),
+ country_code: param_gsub(params['country_code']),
+ 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
+ }
+
+ results = ESign::Eg046MultipleDeliveryService.new(args).worker
+ session[:envelope_id] = results['envelope_id']
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results['envelope_id'])
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ error = JSON.parse e.response_body
+ error_message = error['error_description'] || error['message'] || error['error']
+
+ if error_message.include?('ACCOUNT_LACKS_PERMISSIONS')
+ @error_code = 'ACCOUNT_LACKS_PERMISSIONS'
+ @error_message = @example['CustomErrorTexts'][0]['ErrorMessage']
+ return render 'ds_common/error'
+ end
+
+ handle_error(e)
+ end
+
+ def get
+ enableCFR = ESign::GetDataService.new(session[:ds_access_token], session[:ds_base_path]).cfr?(session[:ds_account_id])
+ if enableCFR == 'enabled'
+ session[:status_cfr] = 'enabled'
+ @title = 'Not CFR Part 11 compatible'
+ @error_information = @manifest['SupportingTexts']['CFRError']
+ render 'ds_common/error'
+ end
+ super
+ end
+end
diff --git a/app/controllers/e_sign/eg001_embedded_signing_controller.rb b/app/controllers/e_sign/eg001_embedded_signing_controller.rb
deleted file mode 100644
index 3b00793..0000000
--- a/app/controllers/e_sign/eg001_embedded_signing_controller.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg001EmbeddedSigningController < EgController
- def create
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
- unless token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation
- # so it could be restarted automatically.
- # But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after
- # authentication.
- redirect_to '/ds/mustAuthenticate'
- end
- redirect_url = ESign::Eg001EmbeddedSigningService.new(session, request).call
- redirect_to redirect_url
- end
-
- def get
- session[:been_here] = true
- super
- end
-end
diff --git a/app/controllers/e_sign/eg002_signing_via_email_controller.rb b/app/controllers/e_sign/eg002_signing_via_email_controller.rb
deleted file mode 100644
index 09d215f..0000000
--- a/app/controllers/e_sign/eg002_signing_via_email_controller.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg002SigningViaEmailController < EgController
- def create
- minimum_buffer_min = 3
- if check_token(minimum_buffer_min)
- begin
- results = ESign::Eg002SigningViaEmailService.new(session, request, 'sent').call
- session[:envelope_id] = results['envelope_id']
- @title = 'Envelope sent'
- @h1 = 'Envelope sent'
- @message = "The envelope has been created and sent!
Envelope ID #{results['envelope_id']}."
- render 'ds_common/example_done'
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- else
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation
- # so it could be restarted automatically.
- # But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after
- # authentication.
- redirect_to '/'
- end
- end
-end
diff --git a/app/controllers/e_sign/eg003_list_envelopes_controller.rb b/app/controllers/e_sign/eg003_list_envelopes_controller.rb
deleted file mode 100644
index 235c808..0000000
--- a/app/controllers/e_sign/eg003_list_envelopes_controller.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg003ListEnvelopesController < EgController
- def create
- minimum_buffer_min = 3
- token_ok = check_token(minimum_buffer_min)
- if token_ok
- results = ESign::Eg003ListEnvelopesService.new(session).call
- @h1 = 'List envelopes results'
- @message = 'Results from the Envelopes::listStatusChanges method:'
- @json = results.to_json.to_json
- render 'ds_common/example_done'
- else
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted automatically.
- # But since it should be rare to have a token issue here, we'll make the user re-enter the form data after authentication.
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/e_sign/eg004_envelope_info_controller.rb b/app/controllers/e_sign/eg004_envelope_info_controller.rb
deleted file mode 100644
index f598872..0000000
--- a/app/controllers/e_sign/eg004_envelope_info_controller.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg004EnvelopeInfoController < EgController
- def create
- minimum_buffer_min = 3
- envelope_id = session[:envelope_id]
- token_ok = check_token(minimum_buffer_min)
-
- if token_ok && envelope_id
- begin
- results = ESign::Eg004EnvelopeInfoService.new(session, envelope_id).call
- # results is an object that implements ArrayAccess. Convert to a regular array:
- @title = 'Envelope status results'
- @h1 = 'Envelope status results'
- @message = 'Results from the Envelopes::get method:'
- @json = results.to_json.to_json
- render 'ds_common/example_done'
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- elsif !token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation
- # so it could be restarted automatically.
- # But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after
- # authentication.
- redirect_to '/ds/mustAuthenticate'
- elsif !envelope_id
- @title = 'Envelope information'
- @envelope_ok = false
- end
- end
-end
diff --git a/app/controllers/e_sign/eg005_envelope_recipients_controller.rb b/app/controllers/e_sign/eg005_envelope_recipients_controller.rb
deleted file mode 100644
index 2737183..0000000
--- a/app/controllers/e_sign/eg005_envelope_recipients_controller.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg005EnvelopeRecipientsController < EgController
- include ApiCreator
- skip_before_action :set_meta
-
- def create
- minimum_buffer_min = 3
- envelope_id = session[:envelope_id] || nil
- token_ok = check_token(minimum_buffer_min)
-
- if token_ok && envelope_id
- # 2. Call the worker method
- args = {
- account_id: session['ds_account_id'],
- base_path: session['ds_base_path'],
- access_token: session['ds_access_token'],
- envelope_id: envelope_id
- }
-
- begin
- results = worker args
- @title = 'Envelope recipients results'
- @h1 = 'List the envelope\'s recipients and their status'
- @message = 'Results from the EnvelopesRecipients::list method:'
- @json = results.to_json.to_json
- render 'ds_common/example_done'
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- elsif !token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation
- # so it could be restarted automatically.
- # But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after
- # authentication.
- redirect_to '/ds/mustAuthenticate'
- elsif !envelope_id
- @title = 'Envelope recipient information'
- @envelope_ok = false
- end
- end
-
- # ***DS.snippet.0.start
- def worker(args)
- # Step 1. List envelope recipients
- # Exceptions will be caught by the calling function
- envelope_api = create_envelope_api(args)
- results = envelope_api.list_recipients args[:account_id], args[:envelope_id]
- results
- end
- # ***DS.snippet.0.end
-end
diff --git a/app/controllers/e_sign/eg006_envelope_docs_controller.rb b/app/controllers/e_sign/eg006_envelope_docs_controller.rb
deleted file mode 100644
index c2869f1..0000000
--- a/app/controllers/e_sign/eg006_envelope_docs_controller.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg006EnvelopeDocsController < EgController
- def create
- minimum_buffer_min = 3
- envelope_id = session[:envelope_id]
- token_ok = check_token(minimum_buffer_min)
-
- if token_ok && envelope_id
- begin
- results = ESign::Eg006EnvelopeDocsService.new(request, session, envelope_id).call
-
- @title = 'Envelope documents list'
- @h1 = 'List the envelope\'s documents'
- @message = 'Results from the EnvelopeDocuments::list method:'
- @json = results.to_json.to_json
- render 'ds_common/example_done'
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- elsif !token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation
- # so it could be restarted automatically.
- # But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after
- # authentication.
- redirect_to '/ds/mustAuthenticate'
- elsif !envelope_id
- @title = 'Envelope recipient information'
- @envelope_ok = false
- end
- end
-end
diff --git a/app/controllers/e_sign/eg007_envelope_get_doc_controller.rb b/app/controllers/e_sign/eg007_envelope_get_doc_controller.rb
deleted file mode 100644
index d66b235..0000000
--- a/app/controllers/e_sign/eg007_envelope_get_doc_controller.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg007EnvelopeGetDocController < EgController
- def create
- minimum_buffer_min = 3
- envelope_id = session[:envelope_id]
- envelope_documents = session[:envelope_documents]
- token_ok = check_token(minimum_buffer_min)
- if token_ok && envelope_id && envelope_documents
- begin
- results = ESign::Eg007EnvelopeGetDocService.new(request, session, envelope_id, envelope_documents).call
- send_data results['data'], filename: results['doc_name'],
- content_type: results['mime_type'],
- disposition: "attachment; filename=\"#{results['doc_name']}\""
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- elsif !token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation
- # so it could be restarted automatically.
- # But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after
- # authentication.
- redirect_to '/ds/mustAuthenticate'
- elsif !envelope_id || !envelope_documents
- @title = 'Download an envelope\'s document'
- @envelope_ok = false
- @documents_ok = false
- end
- end
-end
diff --git a/app/controllers/e_sign/eg008_create_template_controller.rb b/app/controllers/e_sign/eg008_create_template_controller.rb
deleted file mode 100644
index e2962b9..0000000
--- a/app/controllers/e_sign/eg008_create_template_controller.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg008CreateTemplateController < EgController
- def create
- minimum_buffer_min = 3
- token_ok = check_token(minimum_buffer_min)
-
- if token_ok
- begin
- results = ESign::Eg008CreateTemplateService.new(session).call
- msg = if results.fetch(:created_new_template)
- 'The template has been created!'
- else
- 'Done. The template already existed in your account.'
- end
- @title = 'Template results'
- @h1 = 'Template results'
- @message = "#{msg}
Template name: #{results[:template_name]},
- ID #{results[:template_id]}."
- render 'ds_common/example_done'
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- end
- end
-end
diff --git a/app/controllers/e_sign/eg009_use_template_controller.rb b/app/controllers/e_sign/eg009_use_template_controller.rb
deleted file mode 100644
index 89be3c5..0000000
--- a/app/controllers/e_sign/eg009_use_template_controller.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg009UseTemplateController < EgController
- def create
- minimum_buffer_min = 3
- template_id = session[:template_id]
- token_ok = check_token(minimum_buffer_min)
-
- if token_ok && template_id
- begin
- results = ESign::Eg009UseTemplateService.new(request, session, template_id).call
- # results is an object that implements ArrayAccess. Convert to a regular array:
- @title = 'Envelope sent'
- @h1 = 'Envelope sent'
- @message = "The envelope has been created and sent!
Envelope ID #{results[:envelope_id]}."
- render 'ds_common/example_done'
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- elsif !token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation
- # so it could be restarted automatically.
- # But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after
- # authentication.
- redirect_to '/ds/mustAuthenticate'
- elsif !template_id
- @title = 'Use a template to send an envelope'
- @template_ok = false
- end
- end
-end
diff --git a/app/controllers/e_sign/eg010_send_binary_docs_controller.rb b/app/controllers/e_sign/eg010_send_binary_docs_controller.rb
deleted file mode 100644
index e9a70bf..0000000
--- a/app/controllers/e_sign/eg010_send_binary_docs_controller.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-class ESign::Eg010SendBinaryDocsController < EgController
- def create
- minimum_buffer_min = 3
- if check_token minimum_buffer_min
- begin
- results = ESign::Eg010SendBinaryDocsService.new(request, session).call
- @title = 'Envelope sent'
- @h1 = 'Envelope sent'
- @message = "The envelope has been created and sent!
Envelope ID #{results['envelope_id']}."
- render 'ds_common/example_done'
- rescue Net::HTTPError => e
- if !e.response.nil?
- json_response = JSON.parse e.response
- @error_code = json_response['errorCode']
- @error_message = json_response['message']
- else
- @error_code = 'API request problem'
- @error_message = e.to_s
- end
- end
- else
- flash[:message] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation
- # so it could be restarted automatically.
- # But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after
- # authentication.
- session['eg'] = eg_name
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/e_sign/eg011_embedded_sending_controller.rb b/app/controllers/e_sign/eg011_embedded_sending_controller.rb
deleted file mode 100644
index 2dce77c..0000000
--- a/app/controllers/e_sign/eg011_embedded_sending_controller.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg011EmbeddedSendingController < EgController
- def create
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
-
- if token_ok
- begin
- results = ESign::Eg011EmbeddedSendingService.new(request, session).call
- redirect_to results['redirect_url']
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- elsif !token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation
- # so it could be restarted automatically.
- # But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after
- # authentication.
- redirect_to '/ds/mustAuthenticate'
- elsif !template_id
- @title = 'Use a template to send an envelope'
- @template_ok = false
- end
- end
-end
diff --git a/app/controllers/e_sign/eg012_embedded_console_controller.rb b/app/controllers/e_sign/eg012_embedded_console_controller.rb
deleted file mode 100644
index cc9ac72..0000000
--- a/app/controllers/e_sign/eg012_embedded_console_controller.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg012EmbeddedConsoleController < EgController
- def create
- minimum_buffer_min = 3
- envelope_id = session[:envelope_id]
- token_ok = check_token(minimum_buffer_min)
-
- if token_ok
- begin
- results = ESign::Eg012EmbeddedConsoleService.new(session, envelope_id, request).call
- redirect_to results['redirect_url']
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- else
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation
- # so it could be restarted automatically.
- # But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after
- # authentication.
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/e_sign/eg013_add_doc_to_template_controller.rb b/app/controllers/e_sign/eg013_add_doc_to_template_controller.rb
deleted file mode 100644
index 5816582..0000000
--- a/app/controllers/e_sign/eg013_add_doc_to_template_controller.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg013AddDocToTemplateController < EgController
- def create
- minimum_buffer_min = 3
- template_id = session[:template_id]
- token_ok = check_token(minimum_buffer_min)
-
- if token_ok && template_id
- # 2. Call the worker method
- # More data validation would be a good idea here
- # Strip anything other than characters listed
- begin
- results = ESign::Eg013AddDocToTemplateService.new(request, session, template_id).call
- # which need an envelopeId
- # Redirect the user to the embedded signing
- # Don't use an iFrame!
- # State can be stored/recovered using the framework's session or a
- # query parameter on the returnUrl
- redirect_to results[:redirect_url]
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- elsif !token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation
- # so it could be restarted automatically.
- # But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after
- # authentication.
- redirect_to '/ds/mustAuthenticate'
- elsif !template_id
- @title = 'Use embedded signing from template and extra doc',
- @template_ok = false
- end
- end
-end
diff --git a/app/controllers/e_sign/eg014_collect_payment_controller.rb b/app/controllers/e_sign/eg014_collect_payment_controller.rb
deleted file mode 100644
index 154e9f2..0000000
--- a/app/controllers/e_sign/eg014_collect_payment_controller.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg014CollectPaymentController < EgController
- def create
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
-
- if token_ok
- begin
- results = ESign::Eg014CollectPaymentService.new(request, session).call
- @title = 'Envelope sent'
- @h1 = 'Envelope sent'
- @message = "The order form envelope has been created and sent!
- Envelope ID #{results[:envelope_id]}"
- render 'ds_common/example_done'
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- else
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation
- # so it could be restarted automatically.
- # But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after
- # authentication.
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/e_sign/eg015_get_envelope_tab_data_controller.rb b/app/controllers/e_sign/eg015_get_envelope_tab_data_controller.rb
deleted file mode 100644
index 9f6b6e2..0000000
--- a/app/controllers/e_sign/eg015_get_envelope_tab_data_controller.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg015GetEnvelopeTabDataController < EgController
- def create
- minimum_buffer_min = 3
- envelope_id = session[:envelope_id]
- token_ok = check_token(minimum_buffer_min)
- if token_ok
- results = ESign::Eg015GetEnvelopeTabDataService.new(envelope_id, session).call
- @h1 = 'List envelopes results'
- @message = 'Results from the Envelopes::listStatusChanges method:'
- @json = results.to_json.to_json
- render 'ds_common/example_done'
- else
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted
- # automatically. But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after authentication
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/e_sign/eg016_set_envelope_tab_data_controller.rb b/app/controllers/e_sign/eg016_set_envelope_tab_data_controller.rb
deleted file mode 100644
index 20b6533..0000000
--- a/app/controllers/e_sign/eg016_set_envelope_tab_data_controller.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg016SetEnvelopeTabDataController < EgController
- def create
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
- unless token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted
- # automatically. But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after authentication
- redirect_to '/ds/mustAuthenticate'
- end
- redirect_url = ESign::Eg016SetEnvelopeTabDataService.new(request, session).call
- redirect_to redirect_url
- end
-end
diff --git a/app/controllers/e_sign/eg017_set_template_tab_values_controller.rb b/app/controllers/e_sign/eg017_set_template_tab_values_controller.rb
deleted file mode 100644
index 778c38e..0000000
--- a/app/controllers/e_sign/eg017_set_template_tab_values_controller.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg017SetTemplateTabValuesController < EgController
- def create
- minimum_buffer_min = 3
- template_id = session[:template_id]
- token_ok = check_token(minimum_buffer_min)
- if token_ok && template_id
- redirect_url = ESign::Eg017SetTemplateTabValuesService.new(request, session, template_id).call
- redirect_to redirect_url
- elsif !token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted
- # automatically. But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after authentication
- redirect_to '/ds/mustAuthenticate'
- elsif !template_id
- @title = 'Use a template to send an envelope'
- @template_ok = false
- end
- end
-end
diff --git a/app/controllers/e_sign/eg018_get_envelope_custom_field_data_controller.rb b/app/controllers/e_sign/eg018_get_envelope_custom_field_data_controller.rb
deleted file mode 100644
index 0122b70..0000000
--- a/app/controllers/e_sign/eg018_get_envelope_custom_field_data_controller.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg018GetEnvelopeCustomFieldDataController < EgController
- def create
- minimum_buffer_min = 3
- envelope_id = session[:envelope_id]
- token_ok = check_token(minimum_buffer_min)
- if token_ok
- results = ESign::Eg018GetEnvelopeCustomFieldDataService.new(session, envelope_id).call
- @h1 = 'List envelopes results'
- @message = 'Results from the Envelopes::listStatusChanges method:'
- @json = results.to_json.to_json
- render 'ds_common/example_done'
- else
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted
- # automatically. But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after authentication
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/e_sign/eg019_access_code_authentication_controller.rb b/app/controllers/e_sign/eg019_access_code_authentication_controller.rb
deleted file mode 100644
index 88e8114..0000000
--- a/app/controllers/e_sign/eg019_access_code_authentication_controller.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg019AccessCodeAuthenticationController < EgController
- def create
- minimum_buffer_min = 3
- if check_token(minimum_buffer_min)
- begin
- # ***DS.snippet.0.start
- results = ESign::Eg019AccessCodeAuthenticationService.new(request, session).call
- @title = 'Envelope sent'
- @h1 = 'Envelope sent'
- @message = "The envelope has been created and sent!
Envelope ID #{results.envelope_id}."
- render 'ds_common/example_done'
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- else
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted
- # automatically. But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after authentication
- redirect_to '/'
- end
- end
- # ***DS.snippet.0.end
-end
diff --git a/app/controllers/e_sign/eg020_sms_authentication_controller.rb b/app/controllers/e_sign/eg020_sms_authentication_controller.rb
deleted file mode 100644
index 19eaaae..0000000
--- a/app/controllers/e_sign/eg020_sms_authentication_controller.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg020SmsAuthenticationController < EgController
- def create
- minimum_buffer_min = 3
- if check_token(minimum_buffer_min)
- begin
- results = ESign::Eg020SmsAuthenticationService.new(request, session).call
- @title = 'Envelope sent'
- @h1 = 'Envelope sent'
- @message = "The envelope has been created and sent!
Envelope ID #{results.envelope_id}."
- render 'ds_common/example_done'
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- else
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted
- # automatically. But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after authentication
- redirect_to '/'
- end
- end
- # ***DS.snippet.0.end
-end
diff --git a/app/controllers/e_sign/eg021_phone_authentication_controller.rb b/app/controllers/e_sign/eg021_phone_authentication_controller.rb
deleted file mode 100644
index 023a588..0000000
--- a/app/controllers/e_sign/eg021_phone_authentication_controller.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg021PhoneAuthenticationController < EgController
- def create
- minimum_buffer_min = 3
- if check_token(minimum_buffer_min)
- begin
- results = ESign::Eg021PhoneAuthenticationService.new(request, session).call
- session[:envelope_id] = results.envelope_id
- @title = 'Envelope sent'
- @h1 = 'Envelope sent'
- @message = "The envelope has been created and sent!
Envelope ID #{results.envelope_id}."
- render 'ds_common/example_done'
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- else
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted
- # automatically. But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after authentication
- redirect_to '/'
- end
- end
-
- # ***DS.snippet.0.end
-end
diff --git a/app/controllers/e_sign/eg022_kba_authentication_controller.rb b/app/controllers/e_sign/eg022_kba_authentication_controller.rb
deleted file mode 100644
index 5433e48..0000000
--- a/app/controllers/e_sign/eg022_kba_authentication_controller.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg022KbaAuthenticationController < EgController
- def create
- minimum_buffer_min = 3
- if check_token(minimum_buffer_min)
- begin
- results = ESign::Eg022KbaAuthenticationService.new(request, session).call
- @title = 'Envelope sent'
- @h1 = 'Envelope sent'
- @message = "The envelope has been created and sent!
Envelope ID #{results.envelope_id}."
- render 'ds_common/example_done'
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- else
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted
- # automatically. But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after authentication
- redirect_to '/'
- end
- end
-end
diff --git a/app/controllers/e_sign/eg023_idv_authentication_controller.rb b/app/controllers/e_sign/eg023_idv_authentication_controller.rb
deleted file mode 100644
index ec62cde..0000000
--- a/app/controllers/e_sign/eg023_idv_authentication_controller.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg023IdvAuthenticationController < EgController
- def create
- minimum_buffer_min = 3
- if check_token(minimum_buffer_min)
- begin
- results = ESign::Eg023IdvAuthenticationService.new(request, session).call
- if results.to_s == 'needs_idv_activated'
- @title = 'Error'
- @h1 = 'Error'
- @message = 'Please activate IDV on your account to use this example.'
- render 'ds_common/example_done'
-
- else
- @title = 'Envelope sent'
- @h1 = 'Envelope sent'
- @message = "The envelope has been created and sent!
Envelope ID #{results.envelope_id}."
- render 'ds_common/example_done'
- end
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- else
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted
- # automatically. But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after authentication
- redirect_to '/'
- end
- end
-
- # ***DS.snippet.0.end
-end
diff --git a/app/controllers/e_sign/eg024_permission_create_controller.rb b/app/controllers/e_sign/eg024_permission_create_controller.rb
deleted file mode 100644
index f94f1b1..0000000
--- a/app/controllers/e_sign/eg024_permission_create_controller.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg024PermissionCreateController < EgController
- def create
- minimum_buffer_min = 3
- if check_token(minimum_buffer_min)
- begin
- results = ESign::Eg024PermissionCreateService.new(session, request).call
- # Step 4. a) Call the eSignature API
- # b) Display the JSON response
- @title = 'Creating a permission profile'
- @h1 = 'Creating a permission profile'
- @message = "Permission profile was created"
- @json = results.to_json.to_json
- render 'ds_common/example_done'
-
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- else
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted
- # automatically. But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after authentication
- redirect_to '/'
- end
- end
-end
diff --git a/app/controllers/e_sign/eg025_permissions_set_user_group_controller.rb b/app/controllers/e_sign/eg025_permissions_set_user_group_controller.rb
deleted file mode 100644
index 12d3a8f..0000000
--- a/app/controllers/e_sign/eg025_permissions_set_user_group_controller.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg025PermissionsSetUserGroupController < EgController
- include ApiCreator
- before_action :check_auth
-
- def get
- args = {
- account_id: session['ds_account_id'],
- base_path: session['ds_base_path'],
- access_token: session['ds_access_token']
- }
- accounts_api = create_account_api(args)
- permissions = accounts_api.list_permissions(args[:account_id], options = DocuSign_eSign::ListPermissionsOptions.default)
- @permissions_lists = permissions.permission_profiles
- # Get a user group
- group_api = create_group_api(args)
- @group_lists = group_api.list_groups(args[:account_id], options = DocuSign_eSign::ListGroupsOptions.default)
- super
- end
-
- def create
- minimum_buffer_min = 3
- if check_token(minimum_buffer_min)
- begin
- results = ESign::Eg025PermissionsSetUserGroupService.new(session, request).call
- # Step 4. a) Call the eSignature API
- # b) Display the JSON response
- @title = 'Setting a permission profile'
- @h1 = 'Setting a permission profile'
- @json = results.to_json.to_json
- render 'ds_common/example_done'
-
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- else
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted
- # automatically. But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after authentication
- redirect_to '/ds/mustAuthenticate'
- end
- end
-
- def check_auth
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
- unless token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted automatically
- # But since it should be rare to have a token issue here, we'll make the user re-enter the form data after authentication
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/e_sign/eg026_permissions_change_single_setting_controller.rb b/app/controllers/e_sign/eg026_permissions_change_single_setting_controller.rb
deleted file mode 100644
index 90aa89e..0000000
--- a/app/controllers/e_sign/eg026_permissions_change_single_setting_controller.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg026PermissionsChangeSingleSettingController < EgController
- include ApiCreator
- before_action :check_auth
-
- def get
- args = {
- account_id: session['ds_account_id'],
- base_path: session['ds_base_path'],
- access_token: session['ds_access_token']
- }
- accounts_api = create_account_api(args)
- permissions = accounts_api.list_permissions(args[:account_id], options = DocuSign_eSign::ListPermissionsOptions.default)
- @permissions_lists = permissions.permission_profiles
- super
- end
-
- def create
- minimum_buffer_min = 3
- if check_token(minimum_buffer_min)
- begin
- results = ESign::Eg026PermissionsChangeSingleSettingService.new(session, request).call
- # Step 4. a) Call the eSignature API
- # b) Display the JSON response
- @title = 'Updating individual permission settings'
- @h1 = 'Updating individual permission settings'
- @message = "Existing permission profile was changed"
- @json = results.to_json.to_json
- render 'ds_common/example_done'
-
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- else
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted
- # automatically. But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after authentication
- redirect_to '/'
- end
- end
-
- def check_auth
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
- unless token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted automatically
- # But since it should be rare to have a token issue here, we'll make the user re-enter the form data after authentication
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/e_sign/eg027_permissions_delete_controller.rb b/app/controllers/e_sign/eg027_permissions_delete_controller.rb
deleted file mode 100644
index b7ddc0b..0000000
--- a/app/controllers/e_sign/eg027_permissions_delete_controller.rb
+++ /dev/null
@@ -1,55 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg027PermissionsDeleteController < EgController
- include ApiCreator
- before_action :check_auth
- def get
- args = {
- account_id: session['ds_account_id'],
- base_path: session['ds_base_path'],
- access_token: session['ds_access_token']
- }
- accounts_api = create_account_api(args)
- permissions = accounts_api.list_permissions(args[:account_id], options = DocuSign_eSign::ListPermissionsOptions.default)
- @permissions_lists = permissions.permission_profiles
- super
- end
-
- def create
- minimum_buffer_min = 3
- if check_token(minimum_buffer_min)
- begin
- results = ESign::Eg027PermissionsDeleteService.new(session, request).call
- # Step 4. a) Call the eSignature API
- # b) Display the JSON response
- @title = 'Permission profile from an account was deleted'
- @h1 = 'Permission profile from an account was deleted'
- @message = "Permission profile #{request.params[:lists]} was deleted"
- render 'ds_common/example_done'
-
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- else
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted
- # automatically. But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after authentication
- redirect_to '/'
- end
- end
-
- def check_auth
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
- unless token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted automatically
- # But since it should be rare to have a token issue here, we'll make the user re-enter the form data after authentication
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/e_sign/eg028_brands_creating_controller.rb b/app/controllers/e_sign/eg028_brands_creating_controller.rb
deleted file mode 100644
index 5328933..0000000
--- a/app/controllers/e_sign/eg028_brands_creating_controller.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-class ESign::Eg028BrandsCreatingController < EgController
- def create
- minimum_buffer_min = 3
- if check_token(minimum_buffer_min)
- begin
- results = ESign::Eg028BrandsCreatingService.new(session, request).call
- # Step 4. a) Call the eSignature API
- # b) Display the JSON response
- brand_id = results.brands[0].brand_id
- @title = 'Brand creating'
- @h1 = 'Brand creating'
- @message = "The Brand has been created!
Brand ID: #{brand_id}."
- @json = results.to_json.to_json
- render 'ds_common/example_done'
-
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- else
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted
- # automatically. But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after authentication
- redirect_to '/'
- end
- end
-end
diff --git a/app/controllers/e_sign/eg029_brands_apply_to_envelope_controller.rb b/app/controllers/e_sign/eg029_brands_apply_to_envelope_controller.rb
deleted file mode 100644
index 6d38fc6..0000000
--- a/app/controllers/e_sign/eg029_brands_apply_to_envelope_controller.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg029BrandsApplyToEnvelopeController < EgController
- include ApiCreator
- before_action :check_auth
-
- def get
- args = {
- account_id: session['ds_account_id'],
- base_path: session['ds_base_path'],
- access_token: session['ds_access_token']
- }
- accounts_api = create_account_api(args)
- brand_lists = accounts_api.list_brands(args[:account_id], options = DocuSign_eSign::ListBrandsOptions.default)
- @brand_names = brand_lists.brands
- super
- end
-
- def create
- minimum_buffer_min = 3
- if check_token(minimum_buffer_min)
- begin
- results = ESign::Eg029BrandsApplyToEnvelopeService.new(session, request).call
- # Step 4. a) Call the eSignature API
- # b) Display the JSON response
- @title = 'Applying a Brand to an envelope'
- @h1 = 'Applying a Brand to an envelope'
- @message = "The envelope has been created and sent!
Envelope ID #{results.envelope_id}."
- @json = results.to_json.to_json
- render 'ds_common/example_done'
-
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- else
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted
- # automatically. But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after authentication
- redirect_to '/'
- end
- end
-
- def check_auth
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
- unless token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted automatically
- # But since it should be rare to have a token issue here, we'll make the user re-enter the form data after authentication
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/e_sign/eg030_brands_apply_to_template_controller.rb b/app/controllers/e_sign/eg030_brands_apply_to_template_controller.rb
deleted file mode 100644
index 4c3df30..0000000
--- a/app/controllers/e_sign/eg030_brands_apply_to_template_controller.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-# frozen_string_literal: truebrand_lists = accounts_api.list_brands(args[:account_id], options = DocuSign_eSign::ListBrandsOptions.default)
-
-class ESign::Eg030BrandsApplyToTemplateController < EgController
- include ApiCreator
- before_action :check_auth
-
- def get
- args = {
- account_id: session['ds_account_id'],
- base_path: session['ds_base_path'],
- access_token: session['ds_access_token']
- }
- accounts_api = create_account_api(args)
- brand_lists = accounts_api.list_brands(args[:account_id], options = DocuSign_eSign::ListBrandsOptions.default)
- @brand_names = brand_lists.brands
- # get the template lists
- template_api = create_template_api(args)
- template_lists = template_api.list_templates(args[:account_id], options = DocuSign_eSign::ListTemplatesOptions.default)
- @templates = template_lists.envelope_templates
- super
- end
-
- def create
- minimum_buffer_min = 3
- if check_token(minimum_buffer_min)
- begin
- results = ESign::Eg030BrandsApplyToTemplateService.new(session, request).call
- # Step 4. a) Call the eSignature API
- # b) Display the JSON response
- # brand_id = results.brands[0].brand_id
- @title = 'Applying a brand to an envelope using a template'
- @h1 = 'Applying a brand to an envelope using a template'
- @message = "The envelope has been created and sent!
Envelope ID #{results.envelope_id}."
- @json = results.to_json.to_json
- render 'ds_common/example_done'
-
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- else
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted
- # automatically. But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after authentication
- redirect_to '/'
- end
- end
-
- def check_auth
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
- unless token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted automatically
- # But since it should be rare to have a token issue here, we'll make the user re-enter the form data after authentication
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/e_sign/eg031_bulk_sending_envelopes_controller.rb b/app/controllers/e_sign/eg031_bulk_sending_envelopes_controller.rb
deleted file mode 100644
index b9ebf41..0000000
--- a/app/controllers/e_sign/eg031_bulk_sending_envelopes_controller.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg031BulkSendingEnvelopesController < EgController
-
- def create
- minimum_buffer_min = 3
- if check_token(minimum_buffer_min)
- begin
- results = ESign::Eg031BulkSendingEnvelopesService.new(request, session).call
- # Step 4. a) Call the eSignature API
- # b) Display the JSON response
- @title = 'Bulk sent'
- @h1 = 'Bulk send envelope was successfully performed!'
- @message = "Bulk request queued to #{results.queued} user lists."
- @json = results.to_json.to_json
-
- render 'ds_common/example_done'
-
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- else
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted
- # automatically. But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after authentication
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/e_sign/eg032_pauses_signature_workflow_controller.rb b/app/controllers/e_sign/eg032_pauses_signature_workflow_controller.rb
deleted file mode 100644
index 3b7e16f..0000000
--- a/app/controllers/e_sign/eg032_pauses_signature_workflow_controller.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg032PausesSignatureWorkflowController < EgController
- before_action :check_auth
-
- def create
- results = ESign::Eg032PausesSignatureWorkflowService.new(session, request).call
-
- @envelop_id = results.to_hash[:envelopeId].to_s
- session[:envelope_id] = @envelop_id
-
- render 'e_sign/eg032_pauses_signature_workflow/return'
- end
-
- private
-
- def check_auth
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
- unless token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted automatically
- # But since it should be rare to have a token issue here, we'll make the user re-enter the form data after authentication
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/e_sign/eg033_unpauses_signature_workflow_controller.rb b/app/controllers/e_sign/eg033_unpauses_signature_workflow_controller.rb
deleted file mode 100644
index d9497db..0000000
--- a/app/controllers/e_sign/eg033_unpauses_signature_workflow_controller.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg033UnpausesSignatureWorkflowController < EgController
- before_action :check_auth
-
- def update
- results = ESign::Eg033UnpausesSignatureWorkflowService.new(session).call
-
- @envelop_id = results.to_hash[:envelopeId].to_s
- render 'e_sign/eg033_unpauses_signature_workflow/return'
- end
-
- private
-
- def check_auth
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
- unless token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted automatically
- # But since it should be rare to have a token issue here, we'll make the user re-enter the form data after authentication
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/e_sign/eg034_use_conditional_recipients_controller.rb b/app/controllers/e_sign/eg034_use_conditional_recipients_controller.rb
deleted file mode 100644
index 870cea4..0000000
--- a/app/controllers/e_sign/eg034_use_conditional_recipients_controller.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg034UseConditionalRecipientsController < EgController
- before_action :check_auth
-
- def create
- begin
- results = ESign::Eg034UseConditionalRecipientsService.new(session, request).call
- @envelop_id = results.to_hash[:envelopeId].to_s
- render 'e_sign/eg034_use_conditional_recipients/return'
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- if error['errorCode']["WORKFLOW_UPDATE_RECIPIENTROUTING_NOT_ALLOWED"]
- @error_message = "Update to the workflow with recipient routing is not allowed for your account!"
- @error_information = "Please contact with our support team to resolve this issue."
- else
- @error_message = error['message']
- end
- render 'ds_common/error'
- end
- end
-
- private
-
- def check_auth
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
- unless token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted automatically
- # But since it should be rare to have a token issue here, we'll make the user re-enter the form data after authentication
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/e_sign/eg035_sms_delivery_controller.rb b/app/controllers/e_sign/eg035_sms_delivery_controller.rb
deleted file mode 100644
index 957e5e8..0000000
--- a/app/controllers/e_sign/eg035_sms_delivery_controller.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-# frozen_string_literal: true
-
-class ESign::Eg035SmsDeliveryController < EgController
- def create
- minimum_buffer_min = 3
- if check_token(minimum_buffer_min)
- begin
- results = ESign::Eg035SmsDeliveryService.new(session, request, 'sent').call
- session[:envelope_id] = results['envelope_id']
- @title = 'Envelope sent'
- @h1 = 'Envelope sent'
- @message = "The envelope has been created and sent!
Envelope ID #{results['envelope_id']}."
- render 'ds_common/example_done'
- rescue DocuSign_eSign::ApiError => e
- error = JSON.parse e.response_body
- @error_code = error['errorCode']
- @error_message = error['message']
- render 'ds_common/error'
- end
- else
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation
- # so it could be restarted automatically.
- # But since it should be rare to have a token issue here,
- # we'll make the user re-enter the form data after
- # authentication.
- redirect_to '/'
- end
- end
- end
-
\ No newline at end of file
diff --git a/app/controllers/eeg001_embedded_signing_controller.rb b/app/controllers/eeg001_embedded_signing_controller.rb
new file mode 100644
index 0000000..5b2b093
--- /dev/null
+++ b/app/controllers/eeg001_embedded_signing_controller.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+class Eeg001EmbeddedSigningController < EgController
+ before_action -> { check_auth('eSignature') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 1) }
+
+ def create
+ pdf_file_path = 'data/World_Wide_Corp_lorem.pdf'
+
+ pdf_file_path = '../data/World_Wide_Corp_lorem.pdf' unless File.exist?(pdf_file_path)
+
+ args = {
+ account_id: session[:ds_account_id],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token],
+ signer_email: param_gsub(params[:signerEmail]),
+ signer_name: param_gsub(params[:signerName]),
+ ds_ping_url: Rails.application.config.app_url,
+ signer_client_id: 1000,
+ pdf_filename: pdf_file_path
+ }
+
+ redirect_url = Eg001EmbeddedSigningService.new(args).worker
+ redirect_to redirect_url
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+
+ def get
+ enableCFR = ESign::GetDataService.new(session[:ds_access_token], session[:ds_base_path]).cfr?(session[:ds_account_id])
+ if enableCFR == 'enabled'
+ session[:status_cfr] = 'enabled'
+ @title = 'Not CFR Part 11 compatible'
+ @error_information = @manifest['SupportingTexts']['CFRError']
+ render 'ds_common/error'
+ end
+ session[:been_here] = true
+ super
+ end
+end
diff --git a/app/controllers/eg_controller.rb b/app/controllers/eg_controller.rb
index c3295bc..d53d4ae 100644
--- a/app/controllers/eg_controller.rb
+++ b/app/controllers/eg_controller.rb
@@ -1,68 +1,110 @@
-# frozen_string_literal: true
-
-class EgController < ApplicationController
- skip_before_action :verify_authenticity_token
- before_action :eg_name, :set_eg, :set_meta
-
- def file_name
- "#{controller_path}_service.rb"
- end
-
- def eg_name
- controller_name.to(4)
- end
-
- def set_eg
- session[:eg] = controller_name.to(4)
- end
-
- def get
- @messages = ''
-
- # to have the user authenticate or re-authenticate.
- @token_ok = check_token
- @config = Rails.application.config
- if @token_ok
- # addSpecialAttributes(model)
- @envelope_ok = session[:envelope_id].present?
- @documents_ok = session[:envelope_documents].present?
- @document_options = session.fetch(:envelope_documents, {})['documents']
- @gateway_ok = @config.gateway_account_id.try(:length) > 25
- @template_ok = session[:template_id].present?
- @documentation = "#{@config.documentation}#{eg_name}" #= Config.documentation + EgName
- @show_doc = @config.documentation
- else
- redirect_to '/ds/mustAuthenticate'
- end
- end
-
- def set_meta
-
- @source_file = file_name.to_s
- @source_url = "#{Rails.application.config.github_example_url}#{@source_file}"
- end
-
- private
-
- def check_token(buffer_in_min = 10)
- buffer = buffer_in_min * 60
- expires_at = session[:ds_expires_at]
- remaining_duration = expires_at.nil? ? 0 : expires_at - buffer.seconds.from_now.to_i
- if expires_at.nil?
- Rails.logger.info "==> Token expiration is not available: fetching token"
- elsif remaining_duration.negative?
- Rails.logger.debug "==> Token is about to expire in #{time_in_words(remaining_duration)} at: #{Time.at(expires_at)}: fetching token"
- else
- Rails.logger.debug "==> Token is OK for #{time_in_words(remaining_duration)} at: #{Time.at(expires_at)}"
- end
- remaining_duration > 0
- end
-
- def time_in_words(duration)
- "#{Object.new.extend(ActionView::Helpers::DateHelper).distance_of_time_in_words(duration)}#{duration.negative? ? ' ago' : ''}"
- end
-
- def create_source_path
- # code here
- end
-end
+# frozen_string_literal: true
+
+class EgController < ApplicationController
+ skip_before_action :verify_authenticity_token
+ before_action :eg_name, :set_eg, :set_meta, :ensure_manifest
+
+ def file_name
+ "#{controller_path}_service.rb"
+ end
+
+ def eg_name
+ controller_name.to(4)
+ end
+
+ def set_eg
+ session[:eg] = controller_name.split('_', 2).first
+ end
+
+ def get
+ @messages = ''
+
+ # to have the user authenticate or re-authenticate.
+ @token_ok = check_token
+ @config = Rails.application.config
+ if @token_ok || controller_name.include?('cneg')
+ # addSpecialAttributes(model)
+ @envelope_ok = session[:envelope_id].present?
+ @documents_ok = session[:envelope_documents].present?
+ @document_options = session.fetch(:envelope_documents, {})['documents']
+ @gateway_ok = @config.gateway_account_id.try(:length) > 25
+ @template_ok = session[:template_id].present?
+ @documentation = "#{@config.documentation}#{eg_name}" #= Config.documentation + EgName
+ @show_doc = @config.documentation
+ else
+ redirect_to '/ds/mustAuthenticate'
+ end
+ end
+
+ def set_meta
+ @source_file = file_name.to_s
+ #remove extra character that doesn't exist in service file
+ index = @source_file.index('/')
+ @source_file = index.nil? ? @source_file.sub(/^.*?eg/, 'eg') : @source_file.sub(%r{/.+?eg}, '/eg')
+ @source_url = "#{Rails.application.config.github_example_url}#{@source_file}"
+ end
+
+ def check_token(buffer_in_min = 10)
+ buffer = buffer_in_min * 60
+ expires_at = session[:ds_expires_at]
+ remaining_duration = expires_at.nil? ? 0 : expires_at - buffer.seconds.from_now.to_i
+ if expires_at.nil?
+ Rails.logger.info '==> Token expiration is not available: fetching token'
+ elsif remaining_duration.negative?
+ Rails.logger.debug "==> Token is about to expire in #{time_in_words(remaining_duration)} at: #{Time.at(expires_at)}: fetching token"
+ else
+ Rails.logger.debug "==> Token is OK for #{time_in_words(remaining_duration)} at: #{Time.at(expires_at)}"
+ end
+ remaining_duration.positive?
+ end
+
+ private
+
+ def time_in_words(duration)
+ "#{Object.new.extend(ActionView::Helpers::DateHelper).distance_of_time_in_words(duration)}#{duration.negative? ? ' ago' : ''}"
+ end
+
+ def param_gsub(parameter)
+ parameter.gsub(/([^\w \-@.,])+/, '')
+ end
+
+ def check_auth(api)
+ # if not authorized for same API type example or
+ # if it is an attempt to authorize from home page
+ # then user will be redirected to login page
+ unless (session[:api] == api) || ((api == 'eSignature') && !session[:api])
+ session[:api] = api
+ params[:auth] = 'jwt-auth' if api == 'Monitor'
+
+ return redirect_to '/ds/mustAuthenticate'
+ end
+
+ minimum_buffer_min = 10
+ token_ok = check_token(minimum_buffer_min)
+ return if token_ok
+
+ flash[:messages] = 'Sorry, you need to re-authenticate.'
+ # We could store the parameters of the requested operation so it could be restarted automatically
+ # But since it should be rare to have a token issue here, we'll make the user re-enter the form data after authentication
+ redirect_to '/ds/mustAuthenticate'
+ end
+
+ def handle_error(e)
+ error = JSON.parse e.response_body
+ @error_code = e.code || error['errorCode']
+ @error_message = error['error_description'] || error['message'] || error['error']
+ render 'ds_common/error'
+ end
+
+ def create_source_path
+ # code here
+ end
+
+ def ensure_manifest
+ @manifest = Utils::ManifestUtils.new.get_manifest(Rails.configuration.example_manifest_url)
+ end
+
+ def format_string(string, *args)
+ string.gsub(/\{(\d+)\}/) { args[::Regexp.last_match(1).to_i] }
+ end
+end
diff --git a/app/controllers/monitor_api/meg001_get_monitoring_dataset_controller.rb b/app/controllers/monitor_api/meg001_get_monitoring_dataset_controller.rb
new file mode 100644
index 0000000..e96cad3
--- /dev/null
+++ b/app/controllers/monitor_api/meg001_get_monitoring_dataset_controller.rb
@@ -0,0 +1,25 @@
+class MonitorApi::Meg001GetMonitoringDatasetController < EgController
+ before_action -> { check_auth('Monitor') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 1, 'Monitor') }
+
+ def create
+ args = {
+ access_token: session[:ds_access_token],
+ data_set_name: 'monitor',
+ version: '2.0'
+ }
+
+ results = MonitorApi::Eg001GetMonitoringDatasetService.new(args).worker
+
+ @title = @example['ExampleName']
+
+ if results != 'Monitor not enabled'
+ @message = @example['ResultsPageText']
+ @json = results.to_json.to_json
+ else
+ @message = "You do not have Monitor enabled for your account, follow How to enable Monitor for your account to get it enabled."
+ end
+
+ render 'ds_common/example_done'
+ end
+end
diff --git a/app/controllers/notary/neg004_send_with_third_party_notary_controller.rb b/app/controllers/notary/neg004_send_with_third_party_notary_controller.rb
new file mode 100644
index 0000000..e49259a
--- /dev/null
+++ b/app/controllers/notary/neg004_send_with_third_party_notary_controller.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+require_relative '../../services/utils'
+
+class Notary::Neg004SendWithThirdPartyNotaryController < EgController
+ before_action -> { check_auth('Notary') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 4, 'Notary') }
+
+ def create
+ envelope_args = {
+ signer_email: param_gsub(params['signerEmail']),
+ signer_name: param_gsub(params['signerName']),
+ doc_path: File.join('data', Rails.application.config.doc_docx)
+ }
+ args = {
+ account_id: session['ds_account_id'],
+ base_path: session['ds_base_path'],
+ access_token: session['ds_access_token'],
+ envelope_args: envelope_args
+ }
+ results = Notary::Eg004SendWithThirdPartyNotaryService.new(args).worker
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results['envelope_id'])
+ render 'ds_common/example_done'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+end
diff --git a/app/controllers/room_api/eg001_create_room_with_data_controller.rb b/app/controllers/room_api/eg001_create_room_with_data_controller.rb
deleted file mode 100644
index 91bbaa6..0000000
--- a/app/controllers/room_api/eg001_create_room_with_data_controller.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-class RoomApi::Eg001CreateRoomWithDataController < EgController
- before_action :check_auth
-
- def create
- results = RoomApi::Eg001CreateRoomWithDataService.new(session, request).call
-
- @title = "The room was successfully created"
- @h1 = "The room was successfully created"
- @message = "The room was created! Room ID: #{results.room_id}, Name: #{results.name}"
- @json = results.to_json.to_json
-
- render 'ds_common/example_done'
- end
-
- private
-
- def check_auth
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
- unless token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted automatically
- # But since it should be rare to have a token issue here, we'll make the user re-enter the form data after authentication
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/room_api/eg002_create_room_with_template_controller.rb b/app/controllers/room_api/eg002_create_room_with_template_controller.rb
deleted file mode 100644
index 27bcaac..0000000
--- a/app/controllers/room_api/eg002_create_room_with_template_controller.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-class RoomApi::Eg002CreateRoomWithTemplateController < EgController
- before_action :check_auth
-
- def create
- results = RoomApi::Eg002CreateRoomWithTemplateService.new(session, request).call
-
- @title = "The room was successfully created"
- @h1 = "The room was successfully created"
- @message = "The room was created! Room ID: #{results.room_id}, Name: #{results.name}"
- @json = results.to_json.to_json
-
- render 'ds_common/example_done'
- end
-
- def get
- @templates = RoomApi::GetDataService.new(session).get_templates
- end
-
- private
-
- def check_auth
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
- unless token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted automatically
- # But since it should be rare to have a token issue here, we'll make the user re-enter the form data after authentication
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/room_api/eg003_export_data_from_room_controller.rb b/app/controllers/room_api/eg003_export_data_from_room_controller.rb
deleted file mode 100644
index 29bcbf9..0000000
--- a/app/controllers/room_api/eg003_export_data_from_room_controller.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-class RoomApi::Eg003ExportDataFromRoomController < EgController
- before_action :check_auth
-
- def create
- results = RoomApi::Eg003ExportDataFromRoomService.new(session, request).call
-
- @title = "The room data was successfully exported"
- @h1 = "The room data was successfully exported"
- @message = "Results from the Rooms::GetRoomFieldData method:"
- @json = results.to_json.to_json
-
- render 'ds_common/example_done'
- end
-
- def get
- @rooms = RoomApi::GetDataService.new(session).get_rooms
- end
-
- private
-
- def check_auth
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
- unless token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted automatically
- # But since it should be rare to have a token issue here, we'll make the user re-enter the form data after authentication
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/room_api/eg004_add_forms_to_room_controller.rb b/app/controllers/room_api/eg004_add_forms_to_room_controller.rb
deleted file mode 100644
index bd70bdd..0000000
--- a/app/controllers/room_api/eg004_add_forms_to_room_controller.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-class RoomApi::Eg004AddFormsToRoomController < EgController
- before_action :check_auth
-
- def create
- results = RoomApi::Eg004AddFormsToRoomService.new(session, request).call
-
- @title = "The form was successfully added to a room"
- @h1 = "The form was successfully added to a room"
- @message = "Results from the Rooms: AddFormToRoom method:"
- @json = results.to_json.to_json
-
- render 'ds_common/example_done'
- end
-
- def get
- @rooms = RoomApi::GetDataService.new(session).get_rooms
- @form_libraries = RoomApi::GetDataService.new(session).get_form_libraries
- end
-
- private
-
- def check_auth
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
- unless token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted automatically
- # But since it should be rare to have a token issue here, we'll make the user re-enter the form data after authentication
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/room_api/eg005_get_rooms_with_filters_controller.rb b/app/controllers/room_api/eg005_get_rooms_with_filters_controller.rb
deleted file mode 100644
index 55679e4..0000000
--- a/app/controllers/room_api/eg005_get_rooms_with_filters_controller.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-class RoomApi::Eg005GetRoomsWithFiltersController < EgController
- before_action :check_auth
-
- def create
- results = RoomApi::Eg005GetRoomsWithFiltersService.new(session, request).call
-
- @title = "The rooms with filters were loaded"
- @h1 = "The rooms with filters were loaded"
- @message = "Results from the Rooms: GetRooms method:"
- @json = results.to_json.to_json
-
- render 'ds_common/example_done'
- end
-
- def get
- @rooms = RoomApi::GetDataService.new(session).get_rooms
- end
-
- private
-
- def check_auth
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
- unless token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted automatically
- # But since it should be rare to have a token issue here, we'll make the user re-enter the form data after authentication
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/room_api/eg006_create_an_external_form_fill_session_controller.rb b/app/controllers/room_api/eg006_create_an_external_form_fill_session_controller.rb
deleted file mode 100644
index 3653789..0000000
--- a/app/controllers/room_api/eg006_create_an_external_form_fill_session_controller.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-class RoomApi::Eg006CreateAnExternalFormFillSessionController < EgController
- before_action :check_auth
-
- def create
- results = RoomApi::Eg006CreateAnExternalFormFillSessionService.new(session, request).call
-
- @title = "External form fill session was successfully created"
- @h1 = "External form fill session was successfully created"
- @message = "To fill the form navigate the following URL: Fill the form"
- @json = results.to_json.to_json
-
- render 'ds_common/example_done'
- end
-
- def get_rooms
- @rooms = RoomApi::GetDataService.new(session).get_rooms
- end
-
- def get_forms
- @form_libraries = RoomApi::GetDataService.new(session, params['roomId']).get_forms_from_room
- end
-
- private
-
- def check_auth
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
- unless token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted automatically
- # But since it should be rare to have a token issue here, we'll make the user re-enter the form data after authentication
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/room_api/eg007_create_form_group_controller.rb b/app/controllers/room_api/eg007_create_form_group_controller.rb
deleted file mode 100644
index 5990003..0000000
--- a/app/controllers/room_api/eg007_create_form_group_controller.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-class RoomApi::Eg007CreateFormGroupController < EgController
- before_action :check_auth
-
- def create
- results = RoomApi::Eg007CreateFormGroupService.new(session, request).call
-
- @title = "The form group was successfully created"
- @h1 = "The form group was successfully created"
- @message = "The form group was created! form group ID: #{results.form_group_id}, Name: #{results.name}"
- @json = results.to_json.to_json
-
- render 'ds_common/example_done'
- end
-
- private
-
- def check_auth
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
- unless token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted automatically
- # But since it should be rare to have a token issue here, we'll make the user re-enter the form data after authentication
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/room_api/eg008_grant_office_access_to_form_group_controller.rb b/app/controllers/room_api/eg008_grant_office_access_to_form_group_controller.rb
deleted file mode 100644
index d7eedee..0000000
--- a/app/controllers/room_api/eg008_grant_office_access_to_form_group_controller.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-class RoomApi::Eg008GrantOfficeAccessToFormGroupController < EgController
- before_action :check_auth
-
- def create
- results = RoomApi::Eg008GrantOfficeAccessToFormGroupService.new(session, request).call
- result = results.to_json.to_json
- if result['exception']
- @error_code = results[:exception]
- @error_message = "Office may already have access to form group."
- render 'ds_common/error'
- else
- @title = "Granted office access to form group"
- @h1 = "Granted office access to form group"
- @message = "office access has been granted for the form group."
- render 'ds_common/example_done'
- end
-
- end
-
- def get
- super
- # Step 3 start
- @offices = RoomApi::GetDataService.new(session).get_offices
- # Step 3 end
-
- # Step 4 start
- @form_groups = RoomApi::GetDataService.new(session).get_form_groups
- # Step 4 end
- end
-
- private
-
- def check_auth
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
- unless token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted automatically
- # But since it should be rare to have a token issue here, we'll make the user re-enter the form data after authentication
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/room_api/eg009_assign_form_to_form_group_controller.rb b/app/controllers/room_api/eg009_assign_form_to_form_group_controller.rb
deleted file mode 100644
index 4ecde46..0000000
--- a/app/controllers/room_api/eg009_assign_form_to_form_group_controller.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-class RoomApi::Eg009AssignFormToFormGroupController < EgController
- before_action :check_auth
-
- def create
- results = RoomApi::Eg009AssignFormToFormGroupService.new(session, request).call
- result = results.to_json.to_json
- if result['exception']
- @error_code = results[:exception]
- @error_message = "Form may already be assigned to form group."
- render 'ds_common/error'
- else
- @title = "Assigned form to form group"
- @h1 = "Assigned form to form group"
- @message = "Form has been assigned to the selected form group."
-
- render 'ds_common/example_done'
- end
- end
-
- def get
- super
- # Step 3 start
- @forms = RoomApi::GetDataService.new(session).get_form_libraries
- # Step 3 end
-
- # Step 4 start
- @form_groups = RoomApi::GetDataService.new(session).get_form_groups
- # Step 4 end
- end
-
- private
-
- def check_auth
- minimum_buffer_min = 10
- token_ok = check_token(minimum_buffer_min)
- unless token_ok
- flash[:messages] = 'Sorry, you need to re-authenticate.'
- # We could store the parameters of the requested operation so it could be restarted automatically
- # But since it should be rare to have a token issue here, we'll make the user re-enter the form data after authentication
- redirect_to '/ds/mustAuthenticate'
- end
- end
-end
diff --git a/app/controllers/room_api/reg001_create_room_with_data_controller.rb b/app/controllers/room_api/reg001_create_room_with_data_controller.rb
new file mode 100644
index 0000000..fa99f71
--- /dev/null
+++ b/app/controllers/room_api/reg001_create_room_with_data_controller.rb
@@ -0,0 +1,23 @@
+class RoomApi::Reg001CreateRoomWithDataController < EgController
+ before_action -> { check_auth('Rooms') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 1, 'Rooms') }
+
+ def create
+ args = {
+ room_name: params[:roomName],
+ office_id: RoomApi::GetDataService.new(session).get_offices[0]['officeId'],
+ role_id: RoomApi::GetDataService.new(session).get_default_admin_role_id,
+ account_id: session[:ds_account_id],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token]
+ }
+
+ results = RoomApi::Eg001CreateRoomWithDataService.new(args).worker
+
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results.room_id, results.name)
+ @json = results.to_json.to_json
+
+ render 'ds_common/example_done'
+ end
+end
diff --git a/app/controllers/room_api/reg002_create_room_with_template_controller.rb b/app/controllers/room_api/reg002_create_room_with_template_controller.rb
new file mode 100644
index 0000000..ac5e264
--- /dev/null
+++ b/app/controllers/room_api/reg002_create_room_with_template_controller.rb
@@ -0,0 +1,30 @@
+class RoomApi::Reg002CreateRoomWithTemplateController < EgController
+ before_action -> { check_auth('Rooms') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 2, 'Rooms') }
+
+ def create
+ args = {
+ room_name: params[:roomName],
+ office_id: RoomApi::GetDataService.new(session).get_offices[0]['officeId'],
+ role_id: RoomApi::GetDataService.new(session).get_default_admin_role_id,
+ template_id: params['templateId'],
+ account_id: session[:ds_account_id],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token]
+ }
+
+ results = RoomApi::Eg002CreateRoomWithTemplateService.new(args).worker
+
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results.room_id, results.name)
+ @json = results.to_json.to_json
+
+ render 'ds_common/example_done'
+ end
+
+ def get
+ #ds-snippet-start:Rooms2Step3
+ @templates = RoomApi::GetDataService.new(session).get_templates
+ #ds-snippet-end:Rooms2Step3
+ end
+end
diff --git a/app/controllers/room_api/reg003_export_data_from_room_controller.rb b/app/controllers/room_api/reg003_export_data_from_room_controller.rb
new file mode 100644
index 0000000..e4a36a2
--- /dev/null
+++ b/app/controllers/room_api/reg003_export_data_from_room_controller.rb
@@ -0,0 +1,25 @@
+class RoomApi::Reg003ExportDataFromRoomController < EgController
+ before_action -> { check_auth('Rooms') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 3, 'Rooms') }
+
+ def create
+ args = {
+ room_id: params['roomId'],
+ account_id: session[:ds_account_id],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token]
+ }
+
+ results = RoomApi::Eg003ExportDataFromRoomService.new(args).worker
+
+ @title = @example['ExampleName']
+ @message = @example['ResultsPageText']
+ @json = results.to_json.to_json
+
+ render 'ds_common/example_done'
+ end
+
+ def get
+ @rooms = RoomApi::GetDataService.new(session).get_rooms
+ end
+end
diff --git a/app/controllers/room_api/reg004_add_forms_to_room_controller.rb b/app/controllers/room_api/reg004_add_forms_to_room_controller.rb
new file mode 100644
index 0000000..4c5a2b3
--- /dev/null
+++ b/app/controllers/room_api/reg004_add_forms_to_room_controller.rb
@@ -0,0 +1,27 @@
+class RoomApi::Reg004AddFormsToRoomController < EgController
+ before_action -> { check_auth('Rooms') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 4, 'Rooms') }
+
+ def create
+ args = {
+ form_id: params['formId'],
+ room_id: params['roomId'],
+ account_id: session[:ds_account_id],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token]
+ }
+
+ results = RoomApi::Eg004AddFormsToRoomService.new(args).worker
+
+ @title = @example['ExampleName']
+ @message = @example['ResultsPageText']
+ @json = results.to_json.to_json
+
+ render 'ds_common/example_done'
+ end
+
+ def get
+ @rooms = RoomApi::GetDataService.new(session).get_rooms
+ @form_libraries = RoomApi::GetDataService.new(session).get_form_libraries
+ end
+end
diff --git a/app/controllers/room_api/reg005_get_rooms_with_filters_controller.rb b/app/controllers/room_api/reg005_get_rooms_with_filters_controller.rb
new file mode 100644
index 0000000..35bb503
--- /dev/null
+++ b/app/controllers/room_api/reg005_get_rooms_with_filters_controller.rb
@@ -0,0 +1,26 @@
+class RoomApi::Reg005GetRoomsWithFiltersController < EgController
+ before_action -> { check_auth('Rooms') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 5, 'Rooms') }
+
+ def create
+ args = {
+ date_from: params[:date_from],
+ date_to: params[:date_to],
+ account_id: session[:ds_account_id],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token]
+ }
+
+ results = RoomApi::Eg005GetRoomsWithFiltersService.new(args).worker
+
+ @title = @example['ExampleName']
+ @message = @example['ResultsPageText']
+ @json = results.to_json.to_json
+
+ render 'ds_common/example_done'
+ end
+
+ def get
+ @rooms = RoomApi::GetDataService.new(session).get_rooms
+ end
+end
diff --git a/app/controllers/room_api/reg006_create_an_external_form_fill_session_controller.rb b/app/controllers/room_api/reg006_create_an_external_form_fill_session_controller.rb
new file mode 100644
index 0000000..691dea0
--- /dev/null
+++ b/app/controllers/room_api/reg006_create_an_external_form_fill_session_controller.rb
@@ -0,0 +1,35 @@
+class RoomApi::Reg006CreateAnExternalFormFillSessionController < EgController
+ before_action -> { check_auth('Rooms') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 6, 'Rooms') }
+
+ def create
+ args = {
+ form_id: params['formId'],
+ room_id: params['roomId'],
+ account_id: session[:ds_account_id],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token],
+ allowed_host: request.host_with_port
+ }
+ begin
+ results = RoomApi::Eg006CreateAnExternalFormFillSessionService.new(args).worker
+
+ @title = @example['ExampleName']
+ @message = @example['ResultsPageText']
+ @json = results.to_json
+ @url = results.url
+
+ render 'room_api/reg006_create_an_external_form_fill_session/results'
+ rescue DocuSign_Rooms::ApiError => e
+ handle_error(e)
+ end
+ end
+
+ def get_rooms
+ @rooms = RoomApi::GetDataService.new(session).get_rooms
+ end
+
+ def get_forms
+ @form_libraries = RoomApi::GetDataService.new(session, params['roomId']).get_forms_from_room
+ end
+end
diff --git a/app/controllers/room_api/reg007_create_form_group_controller.rb b/app/controllers/room_api/reg007_create_form_group_controller.rb
new file mode 100644
index 0000000..4ae34d6
--- /dev/null
+++ b/app/controllers/room_api/reg007_create_form_group_controller.rb
@@ -0,0 +1,20 @@
+class RoomApi::Reg007CreateFormGroupController < EgController
+ before_action -> { check_auth('Rooms') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 7, 'Rooms') }
+
+ def create
+ args = {
+ group_name: params[:group_name],
+ account_id: session[:ds_account_id],
+ access_token: session[:ds_access_token]
+ }
+
+ results = RoomApi::Eg007CreateFormGroupService.new(args).worker
+
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results.name)
+ @json = results.to_json.to_json
+
+ render 'ds_common/example_done'
+ end
+end
diff --git a/app/controllers/room_api/reg008_grant_office_access_to_form_group_controller.rb b/app/controllers/room_api/reg008_grant_office_access_to_form_group_controller.rb
new file mode 100644
index 0000000..83a57c6
--- /dev/null
+++ b/app/controllers/room_api/reg008_grant_office_access_to_form_group_controller.rb
@@ -0,0 +1,36 @@
+class RoomApi::Reg008GrantOfficeAccessToFormGroupController < EgController
+ before_action -> { check_auth('Rooms') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 8, 'Rooms') }
+
+ def create
+ args = {
+ office_id: params[:office_id],
+ form_group_id: params[:form_group_id],
+ account_id: session[:ds_account_id],
+ access_token: session[:ds_access_token]
+ }
+
+ results = RoomApi::Eg008GrantOfficeAccessToFormGroupService.new(args).worker
+ result = results.to_json.to_json
+ if result['exception']
+ @error_code = results[:exception]
+ @error_message = 'Office may already have access to form group.'
+ render 'ds_common/error'
+ else
+ @title = @example['ExampleName']
+ @message = 'office access has been granted for the form group.'
+ render 'ds_common/example_done'
+ end
+ end
+
+ def get
+ super
+ # Step 3 start
+ @offices = RoomApi::GetDataService.new(session).get_offices
+ # Step 3 end
+
+ # Step 4 start
+ @form_groups = RoomApi::GetDataService.new(session).get_form_groups
+ # Step 4 end
+ end
+end
diff --git a/app/controllers/room_api/reg009_assign_form_to_form_group_controller.rb b/app/controllers/room_api/reg009_assign_form_to_form_group_controller.rb
new file mode 100644
index 0000000..9b36f1d
--- /dev/null
+++ b/app/controllers/room_api/reg009_assign_form_to_form_group_controller.rb
@@ -0,0 +1,37 @@
+class RoomApi::Reg009AssignFormToFormGroupController < EgController
+ before_action -> { check_auth('Rooms') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 9, 'Rooms') }
+
+ def create
+ args = {
+ form_id: params[:form_id],
+ form_group_id: params[:form_group_id],
+ account_id: session[:ds_account_id],
+ access_token: session[:ds_access_token]
+ }
+
+ results = RoomApi::Eg009AssignFormToFormGroupService.new(args).worker
+ result = results.to_json.to_json
+ if result['exception']
+ @error_code = results[:exception]
+ @error_message = 'Form may already be assigned to form group.'
+ render 'ds_common/error'
+ else
+ @title = @example['ExampleName']
+ @message = 'Form has been assigned to the selected form group.'
+
+ render 'ds_common/example_done'
+ end
+ end
+
+ def get
+ super
+ #ds-snippet-start:Rooms9Step3
+ @forms = RoomApi::GetDataService.new(session).get_form_libraries
+ #ds-snippet-end:Rooms9Step3
+
+ #ds-snippet-start:Rooms9Step4
+ @form_groups = RoomApi::GetDataService.new(session).get_form_groups
+ #ds-snippet-end:Rooms9Step4
+ end
+end
diff --git a/app/controllers/session_controller.rb b/app/controllers/session_controller.rb
index 151349d..39d51bc 100644
--- a/app/controllers/session_controller.rb
+++ b/app/controllers/session_controller.rb
@@ -1,76 +1,89 @@
-# frozen_string_literal: true
-
-class SessionController < ApplicationController
- # GET /auth/:provider/callback
- def create
- if session[:eg]
- redirect_url = "/" + session[:eg]
- else
- redirect_url = root_path
- end
-
- # reset the session
- internal_destroy
-
- Rails.logger.debug "\n==> DocuSign callback Authentication response:\n#{auth_hash.to_yaml}\n"
- Rails.logger.info "==> Login: New token for admin user which will expire at: #{Time.at(auth_hash.credentials['expires_at'])}"
- store_auth_hash_from_docusign_callback
- redirect_to redirect_url
- end
-
- # GET /ds/logout
- def destroy
- internal_destroy
- redirect_to root_path
- end
-
- # GET /auth/failure
- def omniauth_failure
- error_msg = "OmniAuth authentication failure message: #{params[:message]} for strategy: #{params[:strategy]} and HTTP_REFERER: #{params[:origin]}"
- Rails.logger.warn "\n==> #{error_msg}"
- flash[:notice] = error_msg
- redirect_to root_path
- end
-
- def show
- Rails.logger.debug "==> Session:\n#{session.to_h.to_yaml}"
- render json: session.to_json
- end
-
- protected
-
- def internal_destroy
- session.delete :ds_expires_at
- session.delete :ds_user_name
- session.delete :ds_access_token
- session.delete :ds_account_id
- session.delete :ds_account_name
- session.delete :ds_base_path
- session.delete 'omniauth.state'
- session.delete 'omniauth.params'
- session.delete 'omniauth.origin'
- session.delete :envelope_id
- session.delete :envelope_documents
- session.delete :template_id
- session.delete :eg
- end
-
- def store_auth_hash_from_docusign_callback
- session[:ds_expires_at] = auth_hash.credentials['expires_at']
- session[:ds_user_name] = auth_hash.info.name
- session[:ds_access_token] = auth_hash.credentials.token
- session[:ds_account_id] = auth_hash.extra.account_id
- session[:ds_account_name] = auth_hash.extra.account_name
- session[:ds_base_path] = auth_hash.extra.base_uri
- end
-
- # returns hash with key structure of:
- # - provider
- # - uid
- # - info: [name, email, first_name, last_name]
- # - credentials: [token, refresh_token, expires_at, expires]
- # - extra: [sub, account_id, account_name, base_uri]
- def auth_hash
- @auth_hash ||= request.env['omniauth.auth']
- end
-end
+# frozen_string_literal: true
+
+class SessionController < ApplicationController
+ # GET /auth/:provider/callback
+ def create
+ redirect_url = if session[:eg]
+ "/#{session[:eg]}"
+ else
+ root_path
+ end
+
+ # reset the session
+ internal_destroy
+
+ Rails.logger.debug "\n==> Docusign callback Authentication response:\n#{auth_hash.to_yaml}\n"
+ Rails.logger.info "==> Login: New token for admin user which will expire at: #{Time.at(auth_hash.credentials['expires_at'])}"
+ store_auth_hash_from_docusign_callback
+ redirect_to redirect_url
+ end
+
+ # GET /ds/logout
+ def destroy
+ internal_destroy
+ redirect_to root_path
+ end
+
+ # def switch_api
+ # internal_destroy
+ # end
+
+ # GET /auth/failure
+ def omniauth_failure
+ unless session[:pkce_failed]
+ Rails.logger.warn "PKCE Auth failed \n"
+ session[:pkce_failed] = true
+ return redirect_to '/auth/docusign'
+ end
+
+ error_msg = "OmniAuth authentication failure message: #{params[:message]} for strategy: #{params[:strategy]} and HTTP_REFERER: #{params[:origin]}"
+ Rails.logger.warn "\n==> #{error_msg}"
+ flash[:notice] = error_msg
+ redirect_to root_path
+ end
+
+ def show
+ Rails.logger.debug "==> Session:\n#{session.to_h.to_yaml}"
+ render json: session.to_json
+ end
+
+ protected
+
+ def internal_destroy
+ session.delete :ds_expires_at
+ session.delete :ds_user_name
+ session.delete :ds_access_token
+ session.delete :ds_account_id
+ session.delete :ds_account_name
+ session.delete :ds_base_path
+ session.delete 'omniauth.state'
+ session.delete 'omniauth.params'
+ session.delete 'omniauth.origin'
+ session.delete :envelope_id
+ session.delete :envelope_documents
+ session.delete :template_id
+ session.delete :eg
+ session.delete :manifest
+ session.delete :status_cfr
+ session.delete :is_workflow_published
+ end
+
+ def store_auth_hash_from_docusign_callback
+ session[:ds_expires_at] = auth_hash.credentials['expires_at']
+ session[:ds_user_name] = auth_hash.info.name
+ session[:ds_access_token] = auth_hash.credentials.token
+ session[:ds_account_id] = auth_hash.extra.account_id
+ session[:ds_account_name] = auth_hash.extra.account_name
+ session[:ds_base_path] = auth_hash.extra.base_uri
+ end
+
+ # returns hash with key structure of:
+ # - provider
+ # - uid
+ # - info: [name, email, first_name, last_name]
+ # - credentials: [token, refresh_token, expires_at, expires]
+ # - extra: [sub, account_id, account_name, base_uri]
+ def auth_hash
+ @auth_hash ||= request.env['omniauth.auth']
+ end
+end
diff --git a/app/controllers/webforms/weg001_create_instance_controller.rb b/app/controllers/webforms/weg001_create_instance_controller.rb
new file mode 100644
index 0000000..8899dab
--- /dev/null
+++ b/app/controllers/webforms/weg001_create_instance_controller.rb
@@ -0,0 +1,60 @@
+# frozen_string_literal: true
+
+class Webforms::Weg001CreateInstanceController < EgController
+ before_action -> { check_auth('WebForms') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 1, 'WebForms') }
+
+ def create_web_form_template
+ args = {
+ template_name: 'Web Form Example Template',
+ account_id: session[:ds_account_id],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token]
+ }
+
+ begin
+ web_form_template_id = Webforms::Eg001CreateInstanceService.new(args).create_web_form_template
+ Utils::FileUtils.new.replace_template_id(File.join('data', Rails.application.config.web_form_config_file), web_form_template_id)
+ session[:web_form_template_id] = web_form_template_id
+
+ redirect_to '/weg001webForm'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+ end
+
+ def create_web_form_instance
+ args = {
+ form_name: 'Web Form Example Template',
+ client_user_id: '1234-5678-abcd-ijkl',
+ account_id: session[:ds_account_id],
+ base_path: Rails.application.config.webforms_host,
+ access_token: session[:ds_access_token]
+ }
+ create_instance_service = Webforms::Eg001CreateInstanceService.new(args)
+ web_forms = create_instance_service.list_web_forms
+ results = create_instance_service.create_web_form_instance web_forms.items.first.id
+
+ @integration_key = Rails.application.config.integration_key
+ @form_url = results.form_url
+ @instance_token = results.instance_token
+ render 'webforms/weg001_create_instance/web_form_embed'
+ end
+
+ def get
+ additional_page = @example['AdditionalPage'].find { |p| p['Name'] == 'create_web_form_template' }
+ @example['ExampleDescription'] = additional_page['ResultsPageText']
+
+ render 'webforms/weg001_create_instance/get'
+ end
+
+ def get_web_form_create_view
+ redirect_to '/weg001' if session[:web_form_template_id].nil?
+
+ additional_page = @example['AdditionalPage'].find { |p| p['Name'] == 'create_web_form' }
+ @title = @example['ExampleName']
+ @description = format_string(additional_page['ResultsPageText'], 'data')
+
+ render 'webforms/weg001_create_instance/web_form_create'
+ end
+end
diff --git a/app/controllers/webforms/weg002_create_remote_instance_controller.rb b/app/controllers/webforms/weg002_create_remote_instance_controller.rb
new file mode 100644
index 0000000..92c57b3
--- /dev/null
+++ b/app/controllers/webforms/weg002_create_remote_instance_controller.rb
@@ -0,0 +1,59 @@
+# frozen_string_literal: true
+
+class Webforms::Weg002CreateRemoteInstanceController < EgController
+ before_action -> { check_auth('WebForms') }
+ before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 2, 'WebForms') }
+
+ def create_web_form_template
+ args = {
+ template_name: 'Web Form Example Template',
+ account_id: session[:ds_account_id],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token]
+ }
+
+ begin
+ web_form_template_id = Webforms::Eg002CreateRemoteInstanceService.new(args).create_web_form_template
+ Utils::FileUtils.new.replace_template_id(File.join('data', Rails.application.config.web_form_config_file), web_form_template_id)
+ session[:web_form_template_id] = web_form_template_id
+
+ redirect_to '/weg002webForm'
+ rescue DocuSign_eSign::ApiError => e
+ handle_error(e)
+ end
+ end
+
+ def create_web_form_instance
+ args = {
+ form_name: 'Web Form Example Template',
+ account_id: session[:ds_account_id],
+ base_path: Rails.application.config.webforms_host,
+ signer_name: Rails.application.config.signer_name,
+ signer_email: Rails.application.config.signer_email,
+ access_token: session[:ds_access_token]
+ }
+ create_remote_instance_service = Webforms::Eg002CreateRemoteInstanceService.new(args)
+ web_forms = create_remote_instance_service.list_web_forms
+
+ if web_forms.items.nil? || web_forms.items.empty?
+ @error_code = '404'
+ @error_message = @example['CustomErrorTexts'][0]['ErrorMessage']
+ return render 'ds_common/error'
+ end
+ results = create_remote_instance_service.create_web_form_instance web_forms.items.first.id
+
+ @title = @example['ExampleName']
+ @message = format_string(@example['ResultsPageText'], results.envelopes[0].id, results.id)
+ render 'ds_common/example_done'
+ end
+
+ def get_web_form_create_view
+ redirect_to '/weg002' if session[:web_form_template_id].nil?
+
+ additional_page = @example['AdditionalPage'].find { |p| p['Name'] == 'create_web_form' }
+ @title = @example['ExampleName']
+ @description = format_string(additional_page['ResultsPageText'], 'data')
+
+ render 'webforms/weg002_create_remote_instance/web_form_create'
+ end
+end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 15b06f0..9a905c5 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,4 +1,17 @@
# frozen_string_literal: true
module ApplicationHelper
+ require 'json/ext'
+
+ def format_string(string, *args)
+ string.gsub(/\{(\d+)\}/) { args[::Regexp.last_match(1).to_i] }
+ end
+
+ def to_json(hash)
+ hash.to_json
+ end
+
+ def example_available?(example)
+ !example['SkipForLanguages'] or !example['SkipForLanguages'].include? 'ruby'
+ end
end
diff --git a/app/helpers/eg024_brands_creating_helper.rb b/app/helpers/eg024_brands_creating_helper.rb
index 8f00128..df0fc09 100644
--- a/app/helpers/eg024_brands_creating_helper.rb
+++ b/app/helpers/eg024_brands_creating_helper.rb
@@ -1,13 +1,13 @@
module Eg024BrandsCreatingHelper
def language_list
- languages = [ ['Arabic', 'ar'],[ 'Armenian', 'hy'] , ['Bahasa Indonesia', 'id' ], ['Bahasa Malay', 'ms'], ['Bulgarian', 'bg'],
- ['Chinese Simplified', 'zh_CN'], ['Chinese Traditional', 'zh_TW'], ['Croatian', 'hr'], ['Czech', 'cs'],
- ['Danish', 'da'], ['Dutch', 'nl'], ['English UK', 'en_GB'], ['English US', 'en' ], ['Estonian', 'et'], ['Farsi', 'fa'],
- ['Hindi', 'hi'], ['Hungarian', 'hu'], ['Italian', 'it'], ['Japanese', 'ja'], ['Korean', 'ko'], ['Latvian', 'lv'],
- ['Lithuanian', 'lt'], ['Norwegian', 'no'], ['Polish', 'pl'], ['Portuguese', 'pt'], ['Portuguese Brasil', 'pt_BR'], ['Romanian', 'ro'],
- ['Russian', 'ru'], ['Serbian', 'sr'], ['Slovak', 'sk'], ['Slovenian', 'sl'], ['Spanish', 'es'], ['Spanish Latin America', 'es_MX'],
- ['Swedish', 'sv'], ['Thai', 'th'], ['Turkish', 'tr'], ['Ukranian', 'uk'], ['Vietnamese', 'vi'] ]
- array = languages.map{ |key, value| [key, value] }
+ languages = [%w[Arabic ar], %w[Armenian hy], ['Bahasa Indonesia', 'id'], ['Bahasa Malay', 'ms'], %w[Bulgarian bg],
+ ['Chinese Simplified', 'zh_CN'], ['Chinese Traditional', 'zh_TW'], %w[Croatian hr], %w[Czech cs],
+ %w[Danish da], %w[Dutch nl], ['English UK', 'en_GB'], ['English US', 'en'], %w[Estonian et], %w[Farsi fa],
+ %w[Hindi hi], %w[Hungarian hu], %w[Italian it], %w[Japanese ja], %w[Korean ko], %w[Latvian lv],
+ %w[Lithuanian lt], %w[Norwegian no], %w[Polish pl], %w[Portuguese pt], ['Portuguese Brasil', 'pt_BR'], %w[Romanian ro],
+ %w[Russian ru], %w[Serbian sr], %w[Slovak sk], %w[Slovenian sl], %w[Spanish es], ['Spanish Latin America', 'es_MX'],
+ %w[Swedish sv], %w[Thai th], %w[Turkish tr], %w[Ukranian uk], %w[Vietnamese vi]]
+ array = languages.map { |key, value| [key, value] }
options_for_select(array)
end
end
diff --git a/app/services/admin_api/eg001_create_user_service.rb b/app/services/admin_api/eg001_create_user_service.rb
new file mode 100644
index 0000000..7201cc8
--- /dev/null
+++ b/app/services/admin_api/eg001_create_user_service.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+class AdminApi::Eg001CreateUserService
+ attr_reader :args, :user_data
+
+ def initialize(args, user_data)
+ @args = args
+ @user_data = user_data
+ end
+
+ def worker
+ #ds-snippet-start:Admin1Step2
+ configuration = DocuSign_Admin::Configuration.new
+ configuration.host = Rails.configuration.admin_host
+
+ api_client = DocuSign_Admin::ApiClient.new(configuration)
+ api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
+ #ds-snippet-end:Admin1Step2
+
+ #ds-snippet-start:Admin1Step6
+ users_api = DocuSign_Admin::UsersApi.new(api_client)
+ results, _status, headers = users_api.create_user_with_http_info(args[:organization_id], user_data)
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+ #ds-snippet-end:Admin1Step6
+
+ results
+ end
+end
diff --git a/app/services/admin_api/eg002_create_active_clm_esign_user_service.rb b/app/services/admin_api/eg002_create_active_clm_esign_user_service.rb
new file mode 100644
index 0000000..499e238
--- /dev/null
+++ b/app/services/admin_api/eg002_create_active_clm_esign_user_service.rb
@@ -0,0 +1,62 @@
+# frozen_string_literal: true
+
+class AdminApi::Eg002CreateActiveClmEsignUserService
+ attr_reader :args
+
+ def initialize(args)
+ @args = args
+ end
+
+ def worker
+ configuration = DocuSign_Admin::Configuration.new
+ configuration.host = Rails.configuration.admin_host
+
+ api_client = DocuSign_Admin::ApiClient.new(configuration)
+ api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
+
+ #ds-snippet-start:Admin2Step6
+ users_api = DocuSign_Admin::UsersApi.new(api_client)
+ results, _status, headers = users_api.add_or_update_user_with_http_info(args[:organization_id], args[:account_id], body(args))
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+ #ds-snippet-end:Admin2Step6
+
+ results
+ end
+
+ private
+
+ #ds-snippet-start:Admin2Step5
+ def body(args)
+ {
+ user_name: args[:user_name],
+ first_name: args[:first_name],
+ last_name: args[:last_name],
+ email: args[:email],
+ auto_activate_memberships: true,
+ product_permission_profiles: [
+ {
+ permission_profile_id: args[:esign_permission_profile_id],
+ product_id: args[:esign_product_id]
+ },
+ {
+ permission_profile_id: args[:clm_permission_profile_id],
+ product_id: args[:clm_product_id]
+ }
+ ],
+ ds_groups: [
+ {
+ ds_group_id: args[:ds_group_id]
+ }
+ ]
+ }
+ end
+ #ds-snippet-end:Admin2Step5
+end
diff --git a/app/services/admin_api/eg003_bulk_export_user_data_service.rb b/app/services/admin_api/eg003_bulk_export_user_data_service.rb
new file mode 100644
index 0000000..679e049
--- /dev/null
+++ b/app/services/admin_api/eg003_bulk_export_user_data_service.rb
@@ -0,0 +1,91 @@
+class AdminApi::Eg003BulkExportUserDataService
+ attr_reader :bulk_exports_api, :args
+
+ def initialize(args)
+ @args = args
+ end
+
+ def worker
+ #ds-snippet-start:Admin3Step2
+ configuration = DocuSign_Admin::Configuration.new
+ configuration.host = Rails.configuration.admin_host
+
+ api_client = DocuSign_Admin::ApiClient.new(configuration)
+ api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
+ #ds-snippet-end:Admin3Step2
+
+ #ds-snippet-start:Admin3Step3
+ @bulk_exports_api = DocuSign_Admin::BulkExportsApi.new(api_client)
+ response, _status, headers = bulk_exports_api.create_user_list_export_with_http_info(args[:organization_id], args[:request_body])
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+ #ds-snippet-end:Admin3Step3
+
+ #ds-snippet-start:Admin3Step4
+ retry_count = 5
+ while retry_count >= 0
+ if response.results
+ get_exported_user_data(args, response.id)
+ break
+ else
+ retry_count -= 1
+ sleep(5)
+ response, _status, headers = bulk_exports_api.get_user_list_export_with_http_info(args[:organization_id], response.id)
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+ end
+ end
+ #ds-snippet-end:Admin3Step4
+
+ response
+ end
+
+ private
+
+ #ds-snippet-start:Admin3Step5
+ def get_exported_user_data(args, export_id)
+ bulk_export_response, _status, headers = bulk_exports_api.get_user_list_export_with_http_info(args[:organization_id], export_id)
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+
+ data_url = bulk_export_response.results[0].url
+
+ uri = URI(data_url)
+
+ req = Net::HTTP::Get.new(uri)
+ req['Authorization'] = "Bearer #{args[:access_token]}"
+
+ http = Net::HTTP.new(uri.host, uri.port)
+ http.use_ssl = true
+
+ http.request(req) do |response|
+ File.open(args[:file_path], 'w') do |file|
+ response.read_body do |chunk|
+ file.write(chunk)
+ end
+ end
+ end
+ end
+ #ds-snippet-end:Admin3Step5
+end
diff --git a/app/services/admin_api/eg004_import_user_service.rb b/app/services/admin_api/eg004_import_user_service.rb
new file mode 100644
index 0000000..d9f0c7e
--- /dev/null
+++ b/app/services/admin_api/eg004_import_user_service.rb
@@ -0,0 +1,36 @@
+class AdminApi::Eg004ImportUserService
+ attr_reader :args
+
+ def initialize(args)
+ @args = args
+ end
+
+ def worker
+ #ds-snippet-start:Admin4Step2
+ configuration = DocuSign_Admin::Configuration.new
+ configuration.host = Rails.configuration.admin_host
+
+ api_client = DocuSign_Admin::ApiClient.new(configuration)
+ api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
+ #ds-snippet-end:Admin4Step2
+
+ #ds-snippet-start:Admin4Step3
+ csv_file_data = File.open(args[:csv_file_path]).read
+ csv_file_data = csv_file_data.gsub('{account_id}', args[:account_id])
+
+ @bulk_imports_api = DocuSign_Admin::BulkImportsApi.new(api_client)
+ results, _status, headers = @bulk_imports_api.create_bulk_import_add_users_request_with_http_info(args[:organization_id], csv_file_data)
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+ #ds-snippet-end:Admin4Step3
+
+ results
+ end
+end
diff --git a/app/services/admin_api/eg005_audit_users_service.rb b/app/services/admin_api/eg005_audit_users_service.rb
new file mode 100644
index 0000000..7afab0c
--- /dev/null
+++ b/app/services/admin_api/eg005_audit_users_service.rb
@@ -0,0 +1,63 @@
+# frozen_string_literal: true
+
+class AdminApi::Eg005AuditUsersService
+ attr_reader :args
+
+ def initialize(args)
+ @args = args
+ end
+
+ def worker
+ #ds-snippet-start:Admin5Step2
+ configuration = DocuSign_Admin::Configuration.new
+ configuration.host = Rails.configuration.admin_host
+
+ api_client = DocuSign_Admin::ApiClient.new(configuration)
+ api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
+ #ds-snippet-end:Admin5Step2
+
+ #ds-snippet-start:Admin5Step3
+ options = DocuSign_Admin::GetUsersOptions.new
+ options.account_id = args[:account_id]
+ options.last_modified_since = (Date.today - 10).strftime('%Y/%m/%d')
+
+ users_api = DocuSign_Admin::UsersApi.new(api_client)
+ modified_users, _status, headers = users_api.get_users_with_http_info(args[:organization_id], options)
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+ #ds-snippet-end:Admin5Step3
+
+ #ds-snippet-start:Admin5Step5
+ results = []
+ modified_users.as_json['users'].each do |user|
+ #ds-snippet-end:Admin5Step5
+ #ds-snippet-start:Admin5Step4
+ userProfilesOptions = DocuSign_Admin::GetUserProfilesOptions.new
+ userProfilesOptions.email = user['email']
+ #ds-snippet-end:Admin5Step4
+ #ds-snippet-start:Admin5Step5
+ result, _status, headers = users_api.get_user_profiles_with_http_info(args[:organization_id], userProfilesOptions)
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+
+ results.push(result)
+ end
+ #ds-snippet-end:Admin5Step5
+
+ results
+ end
+end
diff --git a/app/services/admin_api/eg006_get_user_profile_by_email_service.rb b/app/services/admin_api/eg006_get_user_profile_by_email_service.rb
new file mode 100644
index 0000000..8fdd40c
--- /dev/null
+++ b/app/services/admin_api/eg006_get_user_profile_by_email_service.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+class AdminApi::Eg006GetUserProfileByEmailService
+ attr_reader :args
+
+ def initialize(args)
+ @args = args
+ end
+
+ def worker
+ #ds-snippet-start:Admin6Step2
+ configuration = DocuSign_Admin::Configuration.new
+ configuration.host = Rails.configuration.admin_host
+
+ api_client = DocuSign_Admin::ApiClient.new(configuration)
+ api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
+ #ds-snippet-end:Admin6Step2
+
+ #ds-snippet-start:Admin6Step3
+ users_api = DocuSign_Admin::UsersApi.new(api_client)
+
+ options = DocuSign_Admin::GetUserDSProfilesByEmailOptions.new
+ options.email = args[:email]
+ results, _status, headers = users_api.get_user_ds_profiles_by_email_with_http_info(args[:organization_id], options)
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+ #ds-snippet-end:Admin6Step3
+
+ results
+ end
+end
diff --git a/app/services/admin_api/eg007_get_user_profile_by_user_id_service.rb b/app/services/admin_api/eg007_get_user_profile_by_user_id_service.rb
new file mode 100644
index 0000000..cb4f237
--- /dev/null
+++ b/app/services/admin_api/eg007_get_user_profile_by_user_id_service.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+class AdminApi::Eg007GetUserProfileByUserIdService
+ attr_reader :args
+
+ def initialize(args)
+ @args = args
+ end
+
+ def worker
+ #ds-snippet-start:Admin7Step2
+ configuration = DocuSign_Admin::Configuration.new
+ configuration.host = Rails.configuration.admin_host
+
+ api_client = DocuSign_Admin::ApiClient.new(configuration)
+ api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
+ #ds-snippet-end:Admin7Step2
+
+ #ds-snippet-start:Admin7Step3
+ users_api = DocuSign_Admin::UsersApi.new(api_client)
+ results, _status, headers = users_api.get_user_ds_profile_with_http_info(args[:organization_id], args[:user_id])
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+ #ds-snippet-end:Admin7Step3
+
+ results
+ end
+end
diff --git a/app/services/admin_api/eg008_update_user_product_permission_profile_service.rb b/app/services/admin_api/eg008_update_user_product_permission_profile_service.rb
new file mode 100644
index 0000000..60d726a
--- /dev/null
+++ b/app/services/admin_api/eg008_update_user_product_permission_profile_service.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+class AdminApi::Eg008UpdateUserProductPermissionProfileService
+ attr_reader :args
+
+ def initialize(args)
+ @args = args
+ end
+
+ def worker
+ #ds-snippet-start:Admin8Step2
+ configuration = DocuSign_Admin::Configuration.new
+ configuration.host = Rails.configuration.admin_host
+
+ api_client = DocuSign_Admin::ApiClient.new(configuration)
+ api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
+ #ds-snippet-end:Admin8Step2
+
+ #ds-snippet-start:Admin8Step3
+ product_permission_profile = DocuSign_Admin::ProductPermissionProfileRequest.new({ 'permission_profile_id' => args[:permission_profile_id], 'product_id' => args[:product_id] })
+ user_product_permission_profile_request = DocuSign_Admin::UserProductPermissionProfilesRequest.new({ 'email' => args[:email], 'product_permission_profiles' => [product_permission_profile] })
+ #ds-snippet-end:Admin8Step3
+
+ #ds-snippet-start:Admin8Step4
+ product_permission_profiles_api = DocuSign_Admin::ProductPermissionProfilesApi.new(api_client)
+ results, _status, headers = product_permission_profiles_api.add_user_product_permission_profiles_by_email_with_http_info(args[:organization_id], args[:account_id], user_product_permission_profile_request)
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+ #ds-snippet-end:Admin8Step4
+
+ results
+ end
+end
diff --git a/app/services/admin_api/eg009_delete_user_product_permission_profile_service.rb b/app/services/admin_api/eg009_delete_user_product_permission_profile_service.rb
new file mode 100644
index 0000000..75a9b75
--- /dev/null
+++ b/app/services/admin_api/eg009_delete_user_product_permission_profile_service.rb
@@ -0,0 +1,67 @@
+# frozen_string_literal: true
+
+class AdminApi::Eg009DeleteUserProductPermissionProfileService
+ attr_reader :args
+
+ def initialize(args)
+ @args = args
+ end
+
+ def worker
+ #ds-snippet-start:Admin9Step2
+ configuration = DocuSign_Admin::Configuration.new
+ configuration.host = Rails.configuration.admin_host
+
+ api_client = DocuSign_Admin::ApiClient.new(configuration)
+ api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
+ #ds-snippet-end:Admin9Step2
+
+ #ds-snippet-start:Admin9Step4
+ user_product_profile_delete_request = DocuSign_Admin::UserProductProfileDeleteRequest.new({ 'user_email' => args[:email], 'product_ids' => [args[:product_id]] })
+ #ds-snippet-end:Admin9Step4
+
+ #ds-snippet-start:Admin9Step5
+ product_permission_profiles_api = DocuSign_Admin::ProductPermissionProfilesApi.new(api_client)
+ results, _status, headers = product_permission_profiles_api.remove_user_product_permission_with_http_info(args[:organization_id], args[:account_id], user_product_profile_delete_request)
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+ #ds-snippet-end:Admin9Step5
+
+ results
+ end
+
+ def get_permission_profiles_by_email
+ configuration = DocuSign_Admin::Configuration.new
+ configuration.host = Rails.configuration.admin_host
+
+ api_client = DocuSign_Admin::ApiClient.new(configuration)
+ api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
+
+ #ds-snippet-start:Admin9Step3
+ product_permission_profiles_api = DocuSign_Admin::ProductPermissionProfilesApi.new(api_client)
+
+ options = DocuSign_Admin::GetUserProductPermissionProfilesByEmailOptions.new
+ options.email = args[:email]
+
+ product_permission_profiles, _status, headers = product_permission_profiles_api.get_user_product_permission_profiles_by_email_with_http_info(args[:organization_id], args[:account_id], options)
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+
+ product_permission_profiles.as_json['product_permission_profiles']
+ #ds-snippet-end:Admin9Step3
+ end
+end
diff --git a/app/services/admin_api/eg010_delete_user_data_from_organization_service.rb b/app/services/admin_api/eg010_delete_user_data_from_organization_service.rb
new file mode 100644
index 0000000..52c0515
--- /dev/null
+++ b/app/services/admin_api/eg010_delete_user_data_from_organization_service.rb
@@ -0,0 +1,64 @@
+# frozen_string_literal: true
+
+class AdminApi::Eg010DeleteUserDataFromOrganizationService
+ attr_reader :args
+
+ def initialize(args)
+ @args = args
+ end
+
+ def worker
+ #ds-snippet-start:Admin10Step2
+ configuration = DocuSign_Admin::Configuration.new
+ configuration.host = Rails.configuration.admin_host
+
+ api_client = DocuSign_Admin::ApiClient.new(configuration)
+ api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
+ #ds-snippet-end:Admin10Step2
+
+ # Get user
+ users_api = DocuSign_Admin::UsersApi.new(api_client)
+
+ options = DocuSign_Admin::GetUserDSProfilesByEmailOptions.new
+ options.email = args[:email]
+ result, _status, headers = users_api.get_user_ds_profiles_by_email_with_http_info(args[:organization_id], options)
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+
+ user = result.users[0]
+
+ #ds-snippet-start:Admin10Step3
+ organizations_api = DocuSign_Admin::OrganizationsApi.new(api_client)
+ user_data_redaction_request = DocuSign_Admin::IndividualUserDataRedactionRequest.new(
+ user_id: user.id,
+ memberships: [
+ DocuSign_Admin::MembershipDataRedactionRequest.new(
+ account_id: user.memberships[0].account_id
+ )
+ ]
+ )
+ #ds-snippet-end:Admin10Step3
+
+ #ds-snippet-start:Admin10Step4
+ results, _status, headers = organizations_api.redact_individual_user_data_with_http_info(args[:organization_id], user_data_redaction_request)
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+ #ds-snippet-end:Admin10Step4
+
+ results
+ end
+end
diff --git a/app/services/admin_api/eg011_delete_user_data_from_account_service.rb b/app/services/admin_api/eg011_delete_user_data_from_account_service.rb
new file mode 100644
index 0000000..4001765
--- /dev/null
+++ b/app/services/admin_api/eg011_delete_user_data_from_account_service.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+class AdminApi::Eg011DeleteUserDataFromAccountService
+ attr_reader :args
+
+ def initialize(args)
+ @args = args
+ end
+
+ def worker
+ #ds-snippet-start:Admin11Step2
+ configuration = DocuSign_Admin::Configuration.new
+ configuration.host = Rails.configuration.admin_host
+
+ api_client = DocuSign_Admin::ApiClient.new(configuration)
+ api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
+ #ds-snippet-end:Admin11Step2
+
+ #ds-snippet-start:Admin11Step3
+ accounts_api = DocuSign_Admin::AccountsApi.new(api_client)
+ membership_redaction_request = DocuSign_Admin::IndividualMembershipDataRedactionRequest.new(
+ user_id: args[:user_id]
+ )
+ #ds-snippet-end:Admin11Step3
+
+ #ds-snippet-start:Admin11Step4
+ results, _status, headers = accounts_api.redact_individual_membership_data_with_http_info(args[:account_id], membership_redaction_request)
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+ #ds-snippet-end:Admin11Step4
+
+ results
+ end
+end
diff --git a/app/services/admin_api/eg012_clone_account_service.rb b/app/services/admin_api/eg012_clone_account_service.rb
new file mode 100644
index 0000000..3b87af7
--- /dev/null
+++ b/app/services/admin_api/eg012_clone_account_service.rb
@@ -0,0 +1,80 @@
+# frozen_string_literal: true
+
+class AdminApi::Eg012CloneAccountService
+ attr_reader :args
+
+ def initialize(args)
+ @args = args
+ end
+
+ def worker
+ #ds-snippet-start:Admin12Step2
+ configuration = DocuSign_Admin::Configuration.new
+ configuration.host = Rails.configuration.admin_host
+
+ api_client = DocuSign_Admin::ApiClient.new(configuration)
+ api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
+ #ds-snippet-end:Admin12Step2
+
+ #ds-snippet-start:Admin12Step4
+ source_account = DocuSign_Admin::AssetGroupAccountCloneSourceAccount.new
+ source_account.id = args[:source_account_id]
+
+ target_account_admin = DocuSign_Admin::AssetGroupAccountCloneTargetAccountAdmin.new
+ target_account_admin.first_name = args[:target_account_first_name]
+ target_account_admin.last_name = args[:target_account_last_name]
+ target_account_admin.email = args[:target_account_email]
+
+ target_account = DocuSign_Admin::AssetGroupAccountCloneTargetAccount.new
+ target_account.name = args[:target_account_name]
+ target_account.admin = target_account_admin
+ target_account.country_code = 'US'
+
+ account_data = DocuSign_Admin::AssetGroupAccountClone.new
+ account_data.source_account = source_account
+ account_data.target_account = target_account
+ #ds-snippet-end:Admin12Step4
+
+ #ds-snippet-start:Admin12Step5
+ asset_group_api = DocuSign_Admin::ProvisionAssetGroupApi.new(api_client)
+ results, _status, headers = asset_group_api.clone_asset_group_account_with_http_info(args[:organization_id], account_data)
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+ #ds-snippet-end:Admin12Step5
+
+ results
+ end
+
+ def get_account
+ configuration = DocuSign_Admin::Configuration.new
+ configuration.host = Rails.configuration.admin_host
+
+ api_client = DocuSign_Admin::ApiClient.new(configuration)
+ api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
+
+ #ds-snippet-start:Admin12Step3
+ asset_group_api = DocuSign_Admin::ProvisionAssetGroupApi.new(api_client)
+ options = DocuSign_Admin::GetAssetGroupAccountsOptions.new
+ options.compliant = true
+ results, _status, headers = asset_group_api.get_asset_group_accounts_with_http_info(args[:organization_id], options)
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+ #ds-snippet-end:Admin12Step3
+
+ results
+ end
+end
diff --git a/app/services/admin_api/eg013_create_account_service.rb b/app/services/admin_api/eg013_create_account_service.rb
new file mode 100644
index 0000000..5439555
--- /dev/null
+++ b/app/services/admin_api/eg013_create_account_service.rb
@@ -0,0 +1,81 @@
+# frozen_string_literal: true
+
+class AdminApi::Eg013CreateAccountService
+ attr_reader :args
+
+ def initialize(args)
+ @args = args
+ end
+
+ def worker
+ #ds-snippet-start:Admin13Step2
+ configuration = DocuSign_Admin::Configuration.new
+ configuration.host = Rails.configuration.admin_host
+
+ api_client = DocuSign_Admin::ApiClient.new(configuration)
+ api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
+ #ds-snippet-end:Admin13Step2
+
+ #ds-snippet-start:Admin13Step4
+ target_account_admin = DocuSign_Admin::SubAccountCreateRequestSubAccountCreationTargetAccountAdmin.new
+ target_account_admin.first_name = args[:first_name]
+ target_account_admin.last_name = args[:last_name]
+ target_account_admin.email = args[:email]
+ target_account_admin.locale = 'en'
+
+ target_account = DocuSign_Admin::SubAccountCreateRequestSubAccountCreationTargetAccountDetails.new
+ target_account.name = 'CreatedThroughAPI'
+ target_account.admin = target_account_admin
+ target_account.country_code = 'US'
+
+ subscription_details = DocuSign_Admin::SubAccountCreateRequestSubAccountCreationSubscription.new
+ subscription_details.id = args[:subscription_id]
+ subscription_details.plan_id = args[:plan_id]
+ subscription_details.modules = []
+
+ account_data = DocuSign_Admin::SubAccountCreateRequest.new
+ account_data.subscription_details = subscription_details
+ account_data.target_account = target_account
+ #ds-snippet-end:Admin13Step4
+
+ #ds-snippet-start:Admin13Step5
+ asset_group_api = DocuSign_Admin::ProvisionAssetGroupApi.new(api_client)
+ results, _status, headers = asset_group_api.create_asset_group_account_with_http_info(args[:organization_id], account_data)
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+ #ds-snippet-end:Admin13Step5
+
+ results
+ end
+
+ def get_organization_plan_items
+ configuration = DocuSign_Admin::Configuration.new
+ configuration.host = Rails.configuration.admin_host
+
+ api_client = DocuSign_Admin::ApiClient.new(configuration)
+ api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
+
+ #ds-snippet-start:Admin13Step3
+ asset_group_api = DocuSign_Admin::ProvisionAssetGroupApi.new(api_client)
+ results, _status, headers = asset_group_api.get_organization_plan_items_with_http_info(args[:organization_id])
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+ #ds-snippet-end:Admin13Step3
+
+ results
+ end
+end
diff --git a/app/services/admin_api/get_data_service.rb b/app/services/admin_api/get_data_service.rb
new file mode 100644
index 0000000..dd7b326
--- /dev/null
+++ b/app/services/admin_api/get_data_service.rb
@@ -0,0 +1,69 @@
+class AdminApi::GetDataService
+ attr_reader :args
+
+ def initialize(session, _options = {})
+ @args = {
+ account_id: session[:ds_account_id],
+ base_path: session[:ds_base_path],
+ access_token: session[:ds_access_token],
+ organization_id: session[:organization_id]
+ }
+ end
+
+ def get_product_permission_profiles
+ worker
+
+ #ds-snippet-start:Admin2Step3
+ product_permission_profiles_api = DocuSign_Admin::ProductPermissionProfilesApi.new(@api_client)
+ product_permission_profiles = product_permission_profiles_api.get_product_permission_profiles(args[:organization_id], args[:account_id])
+ product_permission_profiles.as_json['product_permission_profiles']
+ #ds-snippet-end:Admin2Step3
+ end
+
+ def get_ds_groups
+ worker
+
+ #ds-snippet-start:Admin2Step4
+ ds_groups_api = DocuSign_Admin::DSGroupsApi.new(@api_client)
+ ds_groups = ds_groups_api.get_ds_groups(args[:organization_id], args[:account_id])
+ ds_groups.as_json['ds_groups']
+ #ds-snippet-end:Admin2Step4
+ end
+
+ def get_organization_id
+ worker
+ accounts_api = DocuSign_Admin::AccountsApi.new(@api_client)
+ accounts_api.get_organizations.organizations[0].as_json['id']
+ end
+
+ def check_import_status(import_id)
+ worker
+ #ds-snippet-start:Admin4Step4
+ bulk_imports_api = DocuSign_Admin::BulkImportsApi.new(@api_client)
+ bulk_imports_api.get_bulk_user_import_request(args[:organization_id], import_id)
+ #ds-snippet-end:Admin4Step4
+ end
+
+ def check_user_exists_by_email(email)
+ worker
+ users_api = DocuSign_Admin::UsersApi.new(@api_client)
+ options = DocuSign_Admin::GetUsersOptions.new
+ options.email = email
+ response = users_api.get_users(args[:organization_id], options)
+
+ return false if response.users.empty? || response.users[0].user_status == 'closed'
+
+ true
+ end
+
+ private
+
+ def worker
+ #ds-snippet-start:AdminRubyStep2
+ configuration = DocuSign_Admin::Configuration.new
+ configuration.host = Rails.configuration.admin_host
+ @api_client = DocuSign_Admin::ApiClient.new(configuration)
+ @api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
+ #ds-snippet-end:AdminRubyStep2
+ end
+end
diff --git a/app/services/api_creator.rb b/app/services/api_creator.rb
index 3cc5b29..16850e2 100644
--- a/app/services/api_creator.rb
+++ b/app/services/api_creator.rb
@@ -1,13 +1,10 @@
# frozen_string_literal: true
module ApiCreator
- def create_initial_api_client(host: nil, debugging: false)
- configuration = DocuSign_eSign::Configuration.new
-
- # https://github.com/docusign/docusign-ruby-client/blob/master/lib/docusign_esign/configuration.rb#L55-L60
+ def create_initial_api_client(host: nil, client_module: DocuSign_eSign, debugging: false)
+ configuration = client_module::Configuration.new
configuration.debugging = debugging
-
- api_client = DocuSign_eSign::ApiClient.new(configuration)
+ api_client = client_module::ApiClient.new(configuration)
api_client.set_oauth_base_path(host)
api_client
end
@@ -22,7 +19,7 @@ def create_account_api(args)
api_client.default_headers['Authorization'] = "Bearer #{args[:access_token]}"
# Construct your request body
- accounts_api = DocuSign_eSign::AccountsApi.new api_client
+ DocuSign_eSign::AccountsApi.new api_client
end
def create_template_api(args)
@@ -30,18 +27,18 @@ def create_template_api(args)
configuration.host = args[:base_path]
api_client = DocuSign_eSign::ApiClient.new configuration
api_client.default_headers['Authorization'] = "Bearer #{args[:access_token]}"
- templates_api = DocuSign_eSign::TemplatesApi.new api_client
+ DocuSign_eSign::TemplatesApi.new api_client
end
def create_envelope_api(args)
# Obtain your OAuth token
- # Step 2 start
+ #ds-snippet-start:eSignRubyStep2
configuration = DocuSign_eSign::Configuration.new
configuration.host = args[:base_path]
api_client = DocuSign_eSign::ApiClient.new configuration
api_client.default_headers['Authorization'] = "Bearer #{args[:access_token]}"
- # Step 2 end
+ #ds-snippet-end:eSignRubyStep2
DocuSign_eSign::EnvelopesApi.new api_client
end
@@ -50,6 +47,14 @@ def create_group_api(args)
configuration.host = args[:base_path]
api_client = DocuSign_eSign::ApiClient.new configuration
api_client.default_headers['Authorization'] = "Bearer #{args[:access_token]}"
- group_api = DocuSign_eSign::GroupsApi.new api_client
+ DocuSign_eSign::GroupsApi.new api_client
+ end
+
+ def create_folders_api(args)
+ configuration = DocuSign_eSign::Configuration.new
+ configuration.host = args[:base_path]
+ api_client = DocuSign_eSign::ApiClient.new configuration
+ api_client.default_headers['Authorization'] = "Bearer #{args[:access_token]}"
+ DocuSign_eSign::FoldersApi.new api_client
end
end
diff --git a/app/services/clickwrap/eg001_create_clickwrap_service.rb b/app/services/clickwrap/eg001_create_clickwrap_service.rb
index d9a116b..794c28b 100644
--- a/app/services/clickwrap/eg001_create_clickwrap_service.rb
+++ b/app/services/clickwrap/eg001_create_clickwrap_service.rb
@@ -3,24 +3,22 @@
class Clickwrap::Eg001CreateClickwrapService
attr_reader :args
- def initialize(session, request)
- @args = {
- account_id: session[:ds_account_id],
- base_path: session[:ds_base_path],
- access_token: session[:ds_access_token],
- clickwrap_name: request[:clickwrapName]
- }
+ def initialize(args)
+ @args = args
end
- def call
+ def worker
# Step 2. Construct your API headers
+ #ds-snippet-start:Click1Step2
configuration = DocuSign_Click::Configuration.new
configuration.host = args[:base_path]
api_client = DocuSign_Click::ApiClient.new configuration
api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
+ #ds-snippet-end:Click1Step2
# Step 3. Construct the request body
+ #ds-snippet-start:Click1Step3
# Create the display settings
display_settings = DocuSign_Click::DisplaySettings.new(
consentButtonText: 'I Agree',
@@ -29,7 +27,6 @@ def call
format: 'modal',
hasAccept: true,
mustRead: true,
- mustView: true,
requireAccept: true,
size: 'medium',
documentDisplay: 'document'
@@ -37,8 +34,7 @@ def call
# Read file from a local directory
# The reads could raise an exception if the file is not available!
- doc_pdf = Rails.configuration.doc_terms_pdf
- doc_b64 = Base64.encode64(File.binread(File.join('data', doc_pdf)))
+ doc_b64 = Base64.encode64(File.binread(args[:doc_pdf]))
# Create the document model.
documents = [
@@ -57,9 +53,23 @@ def call
name: args[:clickwrap_name],
requireReacceptance: true
)
+ #ds-snippet-end:Click1Step3
# Step 4. Call the Click API
+ #ds-snippet-start:Click1Step4
account_api = DocuSign_Click::AccountsApi.new(api_client)
- account_api.create_clickwrap(args[:account_id], clickwrap_request)
+ results, _status, headers = account_api.create_clickwrap_with_http_info(args[:account_id], clickwrap_request)
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+ #ds-snippet-end:Click1Step4
+
+ results
end
end
diff --git a/app/services/clickwrap/eg002_activate_clickwrap_service.rb b/app/services/clickwrap/eg002_activate_clickwrap_service.rb
index 954c8e7..ba8908e 100644
--- a/app/services/clickwrap/eg002_activate_clickwrap_service.rb
+++ b/app/services/clickwrap/eg002_activate_clickwrap_service.rb
@@ -3,34 +3,79 @@
class Clickwrap::Eg002ActivateClickwrapService
attr_reader :args
- def initialize(session)
- @args = {
- account_id: session[:ds_account_id],
- base_path: session[:ds_base_path],
- access_token: session[:ds_access_token],
- clickwrap_id: session[:clickwrap_id]
- }
+ def initialize(args)
+ @args = args
end
- def call
+ def worker
# Step 2. Construct your API headers
+ #ds-snippet-start:Click2Step2
configuration = DocuSign_Click::Configuration.new
configuration.host = args[:base_path]
api_client = DocuSign_Click::ApiClient.new configuration
api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
+ #ds-snippet-end:Click2Step2
# Step 3. Construct the request body
# Create a clickwrap request model
+ #ds-snippet-start:Click2Step3
clickwrap_request = DocuSign_Click::ClickwrapRequest.new(status: 'active')
+ #ds-snippet-end:Click2Step3
# Step 4. Call the Click API
+ #ds-snippet-start:Click2Step4
accounts_api = DocuSign_Click::AccountsApi.new(api_client)
- response = accounts_api.update_clickwrap_version(
+ results, _status, headers = accounts_api.update_clickwrap_version_with_http_info(
args[:account_id],
args[:clickwrap_id],
1,
clickwrap_request
)
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+ #ds-snippet-end:Click2Step4
+
+ results
+ end
+
+ def get_inactive_clickwraps(statuses)
+ configuration = DocuSign_Click::Configuration.new
+ configuration.host = args[:ds_base_path]
+
+ api_client = DocuSign_Click::ApiClient.new configuration
+ api_client.set_default_header('Authorization', "Bearer #{args[:ds_access_token]}")
+
+ accounts_api = DocuSign_Click::AccountsApi.new(api_client)
+
+ clickwraps = []
+ statuses.each do |status|
+ options = DocuSign_Click::GetClickwrapsOptions.new
+ options.status = status
+ results, _status, headers = accounts_api.get_clickwraps_with_http_info(
+ args[:ds_account_id],
+ options
+ )
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+
+ clickwraps.concat results.clickwraps
+ end
+
+ clickwraps
end
end
diff --git a/app/services/clickwrap/eg003_create_new_clickwrap_version_service.rb b/app/services/clickwrap/eg003_create_new_clickwrap_version_service.rb
index 7ea4540..d30498f 100644
--- a/app/services/clickwrap/eg003_create_new_clickwrap_version_service.rb
+++ b/app/services/clickwrap/eg003_create_new_clickwrap_version_service.rb
@@ -1,35 +1,31 @@
# frozen_string_literal: true
class Clickwrap::Eg003CreateNewClickwrapVersionService
- attr :args
+ attr_reader :args
- def initialize(session)
- @args = {
- account_id: session[:ds_account_id],
- base_path: session[:ds_base_path],
- access_token: session[:ds_access_token],
- clickwrap_id: session[:clickwrap_id],
- clickwrap_name: session[:clickwrap_name]
- }
+ def initialize(args)
+ @args = args
end
- def call
+ def worker
# Step 2. Construct your API headers
+ #ds-snippet-start:Click3Step2
configuration = DocuSign_Click::Configuration.new
configuration.host = args[:base_path]
api_client = DocuSign_Click::ApiClient.new configuration
api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
+ #ds-snippet-end:Click3Step2
# Step 3. Construct the request body
# Create a display settings model
+ #ds-snippet-start:Click3Step3
display_settings = DocuSign_Click::DisplaySettings.new(
consentButtonText: 'I Agree',
displayName: "#{args[:clickwrap_name]} v2",
downloadable: false,
format: 'modal',
mustRead: true,
- mustView: false,
requireAccept: false,
documentDisplay: 'document',
sendToEmail: false
@@ -56,13 +52,27 @@ def call
requireReacceptance: true,
status: 'active'
)
+ #ds-snippet-end:Click3Step3
# Step 4. Call the Click API
+ #ds-snippet-start:Click3Step4
accounts_api = DocuSign_Click::AccountsApi.new(api_client)
- accounts_api.create_clickwrap_version(
+ results, _status, headers = accounts_api.create_clickwrap_version_with_http_info(
args[:account_id],
args[:clickwrap_id],
clickwrap_request
)
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+ #ds-snippet-end:Click4Step4
+
+ results
end
end
diff --git a/app/services/clickwrap/eg004_list_clickwraps_service.rb b/app/services/clickwrap/eg004_list_clickwraps_service.rb
index c66d8a5..b833054 100644
--- a/app/services/clickwrap/eg004_list_clickwraps_service.rb
+++ b/app/services/clickwrap/eg004_list_clickwraps_service.rb
@@ -3,26 +3,37 @@
class Clickwrap::Eg004ListClickwrapsService
attr_reader :args
- def initialize(session, _request)
- @args = {
- account_id: session[:ds_account_id],
- base_path: session[:ds_base_path],
- access_token: session[:ds_access_token]
- }
+ def initialize(args)
+ @args = args
end
- def call
+ def worker
# Step 2. Construct your API headers
+ #ds-snippet-start:Click4Step2
configuration = DocuSign_Click::Configuration.new
configuration.host = args[:base_path]
api_client = DocuSign_Click::ApiClient.new configuration
api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
+ #ds-snippet-end:Click4Step2
# Step 3. Call the Click API
+ #ds-snippet-start:Click4Step3
accounts_api = DocuSign_Click::AccountsApi.new(api_client)
- accounts_api.get_clickwraps(
+ results, _status, headers = accounts_api.get_clickwraps_with_http_info(
args[:account_id]
)
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+ #ds-snippet-end:Click4Step3
+
+ results
end
end
diff --git a/app/services/clickwrap/eg005_clickwrap_responses_service.rb b/app/services/clickwrap/eg005_clickwrap_responses_service.rb
index 079d0ae..6f46aa3 100644
--- a/app/services/clickwrap/eg005_clickwrap_responses_service.rb
+++ b/app/services/clickwrap/eg005_clickwrap_responses_service.rb
@@ -3,25 +3,22 @@
class Clickwrap::Eg005ClickwrapResponsesService
attr_reader :args
- def initialize(session, request)
- @args = {
- account_id: session[:ds_account_id],
- base_path: session[:ds_base_path],
- access_token: session[:ds_access_token],
- clickwrap_id: session[:clickwrap_id],
- client_user_id: request[:client_user_id]
- }
+ def initialize(args)
+ @args = args
end
- def call
+ def worker
# Step 2. Construct your API headers
+ #ds-snippet-start:Click5Step2
configuration = DocuSign_Click::Configuration.new
configuration.host = args[:base_path]
api_client = DocuSign_Click::ApiClient.new configuration
api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
+ #ds-snippet-end:Click5Step2
# Step 3. Call the Click API
+ #ds-snippet-start:Click5Step3
# Set Clickwrap Agreements options
agreements = DocuSign_Click::GetClickwrapAgreementsOptions.new
agreements.client_user_id = args[:client_user_id]
@@ -29,10 +26,22 @@ def call
# Get clickwrap responses using SDK
accounts_api = DocuSign_Click::AccountsApi.new(api_client)
- accounts_api.get_clickwrap_agreements(
+ results, _status, headers = accounts_api.get_clickwrap_agreements_with_http_info(
args[:account_id],
args[:clickwrap_id],
agreements
)
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+ #ds-snippet-end:Click5Step3
+
+ results
end
end
diff --git a/app/services/clickwrap/eg006_embed_clickwrap_service.rb b/app/services/clickwrap/eg006_embed_clickwrap_service.rb
new file mode 100644
index 0000000..2a99f13
--- /dev/null
+++ b/app/services/clickwrap/eg006_embed_clickwrap_service.rb
@@ -0,0 +1,112 @@
+# frozen_string_literal: true
+
+class Clickwrap::Eg006EmbedClickwrapService
+ attr_reader :args
+
+ def initialize(args)
+ @args = args
+ end
+
+ def worker
+ # Step 2. Construct your API headers
+ #ds-snippet-start:Click6Step2
+ configuration = DocuSign_Click::Configuration.new
+ configuration.host = args[:base_path]
+
+ api_client = DocuSign_Click::ApiClient.new configuration
+ api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
+ api_client.config.debugging = true
+ #ds-snippet-end:Click6Step2
+
+ #ds-snippet-start:Click6Step3
+ document_data = {
+ 'fullName' => args[:full_name],
+ 'email' => args[:email],
+ 'company' => args[:company],
+ 'title' => args[:title],
+ 'date' => args[:date]
+ }
+
+ userAgreementRequest = DocuSign_Click::UserAgreementRequest.new({
+ clientUserId: args[:email],
+ documentData: document_data
+ })
+
+ #ds-snippet-end:Click6Step3
+ #ds-snippet-start:Click6Step4
+ accounts_api = DocuSign_Click::AccountsApi.new(api_client)
+
+ response, _status, headers = accounts_api.create_has_agreed_with_http_info(args[:account_id], args[:clickwrap_id], userAgreementRequest)
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+
+ response.as_json
+ #ds-snippet-end:Click6Step4
+ end
+
+ def get_active_clickwraps
+ configuration = DocuSign_Click::Configuration.new
+ configuration.host = args[:ds_base_path]
+
+ api_client = DocuSign_Click::ApiClient.new configuration
+ api_client.set_default_header('Authorization', "Bearer #{args[:ds_access_token]}")
+
+ accounts_api = DocuSign_Click::AccountsApi.new(api_client)
+
+ options = DocuSign_Click::GetClickwrapsOptions.new
+ options.status = 'active'
+
+ results, _status, headers = accounts_api.get_clickwraps_with_http_info(
+ args[:ds_account_id],
+ options
+ )
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+
+ puts results.as_json['clickwraps']
+ results.as_json['clickwraps']
+ end
+
+ def get_inactive_clickwraps
+ configuration = DocuSign_Click::Configuration.new
+ configuration.host = args[:ds_base_path]
+
+ api_client = DocuSign_Click::ApiClient.new configuration
+ api_client.set_default_header('Authorization', "Bearer #{args[:ds_access_token]}")
+
+ accounts_api = DocuSign_Click::AccountsApi.new(api_client)
+
+ options = DocuSign_Click::GetClickwrapsOptions.new
+ options.status = 'inactive'
+
+ results, _status, headers = accounts_api.get_clickwraps_with_http_info(
+ args[:ds_account_id],
+ options
+ )
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+
+ results.as_json['clickwraps']
+ end
+end
diff --git a/app/services/connect/eg001_validate_webhook_message_service.rb b/app/services/connect/eg001_validate_webhook_message_service.rb
new file mode 100644
index 0000000..fbc6688
--- /dev/null
+++ b/app/services/connect/eg001_validate_webhook_message_service.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+require 'openssl'
+require 'base64'
+
+class Connect::Eg001ValidateWebhookMessageService
+ attr_reader :args
+
+ def initialize(args)
+ @args = args
+ end
+
+ #ds-snippet-start:Connect1Step1
+ def worker
+ digest = OpenSSL::Digest.new('sha256')
+ hashBytes = OpenSSL::HMAC.digest(digest, args[:secret], args[:payload])
+ Base64.encode64(hashBytes)
+ end
+
+ def hash_valid?
+ hash = worker(args[:secret], args[:payload])
+ OpenSSL.secure_compare(hash.chomp, args[:signature])
+ end
+ #ds-snippet-end:Connect1Step1
+end
diff --git a/app/services/connected_fields/eg001_set_connected_fields_service.rb b/app/services/connected_fields/eg001_set_connected_fields_service.rb
new file mode 100644
index 0000000..bc22b9a
--- /dev/null
+++ b/app/services/connected_fields/eg001_set_connected_fields_service.rb
@@ -0,0 +1,174 @@
+# frozen_string_literal: true
+
+class ConnectedFields::Eg001SetConnectedFieldsService
+ attr_reader :args
+
+ include ApiCreator
+
+ def initialize(args)
+ @args = args
+ end
+
+ def get_tab_groups
+ #ds-snippet-start:ConnectedFields1Step2
+ headers = {
+ 'Authorization' => "Bearer #{args[:access_token]}",
+ 'Accept' => 'application/json',
+ 'Content-Type' => 'application/json'
+ }
+ #ds-snippet-end:ConnectedFields1Step2
+
+ #ds-snippet-start:ConnectedFields1Step3
+ url = URI("#{args[:extensions_base_path]}/v1/accounts/#{args[:account_id]}/connected-fields/tab-groups")
+ response = Net::HTTP.get_response(url, headers)
+ response_data = JSON.parse(response.body)
+
+ filtered_apps = response_data.select do |app|
+ app['tabs']&.any? do |tab|
+ (tab['extensionData']&.dig('actionContract')&.include? 'Verify') ||
+ (tab['tabLabel']&.include? 'connecteddata')
+ end
+ end
+
+ # return unique apps
+ filtered_apps.uniq { |app| app['appId'] }
+ #ds-snippet-end:ConnectedFields1Step3
+ end
+
+ #ds-snippet-start:ConnectedFields1Step4
+ def extract_verification_data(selected_app_id, tab)
+ extension_data = tab['extensionData']
+
+ {
+ app_id: selected_app_id,
+ extension_group_id: extension_data['extensionGroupId'],
+ publisher_name: extension_data['publisherName'],
+ application_name: extension_data['applicationName'],
+ action_name: extension_data['actionName'],
+ action_input_key: extension_data['actionInputKey'],
+ action_contract: extension_data['actionContract'],
+ extension_name: extension_data['extensionName'],
+ extension_contract: extension_data['extensionContract'],
+ required_for_extension: extension_data['requiredForExtension'],
+ tab_label: tab['tabLabel'],
+ connection_key: extension_data['connectionInstances']&.dig(0, 'connectionKey') || '',
+ connection_value: extension_data['connectionInstances']&.dig(0, 'connectionValue') || ''
+ }
+ end
+ #ds-snippet-end:ConnectedFields1Step4
+
+ def send_envelope(app)
+ # Create the envelope definition
+ #ds-snippet-start:ConnectedFields1Step6
+ envelope = make_envelope args[:envelope_args], app
+
+ # Call Docusign to create the envelope
+ envelope_api = create_envelope_api(args)
+
+ results = envelope_api.create_envelope args[:account_id], envelope
+
+ { 'envelope_id' => results.envelope_id }
+ #ds-snippet-end:ConnectedFields1Step6
+ end
+
+ private
+
+ #ds-snippet-start:ConnectedFields1Step5
+ def make_envelope(envelope_args, app)
+ doc = DocuSign_eSign::Document.new
+ doc.document_base64 = Base64.encode64(File.binread(envelope_args[:doc_pdf]))
+ doc.name = 'Lorem Ipsum'
+ doc.file_extension = 'pdf'
+ doc.document_id = '1'
+
+ # The order in the docs array determines the order in the envelope
+ # Create a signer recipient to sign the document, identified by name and email
+ # We're setting the parameters via the object creation
+ signer = DocuSign_eSign::Signer.new
+ signer.email = envelope_args[:signer_email]
+ signer.name = envelope_args[:signer_name]
+ signer.recipient_id = 1
+
+ # The Docusign platform searches throughout your envelope's documents for matching
+ # anchor strings. So the sign_here_2 tab will be used in both document 2 and 3
+ # since they use the same anchor string for their "signer 1" tabs.
+ sign_here = DocuSign_eSign::SignHere.new
+ sign_here.anchor_string = '/sn1/'
+ sign_here.anchor_units = 'pixels'
+ sign_here.anchor_x_offset = '20'
+ sign_here.anchor_y_offset = '10'
+
+ text_tabs = []
+ app['tabs'].each do |tab|
+ next if tab['tabLabel'].include?('SuggestionInput')
+
+ verification_data = extract_verification_data(app['appId'], tab)
+ text_tabs.push(text_tab(verification_data, text_tabs.length))
+ end
+
+ tabs = DocuSign_eSign::Tabs.new
+ tabs.sign_here_tabs = [sign_here]
+ tabs.text_tabs = text_tabs
+ signer.tabs = tabs
+
+ recipients = DocuSign_eSign::Recipients.new
+ recipients.signers = [signer]
+
+ envelope_definition = DocuSign_eSign::EnvelopeDefinition.new
+ envelope_definition.email_subject = 'Please sign this document'
+ envelope_definition.documents = [doc]
+ envelope_definition.recipients = recipients
+ envelope_definition.status = 'sent'
+ envelope_definition
+ end
+
+ def extension_data(verification_data)
+ {
+ extensionGroupId: verification_data[:extension_group_id],
+ publisherName: verification_data[:publisher_name],
+ applicationId: verification_data[:app_id],
+ applicationName: verification_data[:application_name],
+ actionName: verification_data[:action_name],
+ actionContract: verification_data[:action_contract],
+ extensionName: verification_data[:extension_name],
+ extensionContract: verification_data[:extension_contract],
+ requiredForExtension: verification_data[:required_for_extension],
+ actionInputKey: verification_data[:action_input_key],
+ extensionPolicy: 'MustVerifyToSign',
+ connectionInstances: [
+ {
+ connectionKey: verification_data[:connection_key],
+ connectionValue: verification_data[:connection_value]
+ }
+ ]
+ }
+ end
+
+ def text_tab(verification_data, text_tabs_count)
+ {
+ requireInitialOnSharedChange: false,
+ requireAll: false,
+ name: verification_data[:application_name],
+ required: true,
+ locked: false,
+ disableAutoSize: false,
+ maxLength: 4000,
+ tabLabel: verification_data[:tab_label],
+ font: 'lucidaconsole',
+ fontColor: 'black',
+ fontSize: 'size9',
+ documentId: '1',
+ recipientId: '1',
+ pageNumber: '1',
+ xPosition: (70 + 100 * (text_tabs_count / 10)).to_s,
+ yPosition: (560 + 20 * (text_tabs_count % 10)).to_s,
+ width: '84',
+ height: '22',
+ templateRequired: false,
+ tabType: 'text',
+ tooltip: verification_data[:action_input_key],
+ extensionData: extension_data(verification_data)
+ }
+ end
+ #ds-snippet-end:ConnectedFields1Step5
+end
diff --git a/app/services/e_sign/eg002_signing_via_email_service.rb b/app/services/e_sign/eg002_signing_via_email_service.rb
index 2e5f827..8c7f447 100644
--- a/app/services/e_sign/eg002_signing_via_email_service.rb
+++ b/app/services/e_sign/eg002_signing_via_email_service.rb
@@ -1,44 +1,42 @@
# frozen_string_literal: true
class ESign::Eg002SigningViaEmailService
+ attr_reader :args
+
include ApiCreator
- attr_reader :args, :envelope_args
-
- def initialize(session, request, status)
- @envelope_args = {
- signer_email: request.params['signerEmail'].gsub(/([^\w \-\@\.\,])+/, ''),
- signer_name: request.params['signerName'].gsub(/([^\w \-\@\.\,])+/, ''),
- cc_email: request.params['ccEmail'].gsub(/([^\w \-\@\.\,])+/, ''),
- cc_name: request.params['ccName'].gsub(/([^\w \-\@\.\,])+/, ''),
- status: status
- }
- @args = {
- account_id: session['ds_account_id'],
- base_path: session['ds_base_path'],
- access_token: session['ds_access_token'],
- envelope_args: @envelope_args
- }
- end
- def call
- worker
+ def initialize(args)
+ @args = args
end
- private
-
+ #ds-snippet-start:eSign2Step3
def worker
- # 1. Create the envelope request object
- envelope_definition = make_envelope
- # 2. Call Envelopes::create API method
+ # Create the envelope request object
+ envelope_definition = make_envelope args[:envelope_args]
+ # Call Envelopes::create API method
# Exceptions will be caught by the calling function
envelope_api = create_envelope_api(args)
- results = envelope_api.create_envelope args[:account_id], envelope_definition
+ results, _status, headers = envelope_api.create_envelope_with_http_info args[:account_id], envelope_definition
+
+ remaining = headers['X-RateLimit-Remaining']
+ reset = headers['X-RateLimit-Reset']
+
+ if remaining && reset
+ reset_date = Time.at(reset.to_i).utc
+ puts "API calls remaining: #{remaining}"
+ puts "Next Reset: #{reset_date}"
+ end
+
envelope_id = results.envelope_id
{ 'envelope_id' => envelope_id }
end
+ #ds-snippet-end:eSign2Step3
+
+ private
- def make_envelope
+ #ds-snippet-start:eSign2Step2
+ def make_envelope(envelope_args)
# document 1 (HTML) has tag **signature_1**
# document 2 (DOCX) has tag /sn1/
# document 3 (PDF) has tag /sn1/
@@ -55,31 +53,29 @@ def make_envelope
envelope_definition.email_subject = 'Please sign this document set'
# Add the documents
- doc1_b64 = Base64.encode64(create_document1)
+ doc1_b64 = Base64.encode64(create_document1(envelope_args))
# Read files 2 and 3 from a local directory
# The reads could raise an exception if the file is not available!
- doc_docx = Rails.application.config.doc_docx
- doc2_b64 = Base64.encode64(File.binread(File.join('data', doc_docx)))
- doc_pdf = Rails.application.config.doc_pdf
- doc3_b64 = Base64.encode64(File.binread(File.join('data', doc_pdf)))
+ doc2_b64 = Base64.encode64(File.binread(envelope_args[:doc_docx]))
+ doc3_b64 = Base64.encode64(File.binread(envelope_args[:doc_pdf]))
# Create the document models
document1 = DocuSign_eSign::Document.new(
- # Create the DocuSign document object
+ # Create the Docusign document object
documentBase64: doc1_b64,
name: 'Order acknowledgement', # Can be different from actual file name
fileExtension: 'html', # Many different document types are accepted
documentId: '1' # A label used to reference the doc
)
document2 = DocuSign_eSign::Document.new(
- # Create the DocuSign document object
+ # Create the Docusign document object
documentBase64: doc2_b64,
name: 'Battle Plan', # Can be different from actual file name
fileExtension: 'docx', # Many different document types are accepted
documentId: '2' # A label used to reference the do
)
document3 = DocuSign_eSign::Document.new(
- # Create the DocuSign document object
+ # Create the Docusign document object
documentBase64: doc3_b64,
name: 'Lorem Ipsum', # Can be different from actual file name
fileExtension: 'pdf', # Many different document types are accepted
@@ -109,7 +105,7 @@ def make_envelope
# Create signHere fields (also known as tabs) on the documents
# We're using anchor (autoPlace) positioning
#
- # The DocuSign platform searches throughout your envelope's documents for matching
+ # The Docusign platform searches throughout your envelope's documents for matching
# anchor strings. So the sign_here_2 tab will be used in both document 2 and 3
# since they use the same anchor string for their "signer 1" tabs.
sign_here1 = DocuSign_eSign::SignHere.new(
@@ -127,9 +123,9 @@ def make_envelope
)
# 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, sign_here2]
- })
+ signer1_tabs = DocuSign_eSign::Tabs.new({
+ signHereTabs: [sign_here1, sign_here2]
+ })
signer1.tabs = signer1_tabs
@@ -145,7 +141,7 @@ def make_envelope
envelope_definition
end
- def create_document1
+ def create_document1(args)
"
@@ -169,4 +165,5 @@ def create_document1