echochamber 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +3 -0
  5. data/Gemfile.lock +79 -0
  6. data/LICENSE +21 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +87 -0
  9. data/Rakefile +12 -0
  10. data/doc/Echochamber.html +131 -0
  11. data/doc/Echochamber/Agreement.html +529 -0
  12. data/doc/Echochamber/Agreement/UrlFileInfo.html +263 -0
  13. data/doc/Echochamber/Client.html +4161 -0
  14. data/doc/Echochamber/CounterSignerInfo.html +265 -0
  15. data/doc/Echochamber/Credentials.html +330 -0
  16. data/doc/Echochamber/Credentials/CredentialsError.html +123 -0
  17. data/doc/Echochamber/Fileinfo.html +303 -0
  18. data/doc/Echochamber/InvalidParameterError.html +123 -0
  19. data/doc/Echochamber/ParameterError.html +123 -0
  20. data/doc/Echochamber/PhoneInfo.html +279 -0
  21. data/doc/Echochamber/Recipient.html +309 -0
  22. data/doc/Echochamber/RecipientSecurityOption.html +294 -0
  23. data/doc/Echochamber/Reminder.html +277 -0
  24. data/doc/Echochamber/Request.html +4167 -0
  25. data/doc/Echochamber/Request/Failure.html +123 -0
  26. data/doc/Echochamber/RequiredParameterError.html +123 -0
  27. data/doc/Echochamber/UrlFileInfo.html +295 -0
  28. data/doc/Echochamber/User.html +420 -0
  29. data/doc/Echochamber/Validatable.html +355 -0
  30. data/doc/Echochamber/Validator.html +180 -0
  31. data/doc/Echochamber/Widget.html +654 -0
  32. data/doc/Echochamber/WidgetCompletionInfo.html +309 -0
  33. data/doc/Echochamber/WidgetPersonalization.html +326 -0
  34. data/doc/Echochamber/WidgetSecurityOption.html +359 -0
  35. data/doc/Echochamber/WidgetSignerSecurityOption.html +296 -0
  36. data/doc/Echochamber/WidgetStatus.html +314 -0
  37. data/doc/Echochamber/WidgetVaultingInfo.html +265 -0
  38. data/doc/_index.html +338 -0
  39. data/doc/class_list.html +54 -0
  40. data/doc/css/common.css +1 -0
  41. data/doc/css/full_list.css +57 -0
  42. data/doc/css/style.css +339 -0
  43. data/doc/file.README.html +157 -0
  44. data/doc/file_list.html +56 -0
  45. data/doc/frames.html +26 -0
  46. data/doc/index.html +157 -0
  47. data/doc/js/app.js +219 -0
  48. data/doc/js/full_list.js +178 -0
  49. data/doc/js/jquery.js +4 -0
  50. data/doc/method_list.html +581 -0
  51. data/doc/top-level-namespace.html +112 -0
  52. data/echochamber.gemspec +35 -0
  53. data/features/support/env.rb +8 -0
  54. data/fixtures/agreement.pdf +0 -0
  55. data/fixtures/vcr_cassettes/agreement_combined_pdf.yml +1465 -0
  56. data/fixtures/vcr_cassettes/agreement_document_file.yml +1465 -0
  57. data/fixtures/vcr_cassettes/agreement_documents.yml +42 -0
  58. data/fixtures/vcr_cassettes/agreement_form_data.yml +44 -0
  59. data/fixtures/vcr_cassettes/agreement_info.yml +50 -0
  60. data/fixtures/vcr_cassettes/agreement_signing_urls.yml +42 -0
  61. data/fixtures/vcr_cassettes/audit_trail_pdf.yml +1643 -0
  62. data/fixtures/vcr_cassettes/cancel_agreement.yml +46 -0
  63. data/fixtures/vcr_cassettes/create_agreement.yml +50 -0
  64. data/fixtures/vcr_cassettes/create_reminder.yml +47 -0
  65. data/fixtures/vcr_cassettes/create_transient_document.yml +716 -0
  66. data/fixtures/vcr_cassettes/create_user.yml +50 -0
  67. data/fixtures/vcr_cassettes/create_widget.yml +48 -0
  68. data/fixtures/vcr_cassettes/get_agreements.yml +46 -0
  69. data/fixtures/vcr_cassettes/get_library_document.yml +45 -0
  70. data/fixtures/vcr_cassettes/get_library_document_data.yml +1191 -0
  71. data/fixtures/vcr_cassettes/get_library_document_file.yml +42 -0
  72. data/fixtures/vcr_cassettes/get_library_documents.yml +47 -0
  73. data/fixtures/vcr_cassettes/get_token.yml +44 -0
  74. data/fixtures/vcr_cassettes/get_user.yml +46 -0
  75. data/fixtures/vcr_cassettes/get_users.yml +43 -0
  76. data/fixtures/vcr_cassettes/get_widget.yml +49 -0
  77. data/fixtures/vcr_cassettes/get_widget_document_file.yml +2682 -0
  78. data/fixtures/vcr_cassettes/get_widget_documents.yml +44 -0
  79. data/fixtures/vcr_cassettes/get_widgets.yml +50 -0
  80. data/fixtures/vcr_cassettes/library_combined_document.yml +2197 -0
  81. data/fixtures/vcr_cassettes/library_document_audit_trail.yml +1570 -0
  82. data/fixtures/vcr_cassettes/personalize_widget.yml +47 -0
  83. data/fixtures/vcr_cassettes/update_widget_status.yml +46 -0
  84. data/lib/echochamber.rb +10 -0
  85. data/lib/echochamber/agreement.rb +32 -0
  86. data/lib/echochamber/agreement/client.rb +118 -0
  87. data/lib/echochamber/agreement/fileinfo.rb +20 -0
  88. data/lib/echochamber/agreement/phone_info.rb +19 -0
  89. data/lib/echochamber/agreement/recipient.rb +23 -0
  90. data/lib/echochamber/agreement/recipient_security_option.rb +20 -0
  91. data/lib/echochamber/agreement/request.rb +142 -0
  92. data/lib/echochamber/agreement/url_file_info.rb +18 -0
  93. data/lib/echochamber/client.rb +82 -0
  94. data/lib/echochamber/credentials.rb +33 -0
  95. data/lib/echochamber/library_documents/client.rb +83 -0
  96. data/lib/echochamber/library_documents/request.rb +78 -0
  97. data/lib/echochamber/reminder.rb +17 -0
  98. data/lib/echochamber/request.rb +141 -0
  99. data/lib/echochamber/user.rb +29 -0
  100. data/lib/echochamber/validatable.rb +54 -0
  101. data/lib/echochamber/version.rb +3 -0
  102. data/lib/echochamber/widget.rb +42 -0
  103. data/lib/echochamber/widget/client.rb +127 -0
  104. data/lib/echochamber/widget/counter_signer_info.rb +19 -0
  105. data/lib/echochamber/widget/request.rb +135 -0
  106. data/lib/echochamber/widget/widget_completion_info.rb +19 -0
  107. data/lib/echochamber/widget/widget_personalization.rb +21 -0
  108. data/lib/echochamber/widget/widget_security_option.rb +22 -0
  109. data/lib/echochamber/widget/widget_signer_security_option.rb +18 -0
  110. data/lib/echochamber/widget/widget_status.rb +20 -0
  111. data/lib/echochamber/widget/widget_vaulting_info.rb +16 -0
  112. data/spec/lib/agreement/client_spec.rb +157 -0
  113. data/spec/lib/client_spec.rb +78 -0
  114. data/spec/lib/library_documents/client_spec.rb +71 -0
  115. data/spec/lib/request_spec.rb +18 -0
  116. data/spec/lib/shared_client.rb +22 -0
  117. data/spec/lib/user_spec.rb +6 -0
  118. data/spec/lib/validatable_spec.rb +110 -0
  119. data/spec/lib/version_spec.rb +7 -0
  120. data/spec/lib/widget/client_spec.rb +154 -0
  121. data/spec/spec_helper.rb +21 -0
  122. metadata +344 -0
@@ -0,0 +1,47 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: put
5
+ uri: https://secure.echosign.com/api/rest/v2/widgets/2AAABLblqZhD_6RpgbZh5ZVlLXz1H1kfVzw4vHB91MtmjNHBDorFqO0H3_cGzBudZxiWNzPXFzOc*/personalize
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"email":"cthomas@railjumper.com"}'
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Type:
15
+ - application/json
16
+ Access-Token:
17
+ - 2AAABLblqZhC3HrDExRuNnTr9I-U3z2f2KtGloHKah3ccogCP4HzbN5XSbcKSlxNJDtNCVAq94pM*
18
+ Content-Length:
19
+ - '34'
20
+ User-Agent:
21
+ - Ruby
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ headers:
27
+ Date:
28
+ - Thu, 21 Aug 2014 04:23:18 GMT
29
+ Server:
30
+ - Apache
31
+ Content-Length:
32
+ - '382'
33
+ Strict-Transport-Security:
34
+ - max-age=31536000;
35
+ P3p:
36
+ - CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
37
+ X-Robots-Tag:
38
+ - none
39
+ Content-Type:
40
+ - application/json;charset=UTF-8
41
+ body:
42
+ encoding: UTF-8
43
+ string: '{"javascript":"<script type=''text/javascript'' language=''JavaScript''
44
+ src=''https://secure.echosign.com/public/hostedForm?formid=9V5BHC4L3A394E&token=39QF96QTRUGYCPYUYQI0G4ZK''></script>","url":"https://secure.echosign.com/public/hostedForm?formid=9V5BHC4L3A394E&token=39QF96QTRUGYCPYUYQI0G4ZK","widgetId":"2AAABLblqZhD_6RpgbZh5ZVlLXz1H1kfVzw4vHB91MtmjNHBDorFqO0H3_cGzBudZxiWNzPXFzOc*"}'
45
+ http_version:
46
+ recorded_at: Thu, 21 Aug 2014 04:23:18 GMT
47
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: put
5
+ uri: https://secure.echosign.com/api/rest/v2/widgets/2AAABLblqZhD_6RpgbZh5ZVlLXz1H1kfVzw4vHB91MtmjNHBDorFqO0H3_cGzBudZxiWNzPXFzOc*/status
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"value":"DISABLE","message":"Hey guys, hope you like this widget."}'
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Type:
15
+ - application/json
16
+ Access-Token:
17
+ - 2AAABLblqZhC3HrDExRuNnTr9I-U3z2f2KtGloHKah3ccogCP4HzbN5XSbcKSlxNJDtNCVAq94pM*
18
+ Content-Length:
19
+ - '68'
20
+ User-Agent:
21
+ - Ruby
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ headers:
27
+ Date:
28
+ - Thu, 21 Aug 2014 05:04:32 GMT
29
+ Server:
30
+ - Apache
31
+ Content-Length:
32
+ - '62'
33
+ Strict-Transport-Security:
34
+ - max-age=31536000;
35
+ P3p:
36
+ - CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
37
+ X-Robots-Tag:
38
+ - none
39
+ Content-Type:
40
+ - application/json;charset=UTF-8
41
+ body:
42
+ encoding: UTF-8
43
+ string: '{"code":"OK","message":"The operation completed successfully"}'
44
+ http_version:
45
+ recorded_at: Thu, 21 Aug 2014 05:04:32 GMT
46
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,10 @@
1
+ require 'json'
2
+ require "echochamber/version"
3
+ require 'echochamber/client'
4
+ require 'echochamber/validatable'
5
+ require 'echochamber/credentials'
6
+ require 'echochamber/request'
7
+ require 'echochamber/agreement'
8
+ require 'echochamber/user'
9
+ require 'echochamber/reminder'
10
+ require 'echochamber/widget'
@@ -0,0 +1,32 @@
1
+ require 'echochamber/agreement/fileinfo'
2
+ require 'echochamber/agreement/url_file_info'
3
+ require 'echochamber/agreement/recipient'
4
+
5
+ module Echochamber
6
+ class Agreement < Hash
7
+
8
+ include Validatable
9
+
10
+ attr_accessor :user_id, :user_email
11
+
12
+ # Creates an agreement object for submission
13
+ #
14
+ # @param [String] user_id ID of the user whom this agreement is made for
15
+ # @param [String] user_email Email of the user whom this agreement is made for
16
+ # @param [Hash] params SYMBOL-referenced Hash containing:
17
+ # @option params [Array] :fileInfos A list of one or more files (or references to files) that will be sent out for signature. If more than one file is provided, they will be combined into one PDF before being sent out. Note: Only one of the four parameters in every FileInfo object must be specified. Populate the array with instances of {Echochamber::Fileinfo Echochamber::Fileinfo} (REQUIRED)
18
+ # @option params [Array] :recipients A list of one or more recipients. For regular (non-MegaSign) documents, there is no limit on the number of electronic signatures in a single document. Written signatures are limited to four per document. This limit includes the sender if the sender's signature is also required. Populate the array with instances of {Echochamber::Recipient Echochamber::Recipient} (REQUIRED)
19
+ # @option params [String] :signatureFlow ['SENDER_SIGNATURE_NOT_REQUIRED' or 'SENDER_SIGNS_LAST' or 'SENDER_SIGNS_FIRST' or 'SEQUENTIAL' or 'PARALLEL']: Selects the workflow you would like to use - whether the sender needs to sign before the recipient, after the recipient, or not at all. The possible values for this variable are SENDER_SIGNATURE_NOT_REQUIRED, SENDER_SIGNS_LAST, SENDER_SIGNS_FIRST, SEQUENTIAL or PARALLEL. (REQUIRED)
20
+ # @option params [String] :signatureType ['ESIGN' or 'WRITTEN']: Specifies the type of signature you would like to request - written or eSignature. The possible values are ESIGN or WRITTEN (REQUIRED)
21
+ # @option params [String] :name The name of the agreement that will be used to identify it, in emails and on the website. (REQUIRED)
22
+ # @return [Echochamber::Agreement]
23
+ def initialize(user_id=nil, user_email=nil, params)
24
+ @user_id = user_id
25
+ @user_email = user_email
26
+ #TODO (cthomas) barf if user_id or user_email are blank
27
+ require_keys([:signatureType, :recipients, :signatureFlow, :fileInfos, :name], params)
28
+ merge!({ documentCreationInfo: params })
29
+ end
30
+
31
+ end # class Agreement
32
+ end # module Echochamber
@@ -0,0 +1,118 @@
1
+ module Echochamber
2
+
3
+ class Client
4
+
5
+ # Creates an agreement
6
+ #
7
+ # @param agreement [Echochamber::Agreement]
8
+ # @return [String] Agreement ID
9
+ def create_agreement(agreement)
10
+ agreement_response = Echochamber::Request.create_agreement(agreement, token, agreement.user_id, agreement.user_email)
11
+ agreement_response.fetch("agreementId")
12
+ end
13
+
14
+ # Gets list of agreements
15
+ #
16
+ # @param agreement [Echochamber::Agreement]
17
+ # @return [String] Agreement ID
18
+ def get_agreements
19
+ get_agreements_response = Echochamber::Request.get_agreements(token)
20
+ get_agreements_response.fetch("userAgreementList")
21
+ end
22
+
23
+ # Gets detailed info on an agreement
24
+ #
25
+ # @param agreement_id [String] ID of agreement to retrieve info on.
26
+ # @return [Hash] Detailed agreement info
27
+ def agreement_info(agreement_id)
28
+ Echochamber::Request.agreement_info(token, agreement_id)
29
+ end
30
+
31
+ # Cancel agreement
32
+ #
33
+ # @param agreement_id [String] (REQUIRED)
34
+ # @param notify_signer [Boolean] Whether to notify the signer by email of the cancellation. Default is false.
35
+ # @param comment [String] Comment regarding this cancellation.
36
+ # @return [String] Result of the operation
37
+ def cancel_agreement(agreement_id, notify_signer=false, comment=nil)
38
+ request_body = {
39
+ "value" => "CANCEL",
40
+ "notifySigner" => notify_signer
41
+ }
42
+ request_body.merge!(comment: comment) unless comment.nil?
43
+
44
+ agreement_status_response = Echochamber::Request.update_agreement_status(token, agreement_id, request_body)
45
+ agreement_status_response.fetch('result')
46
+ end
47
+
48
+ # All documents relating to an agreement
49
+ #
50
+ # @param agreement_id [String] (REQUIRED)
51
+ # @param recipient_email [String] The email address of the participant to be used to retrieve documents. (REQUIRED)
52
+ # @param format [String] Content format of the supported documents. It can have two possible values ORIGINAL or CONVERTED_PDF. (REQUIRED)
53
+ # @param version_id [String] Version of the agreement as provided by agreement_info(). If not provided, the latest version of the agreement is used.
54
+ # @return [Array] Documents relating to agreement.
55
+ def agreement_documents(agreement_id, recipient_email, format, version_id=nil)
56
+ result = Echochamber::Request.agreement_documents(token, agreement_id, recipient_email, format, version_id)
57
+ end
58
+
59
+ # Retrieve a document file from an agreement
60
+ #
61
+ # @param agreement_id [String] (REQUIRED)
62
+ # @param document_id [String] (REQUIRED)
63
+ # @param file_path [String] File path to save the document. If no file path is given, nothing is saved to disk.
64
+ # @return [String] Raw bytes from document file
65
+ def agreement_document_file(agreement_id, document_id, file_path=nil)
66
+ response = Echochamber::Request.agreement_document_file(token, agreement_id, document_id)
67
+ unless file_path.nil?
68
+ file = File.new(file_path, 'wb')
69
+ file.write(response)
70
+ file.close
71
+ end
72
+ response
73
+ end
74
+
75
+ # Retrieves the URL for the eSign page for the current signer(s) of an agreement
76
+ #
77
+ # @param agreement_id [String] (REQUIRED)
78
+ # @return [Hash] URL information for the eSign page of the agreement
79
+ def agreement_signing_urls(agreement_id)
80
+ response = Echochamber::Request.agreement_signing_urls(token, agreement_id)
81
+ end
82
+
83
+ # Gets a single combined PDF document for the documents associated with an agreement.
84
+ #
85
+ # @param agreement_id [String] (REQUIRED)
86
+ # @param file_path [String] File path to save the document. If no file path is given, nothing is saved to disk.
87
+ # @param versionId [String] The version identifier of agreement as provided by get_agreement. If not provided then latest version will be used
88
+ # @param participantEmail [String] The email address of the participant to be used to retrieve documents. If none is given, the auth token will be used to determine the user
89
+ # @param attachSupportingDocuments [Boolean] When set to YES, attach corresponding supporting documents to the signed agreement PDF. Default value of this parameter is true.
90
+ # @param auditReport [Boolean] When set to YES, attach an audit report to the signed agreement PDF. Default value is false
91
+ # @return [String] Raw bytes from document file
92
+ def agreement_combined_pdf(agreement_id, file_path=nil, versionId=nil, participantEmail=nil, attachSupportingDocuments=true, auditReport=false)
93
+ response = Echochamber::Request.agreement_combined_pdf(token, agreement_id, versionId, participantEmail, attachSupportingDocuments, auditReport)
94
+ unless file_path.nil?
95
+ file = File.new(file_path, 'wb')
96
+ file.write(response)
97
+ file.close
98
+ end
99
+ response
100
+ end
101
+
102
+ # Retrieves library document audit trail file
103
+ #
104
+ # @param agreement_id [String] (REQUIRED)
105
+ # @param file_path [String] File path where to save the CSV file. If no file path is given, nothing is saved to disk.
106
+ # @return [String] Raw bytes representing CSV file
107
+ def agreement_form_data(agreement_id, file_path=nil)
108
+ response = Echochamber::Request.agreement_form_data(token, agreement_id)
109
+ unless file_path.nil?
110
+ file = File.new(file_path, 'wb')
111
+ file.write(response)
112
+ file.close
113
+ end
114
+ response
115
+ end
116
+
117
+ end
118
+ end
@@ -0,0 +1,20 @@
1
+ module Echochamber
2
+ class Fileinfo < Hash
3
+
4
+ include Validatable
5
+
6
+ # Validates Fileinfo params
7
+ #
8
+ # @param [Hash] params SYMBOL-referenced Hash containing exactly one of the following:
9
+ # @option params [String] :transientDocumentId A transient document ID available to the sender
10
+ # @option params [String] :libraryDocumentId A library document ID available to the sender
11
+ # @option params [String] :libraryDocumentName A library document name available to the sender
12
+ # @option params [Echochamber::UrlFileInfo] :documentURL A description of the URL where the document can be found
13
+ # @return [Echochamber::Fileinfo]
14
+ def initialize(params)
15
+ require_exactly_one([:transientDocumentId, :libraryDocumentId, :libraryDocumentName, :documentURL], params)
16
+ merge!(params)
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,19 @@
1
+ module Echochamber
2
+ class PhoneInfo < Hash
3
+
4
+ include Validatable
5
+
6
+ # PhoneInfo
7
+ #
8
+ # @param [Hash] params SYMBOL-referenced Hash.
9
+ # @option params [String] :phone The phone number required for the recipient to view and sign the document (REQUIRED)
10
+ # @option params [String] :countryCode The phoneInfo country code required for the recipient to view and sign the document if authentication type is PHONE
11
+ # @return [Echochamber::PhoneInfo]
12
+
13
+ def initialize(params)
14
+ require_keys([:phone], params)
15
+ merge!(params)
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ module Echochamber
2
+ class Recipient < Hash
3
+
4
+ include Validatable
5
+
6
+ # Creates an Echochamber::Recipient object
7
+ #
8
+ # @param [Hash] params SYMBOL-referenced Hash. Role, and either fax or email is required.
9
+ # @option params [String] :role ['SIGNER' or 'APPROVER']: Specify the role of recipient (REQUIRED)
10
+ # @option params [String] :email Email of the recipient. This is required if fax is not provided. Both fax and email can not be provided (email or fax REQUIRED)
11
+ # @option params [String] :fax Fax of the recipient. This is required if email is not provided. Both fax and email can not be provided (email or fax REQUIRED)
12
+ # @option params [Array] :securityOptions Security options that apply to the recipient. Populate the array with instances of {Echochamber::RecipientSecurityOption Echochamber::RecipientSecurityOption}
13
+ # @return [Echochamber::Recipient]
14
+
15
+ def initialize(params)
16
+ require_keys([:role], params)
17
+ require_exactly_one([:email, :fax], params)
18
+ merge!(params)
19
+ end
20
+
21
+ end
22
+ end
23
+
@@ -0,0 +1,20 @@
1
+ module Echochamber
2
+ class RecipientSecurityOption < Hash
3
+
4
+ include Validatable
5
+
6
+ # Validates RecipientSecurityOption parameters
7
+ #
8
+ # @param [Hash] params SYMBOL-referenced Hash.
9
+ # @option params [String] :authenticationMethod ['INHERITED_FROM_DOCUMENT' or 'KBA' or 'PASSWORD' or 'WEB_IDENTITY' or 'PHONE' or 'NONE']: The authentication method for the recipients to have access to view and sign the document. (REQUIRED)
10
+ # @option params [Array] :phoneInfos The phoneInfo required for the recipient to view and sign the document. Populate with instances of {Echochamber::PhoneInfo Echochamber::PhoneInfo}
11
+ # @option params [String] :password The password required for the recipient to view and sign the document.
12
+ # @return [Echochamber::RecipientSecurityOption]
13
+
14
+ def initialize(params)
15
+ require_keys([:authenticationMethod], params)
16
+ merge! params
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,142 @@
1
+ module Echochamber::Request
2
+
3
+ # Performs REST create_agreement operation
4
+ #
5
+ # @param body [Hash] Request body (REQUIRED)
6
+ # @param token [String] Auth token (REQUIRED)
7
+ # @param user_id [String] Echosign user ID (REQUIRED)
8
+ # @param user_email [String] Echosign user email
9
+ # @return [Hash] Agreement response body
10
+ def self.create_agreement(body, token, user_id=nil, user_email=nil)
11
+ headers = { :content_type => :json, :accept => :json, 'Access-Token' => token }
12
+ headers.merge!('X-User-Id' => user_id) unless user_id.nil?
13
+ headers.merge!('X-User-Email' => user_email) unless user_email.nil?
14
+ response = post(ENDPOINT.fetch(:agreement), body, headers)
15
+ JSON.parse(response.body)
16
+ end
17
+
18
+ # Performs REST GET /agreements operation
19
+ #
20
+ # @param token [String] Auth Token
21
+ # @return [Hash] Agreements response body
22
+ def self.get_agreements(token)
23
+ headers = { :accept => :json, 'Access-Token' => token }
24
+ response = get(ENDPOINT.fetch(:agreement), headers)
25
+ JSON.parse(response.body)
26
+ end
27
+
28
+ # Performs REST GET /agreement/:id operation
29
+ #
30
+ # @param token [String] Auth Token
31
+ # @param agreement_id [String] ID of agreement to retrieve info on.
32
+ # @return [Hash] Agreement info response body
33
+ def self.agreement_info(token, agreement_id)
34
+ headers = { :accept => :json, 'Access-Token' => token }
35
+ endpoint = "#{ENDPOINT.fetch(:agreement)}/#{agreement_id}"
36
+ response = get(endpoint, headers)
37
+ JSON.parse(response.body)
38
+ end
39
+
40
+ # Performs REST GET /agreement/:id/signingUrls operation
41
+ #
42
+ # @param token [String] Auth Token
43
+ # @param agreement_id [String] ID of agreement to retrieve info on.
44
+ # @return [Hash] URL information for the eSign page of the agreement
45
+ def self.agreement_signing_urls(token, agreement_id)
46
+ headers = { 'Access-Token' => token }
47
+ endpoint = "#{ENDPOINT.fetch(:agreement)}/#{agreement_id}/signingUrls"
48
+ response = get(endpoint, headers)
49
+ JSON.parse(response.body)
50
+ end
51
+
52
+ # Gets a single combined PDF document for the documents associated with an agreement.
53
+ #
54
+ # @param token [String] Auth Token
55
+ # @param agreement_id [String] ID of agreement to retrieve info on.
56
+ # @return [String] Raw bytes from document file
57
+ def self.agreement_combined_pdf(token, agreement_id, versionId, participantEmail, attachSupportingDocuments, auditReport)
58
+ headers = { 'Access-Token' => token }
59
+ endpoint = "#{ENDPOINT.fetch(:agreement)}/#{agreement_id}/combinedDocument"
60
+ endpoint << add_query(endpoint, "versionId=#{versionId}") unless versionId.nil?
61
+ endpoint << add_query(endpoint, "participantEmail=#{participantEmail}") unless participantEmail.nil?
62
+ endpoint << add_query(endpoint, "attachSupportingDocuments=#{attachSupportingDocuments}")
63
+ endpoint << add_query(endpoint, "auditReport=#{auditReport}")
64
+ response = get(endpoint, headers)
65
+ end
66
+
67
+ # Retrieves data entered by the user into interactive form fields at the time they signed the agreement
68
+ #
69
+ # @param token [String] Auth Token
70
+ # @param agreement_id [String] (REQUIRED)
71
+ # @return [String] Raw bytes representing CSV file
72
+ def self.agreement_form_data(token, agreement_id)
73
+ headers = { 'Access-Token' => token }
74
+ endpoint = "#{ENDPOINT.fetch(:agreement)}/#{agreement_id}/formData"
75
+ response = get(endpoint, headers)
76
+ end
77
+
78
+ # Retrieve agreement document PDF
79
+ #
80
+ # @param token [String] Auth Token
81
+ # @param agreement_id [String] ID of agreement to retrieve info on.
82
+ # @return [String] Raw bytes from document file
83
+ def self.agreement_document_file(token, agreement_id, document_id)
84
+ headers = { 'Access-Token' => token }
85
+ endpoint = "#{ENDPOINT.fetch(:agreement)}/#{agreement_id}/documents/#{document_id}"
86
+ response = get(endpoint, headers)
87
+ end
88
+
89
+ # Performs REST GET /agreement/:id/auditTrail operation
90
+ #
91
+ # @param token [String] Auth Token
92
+ # @param agreement_id [String] ID of agreement to retrieve info on.
93
+ # @return [String] Raw bytes from audit pdf file
94
+ def self.audit_trail_pdf(token, agreement_id)
95
+ headers = { 'Access-Token' => token }
96
+ endpoint = "#{ENDPOINT.fetch(:agreement)}/#{agreement_id}/auditTrail"
97
+ response = get(endpoint, headers)
98
+ end
99
+
100
+ # Performs REST GET /agreement/:id/documents
101
+ #
102
+ # @param agreement_id [String] (REQUIRED)
103
+ # @param recipient_email [String] The email address of the participant to be used to retrieve documents. (REQUIRED)
104
+ # @param format [String] Content format of the supported documents. It can have two possible values ORIGINAL or CONVERTED_PDF. (REQUIRED)
105
+ # @param version_id [String] Version of the agreement as provided by {agreement_info agreement_info}. If not provided, the latest version of the agreement is used.
106
+ # @return [Hash] Agreement documents response body
107
+ def self.agreement_documents(token, agreement_id, recipient_email=nil, format=nil, version_id=nil)
108
+ headers = { :accept => :json, 'Access-Token' => token }
109
+ endpoint = "#{ENDPOINT.fetch(:agreement)}/#{agreement_id}/documents"
110
+ endpoint << add_query(endpoint, "versionId=#{version_id}") unless version_id.nil?
111
+ endpoint << add_query(endpoint, "participantEmail=#{recipient_email}") unless version_id.nil?
112
+ endpoint << add_query(endpoint, "supportingDocumentContentFormat=#{format}") unless format.nil?
113
+ response = get(endpoint, headers)
114
+ JSON.parse(response.body)
115
+ end
116
+
117
+
118
+ # Performs REST PUT /agreement/:id operation
119
+ #
120
+ # @param token [String] Auth Token
121
+ # @param agreement_id [String] ID of agreement to retrieve info on.
122
+ # @param request_body [Hash] Hash for Agreement status update
123
+ # @return [Hash] Agreements response body
124
+ def self.update_agreement_status(token, agreement_id, request_body)
125
+ headers = { :content_type => :json, :accept => :json, 'Access-Token' => token }
126
+ endpoint = "#{ENDPOINT.fetch(:agreement)}/#{agreement_id}/status"
127
+
128
+ begin
129
+ response = RestClient.put(
130
+ endpoint,
131
+ request_body.to_json,
132
+ headers
133
+ )
134
+ rescue Exception => error
135
+ raise_error(error)
136
+ end
137
+
138
+ JSON.parse(response.body)
139
+ end
140
+
141
+
142
+ end