echosign 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) 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 +91 -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/echosign.gemspec +36 -0
  11. data/features/support/env.rb +8 -0
  12. data/fixtures/agreement.pdf +0 -0
  13. data/fixtures/vcr_cassettes/agreement_combined_pdf.yml +1465 -0
  14. data/fixtures/vcr_cassettes/agreement_document_file.yml +1465 -0
  15. data/fixtures/vcr_cassettes/agreement_documents.yml +42 -0
  16. data/fixtures/vcr_cassettes/agreement_form_data.yml +44 -0
  17. data/fixtures/vcr_cassettes/agreement_info.yml +50 -0
  18. data/fixtures/vcr_cassettes/agreement_signing_urls.yml +42 -0
  19. data/fixtures/vcr_cassettes/audit_trail_pdf.yml +1643 -0
  20. data/fixtures/vcr_cassettes/cancel_agreement.yml +46 -0
  21. data/fixtures/vcr_cassettes/create_agreement.yml +50 -0
  22. data/fixtures/vcr_cassettes/create_reminder.yml +47 -0
  23. data/fixtures/vcr_cassettes/create_transient_document.yml +716 -0
  24. data/fixtures/vcr_cassettes/create_user.yml +50 -0
  25. data/fixtures/vcr_cassettes/create_widget.yml +48 -0
  26. data/fixtures/vcr_cassettes/get_agreements.yml +46 -0
  27. data/fixtures/vcr_cassettes/get_library_document.yml +45 -0
  28. data/fixtures/vcr_cassettes/get_library_document_data.yml +1191 -0
  29. data/fixtures/vcr_cassettes/get_library_document_file.yml +42 -0
  30. data/fixtures/vcr_cassettes/get_library_documents.yml +47 -0
  31. data/fixtures/vcr_cassettes/get_token.yml +44 -0
  32. data/fixtures/vcr_cassettes/get_user.yml +46 -0
  33. data/fixtures/vcr_cassettes/get_users.yml +43 -0
  34. data/fixtures/vcr_cassettes/get_widget.yml +49 -0
  35. data/fixtures/vcr_cassettes/get_widget_document_file.yml +2682 -0
  36. data/fixtures/vcr_cassettes/get_widget_documents.yml +44 -0
  37. data/fixtures/vcr_cassettes/get_widgets.yml +50 -0
  38. data/fixtures/vcr_cassettes/library_combined_document.yml +2197 -0
  39. data/fixtures/vcr_cassettes/library_document_audit_trail.yml +1570 -0
  40. data/fixtures/vcr_cassettes/personalize_widget.yml +47 -0
  41. data/fixtures/vcr_cassettes/update_widget_status.yml +46 -0
  42. data/lib/echosign.rb +11 -0
  43. data/lib/echosign/agreement.rb +34 -0
  44. data/lib/echosign/agreement/client.rb +118 -0
  45. data/lib/echosign/agreement/fileinfo.rb +20 -0
  46. data/lib/echosign/agreement/form_field_location.rb +20 -0
  47. data/lib/echosign/agreement/phone_info.rb +19 -0
  48. data/lib/echosign/agreement/recipient.rb +22 -0
  49. data/lib/echosign/agreement/recipient_security_option.rb +20 -0
  50. data/lib/echosign/agreement/request.rb +144 -0
  51. data/lib/echosign/agreement/request_form_field.rb +15 -0
  52. data/lib/echosign/agreement/url_file_info.rb +18 -0
  53. data/lib/echosign/client.rb +82 -0
  54. data/lib/echosign/credentials.rb +33 -0
  55. data/lib/echosign/library_documents/client.rb +83 -0
  56. data/lib/echosign/library_documents/request.rb +78 -0
  57. data/lib/echosign/mega_sign.rb +32 -0
  58. data/lib/echosign/mega_sign/client.rb +119 -0
  59. data/lib/echosign/mega_sign/request.rb +144 -0
  60. data/lib/echosign/refresh.rb +25 -0
  61. data/lib/echosign/reminder.rb +17 -0
  62. data/lib/echosign/request.rb +165 -0
  63. data/lib/echosign/user.rb +29 -0
  64. data/lib/echosign/validatable.rb +54 -0
  65. data/lib/echosign/version.rb +3 -0
  66. data/lib/echosign/widget.rb +176 -0
  67. data/lib/echosign/widget/client.rb +127 -0
  68. data/lib/echosign/widget/counter_signer_info.rb +19 -0
  69. data/lib/echosign/widget/request.rb +135 -0
  70. data/lib/echosign/widget/widget_completion_info.rb +25 -0
  71. data/lib/echosign/widget/widget_personalization.rb +21 -0
  72. data/lib/echosign/widget/widget_security_option.rb +22 -0
  73. data/lib/echosign/widget/widget_signer_security_option.rb +18 -0
  74. data/lib/echosign/widget/widget_status.rb +20 -0
  75. data/lib/echosign/widget/widget_vaulting_info.rb +16 -0
  76. data/spec/lib/agreement/client_spec.rb +157 -0
  77. data/spec/lib/client_spec.rb +78 -0
  78. data/spec/lib/library_documents/client_spec.rb +71 -0
  79. data/spec/lib/request_spec.rb +18 -0
  80. data/spec/lib/shared_client.rb +22 -0
  81. data/spec/lib/user_spec.rb +6 -0
  82. data/spec/lib/validatable_spec.rb +110 -0
  83. data/spec/lib/version_spec.rb +7 -0
  84. data/spec/lib/widget/client_spec.rb +154 -0
  85. data/spec/spec_helper.rb +22 -0
  86. metadata +307 -0
@@ -0,0 +1,47 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: put
5
+ uri: https://secure.echosign.com/api/rest/v5/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/v5/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,11 @@
1
+ require 'json'
2
+ require "echosign/version"
3
+ require 'echosign/client'
4
+ require 'echosign/validatable'
5
+ require 'echosign/credentials'
6
+ require 'echosign/refresh'
7
+ require 'echosign/request'
8
+ require 'echosign/agreement'
9
+ require 'echosign/user'
10
+ require 'echosign/reminder'
11
+ require 'echosign/widget'
@@ -0,0 +1,34 @@
1
+ require 'echosign/agreement/fileinfo'
2
+ require 'echosign/agreement/url_file_info'
3
+ require 'echosign/agreement/recipient'
4
+ require 'echosign/agreement/request_form_field'
5
+ require 'echosign/agreement/form_field_location'
6
+
7
+ module Echosign
8
+ class Agreement < Hash
9
+
10
+ include Validatable
11
+
12
+ attr_accessor :user_id, :user_email
13
+
14
+ # Creates an agreement object for submission
15
+ #
16
+ # @param [String] user_id ID of the user whom this agreement is made for
17
+ # @param [String] user_email Email of the user whom this agreement is made for
18
+ # @param [Hash] params SYMBOL-referenced Hash containing:
19
+ # @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 {Echosign::Fileinfo Echosign::Fileinfo} (REQUIRED)
20
+ # @option params [Array] :recipientSetInfos 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 {Echosign::Recipient Echosign::Recipient} (REQUIRED)
21
+ # @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)
22
+ # @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)
23
+ # @option params [String] :name The name of the agreement that will be used to identify it, in emails and on the website. (REQUIRED)
24
+ # @return [Echosign::Agreement]
25
+ def initialize(user_id=nil, user_email=nil, params)
26
+ @user_id = user_id
27
+ @user_email = user_email
28
+ #TODO (cthomas) barf if user_id or user_email are blank
29
+ require_keys([:signatureType, :recipientSetInfos, :signatureFlow, :fileInfos, :name], params)
30
+ merge!({ documentCreationInfo: params })
31
+ end
32
+
33
+ end # class Agreement
34
+ end # module Echosign
@@ -0,0 +1,118 @@
1
+ module Echosign
2
+
3
+ class Client
4
+
5
+ # Creates an agreement
6
+ #
7
+ # @param agreement [Echosign::Agreement]
8
+ # @return [String] Agreement ID
9
+ def create_agreement(agreement)
10
+ agreement_response = Echosign::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 [Echosign::Agreement]
17
+ # @return [String] Agreement ID
18
+ def get_agreements
19
+ get_agreements_response = Echosign::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
+ Echosign::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 = Echosign::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 = Echosign::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 = Echosign::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 = Echosign::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 = Echosign::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 = Echosign::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 Echosign
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 [Echosign::UrlFileInfo] :documentURL A description of the URL where the document can be found
13
+ # @return [Echosign::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,20 @@
1
+ module Echosign
2
+ class FormFieldLocation < Hash
3
+
4
+ include Validatable
5
+
6
+ # Validates FormFieldLocation params
7
+ #
8
+ # @param [Hash] params SYMBOL-referenced Hash containing exactly one of the following:
9
+ # @option param [Integer] height (double): Height of the form field in pixels,
10
+ # @option param [Integer] left (double): No. of pixels from left of the page for form field placement,
11
+ # @option param [Integer] pageNumber (int): Number of the page where form field has to be placed, starting from 1.,
12
+ # @option param [Integer] top (double): No. of pixels from bottom of the page for form field placement,
13
+ # @option param [Integer] width (double): Width of the form field in pixels
14
+ # @return [Echosign::FormFieldLocation]
15
+ def initialize(params)
16
+ require_keys([:pageNumber, :left, :top, :width, :height], params)
17
+ merge!(params)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ module Echosign
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 [Echosign::PhoneInfo]
12
+
13
+ def initialize(params)
14
+ require_keys([:phone], params)
15
+ merge!(params)
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ module Echosign
2
+ class Recipient < Hash
3
+
4
+ include Validatable
5
+
6
+ # Creates an Echosign::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 {Echosign::RecipientSecurityOption Echosign::RecipientSecurityOption}
13
+ # @return [Echosign::Recipient]
14
+
15
+ def initialize(params)
16
+ require_exactly_one([:email, :fax], params)
17
+ merge!(params)
18
+ end
19
+
20
+ end
21
+ end
22
+
@@ -0,0 +1,20 @@
1
+ module Echosign
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 {Echosign::PhoneInfo Echosign::PhoneInfo}
11
+ # @option params [String] :password The password required for the recipient to view and sign the document.
12
+ # @return [Echosign::RecipientSecurityOption]
13
+
14
+ def initialize(params)
15
+ require_keys([:authenticationMethod], params)
16
+ merge! params
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,144 @@
1
+ module Echosign::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 = { '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
+ headers.merge!('Content-Type' => "application/json")
15
+ response = HTTParty.post(ENDPOINT.fetch(:agreement), :body => body.to_json,
16
+ :headers => headers)
17
+ JSON.parse(response.body)
18
+ end
19
+
20
+ # Performs REST GET /agreements operation
21
+ #
22
+ # @param token [String] Auth Token
23
+ # @return [Hash] Agreements response body
24
+ def self.get_agreements(token)
25
+ headers = { 'Access-Token' => token }
26
+ response = get(ENDPOINT.fetch(:agreement), headers)
27
+ JSON.parse(response.body)
28
+ end
29
+
30
+ # Performs REST GET /agreement/:id operation
31
+ #
32
+ # @param token [String] Auth Token
33
+ # @param agreement_id [String] ID of agreement to retrieve info on.
34
+ # @return [Hash] Agreement info response body
35
+ def self.agreement_info(token, agreement_id)
36
+ headers = { 'Access-Token' => token }
37
+ endpoint = "#{ENDPOINT.fetch(:agreement)}/#{agreement_id}"
38
+ response = get(endpoint, headers)
39
+ JSON.parse(response.body)
40
+ end
41
+
42
+ # Performs REST GET /agreement/:id/signingUrls operation
43
+ #
44
+ # @param token [String] Auth Token
45
+ # @param agreement_id [String] ID of agreement to retrieve info on.
46
+ # @return [Hash] URL information for the eSign page of the agreement
47
+ def self.agreement_signing_urls(token, agreement_id)
48
+ headers = { 'Access-Token' => token }
49
+ endpoint = "#{ENDPOINT.fetch(:agreement)}/#{agreement_id}/signingUrls"
50
+ response = get(endpoint, headers)
51
+ JSON.parse(response.body)
52
+ end
53
+
54
+ # Gets a single combined PDF document for the documents associated with an agreement.
55
+ #
56
+ # @param token [String] Auth Token
57
+ # @param agreement_id [String] ID of agreement to retrieve info on.
58
+ # @return [String] Raw bytes from document file
59
+ def self.agreement_combined_pdf(token, agreement_id, versionId, participantEmail, attachSupportingDocuments, auditReport)
60
+ headers = { 'Access-Token' => token }
61
+ endpoint = "#{ENDPOINT.fetch(:agreement)}/#{agreement_id}/combinedDocument"
62
+ endpoint << add_query(endpoint, "versionId=#{versionId}") unless versionId.nil?
63
+ endpoint << add_query(endpoint, "participantEmail=#{participantEmail}") unless participantEmail.nil?
64
+ endpoint << add_query(endpoint, "attachSupportingDocuments=#{attachSupportingDocuments}")
65
+ endpoint << add_query(endpoint, "auditReport=#{auditReport}")
66
+ response = get(endpoint, headers)
67
+ end
68
+
69
+ # Retrieves data entered by the user into interactive form fields at the time they signed the agreement
70
+ #
71
+ # @param token [String] Auth Token
72
+ # @param agreement_id [String] (REQUIRED)
73
+ # @return [String] Raw bytes representing CSV file
74
+ def self.agreement_form_data(token, agreement_id)
75
+ headers = { 'Access-Token' => token }
76
+ endpoint = "#{ENDPOINT.fetch(:agreement)}/#{agreement_id}/formData"
77
+ response = get(endpoint, headers)
78
+ end
79
+
80
+ # Retrieve agreement document PDF
81
+ #
82
+ # @param token [String] Auth Token
83
+ # @param agreement_id [String] ID of agreement to retrieve info on.
84
+ # @return [String] Raw bytes from document file
85
+ def self.agreement_document_file(token, agreement_id, document_id)
86
+ headers = { 'Access-Token' => token }
87
+ endpoint = "#{ENDPOINT.fetch(:agreement)}/#{agreement_id}/documents/#{document_id}"
88
+ response = get(endpoint, headers)
89
+ end
90
+
91
+ # Performs REST GET /agreement/:id/auditTrail operation
92
+ #
93
+ # @param token [String] Auth Token
94
+ # @param agreement_id [String] ID of agreement to retrieve info on.
95
+ # @return [String] Raw bytes from audit pdf file
96
+ def self.audit_trail_pdf(token, agreement_id)
97
+ headers = { 'Access-Token' => token }
98
+ endpoint = "#{ENDPOINT.fetch(:agreement)}/#{agreement_id}/auditTrail"
99
+ response = get(endpoint, headers)
100
+ end
101
+
102
+ # Performs REST GET /agreement/:id/documents
103
+ #
104
+ # @param agreement_id [String] (REQUIRED)
105
+ # @param recipient_email [String] The email address of the participant to be used to retrieve documents. (REQUIRED)
106
+ # @param format [String] Content format of the supported documents. It can have two possible values ORIGINAL or CONVERTED_PDF. (REQUIRED)
107
+ # @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.
108
+ # @return [Hash] Agreement documents response body
109
+ def self.agreement_documents(token, agreement_id, recipient_email=nil, format=nil, version_id=nil)
110
+ headers = { 'Access-Token' => token }
111
+ endpoint = "#{ENDPOINT.fetch(:agreement)}/#{agreement_id}/documents"
112
+ endpoint << add_query(endpoint, "versionId=#{version_id}") unless version_id.nil?
113
+ endpoint << add_query(endpoint, "participantEmail=#{recipient_email}") unless version_id.nil?
114
+ endpoint << add_query(endpoint, "supportingDocumentContentFormat=#{format}") unless format.nil?
115
+ response = get(endpoint, headers)
116
+ JSON.parse(response.body)
117
+ end
118
+
119
+
120
+ # Performs REST PUT /agreement/:id operation
121
+ #
122
+ # @param token [String] Auth Token
123
+ # @param agreement_id [String] ID of agreement to retrieve info on.
124
+ # @param request_body [Hash] Hash for Agreement status update
125
+ # @return [Hash] Agreements response body
126
+ def self.update_agreement_status(token, agreement_id, request_body)
127
+ headers = { 'Access-Token' => token }
128
+ endpoint = "#{ENDPOINT.fetch(:agreement)}/#{agreement_id}/status"
129
+
130
+ begin
131
+ response = HTTParty.put(
132
+ endpoint,
133
+ request_body.to_json,
134
+ headers
135
+ )
136
+ rescue Exception => error
137
+ raise_error(error)
138
+ end
139
+
140
+ JSON.parse(response.body)
141
+ end
142
+
143
+
144
+ end