echosign 1.0.2 → 1.5.0

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 (132) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.rubocop.yml +14 -0
  4. data/.rubocop_todo.yml +241 -0
  5. data/.simplecov +2 -0
  6. data/.travis.yml +9 -0
  7. data/Gemfile +3 -3
  8. data/Gemfile.lock +74 -48
  9. data/README.md +43 -8
  10. data/Rakefile +2 -2
  11. data/doc/Echosign.html +135 -0
  12. data/doc/Echosign/Agreement.html +545 -0
  13. data/doc/Echosign/Client.html +5365 -0
  14. data/doc/Echosign/CounterSignerInfo.html +267 -0
  15. data/doc/Echosign/Credentials.html +1053 -0
  16. data/doc/Echosign/Fileinfo.html +305 -0
  17. data/doc/Echosign/FormFieldLocation.html +264 -0
  18. data/doc/Echosign/MegaSign.html +533 -0
  19. data/doc/Echosign/ParameterError.html +124 -0
  20. data/doc/Echosign/PhoneInfo.html +281 -0
  21. data/doc/Echosign/Recipient.html +311 -0
  22. data/doc/Echosign/RecipientSecurityOption.html +296 -0
  23. data/doc/Echosign/Refresh.html +288 -0
  24. data/doc/Echosign/Reminder.html +279 -0
  25. data/doc/Echosign/Request.html +5289 -0
  26. data/doc/Echosign/Request/EndpointHash.html +328 -0
  27. data/doc/Echosign/Request/Failure.html +290 -0
  28. data/doc/Echosign/RequestFormField.html +244 -0
  29. data/doc/Echosign/RequiredParameterError.html +124 -0
  30. data/doc/Echosign/UrlFileInfo.html +297 -0
  31. data/doc/Echosign/User.html +422 -0
  32. data/doc/Echosign/Validatable.html +355 -0
  33. data/doc/Echosign/Widget.html +924 -0
  34. data/doc/Echosign/WidgetCompletionInfo.html +323 -0
  35. data/doc/Echosign/WidgetPersonalization.html +330 -0
  36. data/doc/Echosign/WidgetSecurityOption.html +361 -0
  37. data/doc/Echosign/WidgetSignerSecurityOption.html +298 -0
  38. data/doc/Echosign/WidgetStatus.html +316 -0
  39. data/doc/Echosign/WidgetVaultingInfo.html +267 -0
  40. data/doc/_index.html +378 -0
  41. data/doc/class_list.html +51 -0
  42. data/doc/css/common.css +1 -0
  43. data/doc/css/full_list.css +58 -0
  44. data/doc/css/style.css +496 -0
  45. data/doc/file.README.html +191 -0
  46. data/doc/file_list.html +56 -0
  47. data/doc/frames.html +17 -0
  48. data/doc/index.html +191 -0
  49. data/doc/js/app.js +292 -0
  50. data/doc/js/full_list.js +216 -0
  51. data/doc/js/jquery.js +4 -0
  52. data/doc/method_list.html +1035 -0
  53. data/doc/top-level-namespace.html +110 -0
  54. data/echosign.gemspec +18 -20
  55. data/features/support/env.rb +8 -8
  56. data/fixtures/vcr_cassettes/agreement_combined_pdf.yml +2 -2
  57. data/fixtures/vcr_cassettes/agreement_document_file.yml +1 -1
  58. data/fixtures/vcr_cassettes/agreement_documents.yml +2 -2
  59. data/fixtures/vcr_cassettes/agreement_form_data.yml +1 -1
  60. data/fixtures/vcr_cassettes/agreement_info.yml +1 -1
  61. data/fixtures/vcr_cassettes/agreement_signing_urls.yml +1 -1
  62. data/fixtures/vcr_cassettes/audit_trail_pdf.yml +1 -1
  63. data/fixtures/vcr_cassettes/cancel_agreement.yml +1 -1
  64. data/fixtures/vcr_cassettes/create_agreement.yml +1 -1
  65. data/fixtures/vcr_cassettes/create_reminder.yml +1 -1
  66. data/fixtures/vcr_cassettes/create_transient_document.yml +1 -1
  67. data/fixtures/vcr_cassettes/create_user.yml +1 -1
  68. data/fixtures/vcr_cassettes/create_widget.yml +1 -1
  69. data/fixtures/vcr_cassettes/get_agreements.yml +1 -1
  70. data/fixtures/vcr_cassettes/get_library_document.yml +1 -1
  71. data/fixtures/vcr_cassettes/get_library_document_data.yml +1 -1
  72. data/fixtures/vcr_cassettes/get_library_document_file.yml +1 -1
  73. data/fixtures/vcr_cassettes/get_library_documents.yml +1 -1
  74. data/fixtures/vcr_cassettes/get_token.yml +22 -20
  75. data/fixtures/vcr_cassettes/get_user.yml +1 -1
  76. data/fixtures/vcr_cassettes/get_users.yml +2 -2
  77. data/fixtures/vcr_cassettes/get_widget.yml +1 -1
  78. data/fixtures/vcr_cassettes/get_widget_document_file.yml +1 -1
  79. data/fixtures/vcr_cassettes/get_widget_documents.yml +1 -1
  80. data/fixtures/vcr_cassettes/get_widgets.yml +1 -1
  81. data/fixtures/vcr_cassettes/library_combined_document.yml +2 -2
  82. data/fixtures/vcr_cassettes/library_document_audit_trail.yml +1 -1
  83. data/fixtures/vcr_cassettes/personalize_widget.yml +1 -1
  84. data/fixtures/vcr_cassettes/refresh_token.yml +46 -0
  85. data/fixtures/vcr_cassettes/revoke_token.yml +44 -0
  86. data/fixtures/vcr_cassettes/update_widget_status.yml +1 -1
  87. data/lib/echosign.rb +11 -11
  88. data/lib/echosign/agreement.rb +26 -10
  89. data/lib/echosign/agreement/client.rb +111 -104
  90. data/lib/echosign/agreement/fileinfo.rb +1 -3
  91. data/lib/echosign/agreement/form_field_location.rb +2 -3
  92. data/lib/echosign/agreement/phone_info.rb +5 -5
  93. data/lib/echosign/agreement/recipient.rb +9 -8
  94. data/lib/echosign/agreement/recipient_security_option.rb +5 -4
  95. data/lib/echosign/agreement/request.rb +33 -43
  96. data/lib/echosign/agreement/request_form_field.rb +2 -3
  97. data/lib/echosign/agreement/url_file_info.rb +8 -6
  98. data/lib/echosign/client.rb +33 -24
  99. data/lib/echosign/credentials.rb +95 -24
  100. data/lib/echosign/library_documents/client.rb +18 -23
  101. data/lib/echosign/library_documents/request.rb +19 -20
  102. data/lib/echosign/mega_sign.rb +20 -10
  103. data/lib/echosign/mega_sign/client.rb +109 -104
  104. data/lib/echosign/mega_sign/request.rb +32 -43
  105. data/lib/echosign/refresh.rb +6 -10
  106. data/lib/echosign/reminder.rb +2 -2
  107. data/lib/echosign/request.rb +85 -75
  108. data/lib/echosign/user.rb +13 -7
  109. data/lib/echosign/validatable.rb +6 -10
  110. data/lib/echosign/version.rb +1 -1
  111. data/lib/echosign/widget.rb +53 -27
  112. data/lib/echosign/widget/client.rb +33 -36
  113. data/lib/echosign/widget/counter_signer_info.rb +4 -5
  114. data/lib/echosign/widget/request.rb +28 -52
  115. data/lib/echosign/widget/widget_completion_info.rb +22 -12
  116. data/lib/echosign/widget/widget_personalization.rb +9 -7
  117. data/lib/echosign/widget/widget_security_option.rb +21 -11
  118. data/lib/echosign/widget/widget_signer_security_option.rb +8 -6
  119. data/lib/echosign/widget/widget_status.rb +10 -8
  120. data/lib/echosign/widget/widget_vaulting_info.rb +4 -5
  121. data/spec/lib/agreement/client_spec.rb +25 -31
  122. data/spec/lib/client_spec.rb +15 -18
  123. data/spec/lib/credentials_spec.rb +48 -0
  124. data/spec/lib/library_documents/client_spec.rb +11 -15
  125. data/spec/lib/shared_client.rb +9 -16
  126. data/spec/lib/user_spec.rb +0 -2
  127. data/spec/lib/validatable_spec.rb +12 -18
  128. data/spec/lib/version_spec.rb +1 -1
  129. data/spec/lib/widget/client_spec.rb +46 -49
  130. data/spec/spec_helper.rb +12 -5
  131. metadata +125 -60
  132. data/spec/lib/request_spec.rb +0 -18
@@ -1,5 +1,4 @@
1
1
  module Echosign::Request
2
-
3
2
  # Performs REST create_mega_sign operation
4
3
  #
5
4
  # @param body [Hash] Request body (REQUIRED)
@@ -7,13 +6,13 @@ module Echosign::Request
7
6
  # @param user_id [String] Echosign user ID (REQUIRED)
8
7
  # @param user_email [String] Echosign user email
9
8
  # @return [Hash] MegaSign response body
10
- def self.create_mega_sign(body, token, user_id=nil, user_email=nil)
9
+ def self.create_mega_sign(token, base_uri, body, user_id = nil, user_email = nil)
11
10
  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(:mega_sign), :body => body.to_json,
16
- :headers => headers)
11
+ headers['X-User-Id'] = user_id unless user_id.nil?
12
+ headers['X-User-Email'] = user_email unless user_email.nil?
13
+ headers['Content-Type'] = "application/json"
14
+ response = HTTParty.post(ENDPOINT.fetch(:megaSign, base_uri), body: body.to_json,
15
+ headers: headers)
17
16
  JSON.parse(response.body)
18
17
  end
19
18
 
@@ -21,9 +20,9 @@ module Echosign::Request
21
20
  #
22
21
  # @param token [String] Auth Token
23
22
  # @return [Hash] MegaSigns response body
24
- def self.get_mega_signs(token)
23
+ def self.get_mega_signs(token, base_uri)
25
24
  headers = { 'Access-Token' => token }
26
- response = get(ENDPOINT.fetch(:mega_sign), headers)
25
+ response = get(ENDPOINT.fetch(:megaSign, base_uri), headers)
27
26
  JSON.parse(response.body)
28
27
  end
29
28
 
@@ -32,9 +31,9 @@ module Echosign::Request
32
31
  # @param token [String] Auth Token
33
32
  # @param mega_sign_id [String] ID of mega_sign to retrieve info on.
34
33
  # @return [Hash] MegaSign info response body
35
- def self.mega_sign_info(token, mega_sign_id)
34
+ def self.mega_sign_info(token, base_uri, mega_sign_id)
36
35
  headers = { 'Access-Token' => token }
37
- endpoint = "#{ENDPOINT.fetch(:mega_sign)}/#{mega_sign_id}"
36
+ endpoint = "#{ENDPOINT.fetch(:megaSign, base_uri)}/#{mega_sign_id}"
38
37
  response = get(endpoint, headers)
39
38
  JSON.parse(response.body)
40
39
  end
@@ -44,21 +43,22 @@ module Echosign::Request
44
43
  # @param token [String] Auth Token
45
44
  # @param mega_sign_id [String] ID of mega_sign to retrieve info on.
46
45
  # @return [Hash] URL information for the eSign page of the mega_sign
47
- def self.mega_sign_signing_urls(token, mega_sign_id)
46
+ def self.mega_sign_signing_urls(token, base_uri, mega_sign_id)
48
47
  headers = { 'Access-Token' => token }
49
- endpoint = "#{ENDPOINT.fetch(:mega_sign)}/#{mega_sign_id}/signingUrls"
48
+ endpoint = "#{ENDPOINT.fetch(:megaSign, base_uri)}/#{mega_sign_id}/signingUrls"
50
49
  response = get(endpoint, headers)
51
50
  JSON.parse(response.body)
52
51
  end
53
52
 
54
53
  # Gets a single combined PDF document for the documents associated with an mega_sign.
55
- #
54
+ #
56
55
  # @param token [String] Auth Token
57
56
  # @param mega_sign_id [String] ID of mega_sign to retrieve info on.
58
57
  # @return [String] Raw bytes from document file
59
- def self.mega_sign_combined_pdf(token, mega_sign_id, versionId, participantEmail, attachSupportingDocuments, auditReport)
58
+ def self.mega_sign_combined_pdf(token, base_uri, mega_sign_id, versionId, participantEmail,
59
+ attachSupportingDocuments, auditReport)
60
60
  headers = { 'Access-Token' => token }
61
- endpoint = "#{ENDPOINT.fetch(:mega_sign)}/#{mega_sign_id}/combinedDocument"
61
+ endpoint = "#{ENDPOINT.fetch(:megaSign, base_uri)}/#{mega_sign_id}/combinedDocument"
62
62
  endpoint << add_query(endpoint, "versionId=#{versionId}") unless versionId.nil?
63
63
  endpoint << add_query(endpoint, "participantEmail=#{participantEmail}") unless participantEmail.nil?
64
64
  endpoint << add_query(endpoint, "attachSupportingDocuments=#{attachSupportingDocuments}")
@@ -67,13 +67,13 @@ module Echosign::Request
67
67
  end
68
68
 
69
69
  # Retrieves data entered by the user into interactive form fields at the time they signed the mega_sign
70
- #
70
+ #
71
71
  # @param token [String] Auth Token
72
72
  # @param mega_sign_id [String] (REQUIRED)
73
73
  # @return [String] Raw bytes representing CSV file
74
- def self.mega_sign_form_data(token, mega_sign_id)
74
+ def self.mega_sign_form_data(token, base_uri, mega_sign_id)
75
75
  headers = { 'Access-Token' => token }
76
- endpoint = "#{ENDPOINT.fetch(:mega_sign)}/#{mega_sign_id}/formData"
76
+ endpoint = "#{ENDPOINT.fetch(:megaSign, base_uri)}/#{mega_sign_id}/formData"
77
77
  response = get(endpoint, headers)
78
78
  end
79
79
 
@@ -82,9 +82,9 @@ module Echosign::Request
82
82
  # @param token [String] Auth Token
83
83
  # @param mega_sign_id [String] ID of mega_sign to retrieve info on.
84
84
  # @return [String] Raw bytes from document file
85
- def self.mega_sign_document_file(token, mega_sign_id, document_id)
85
+ def self.mega_sign_document_file(token, base_uri, mega_sign_id, document_id)
86
86
  headers = { 'Access-Token' => token }
87
- endpoint = "#{ENDPOINT.fetch(:mega_sign)}/#{mega_sign_id}/documents/#{document_id}"
87
+ endpoint = "#{ENDPOINT.fetch(:megaSign, base_uri)}/#{mega_sign_id}/documents/#{document_id}"
88
88
  response = get(endpoint, headers)
89
89
  end
90
90
 
@@ -93,9 +93,9 @@ module Echosign::Request
93
93
  # @param token [String] Auth Token
94
94
  # @param mega_sign_id [String] ID of mega_sign to retrieve info on.
95
95
  # @return [String] Raw bytes from audit pdf file
96
- def self.audit_trail_pdf(token, mega_sign_id)
96
+ def self.audit_trail_pdf(token, base_uri, mega_sign_id)
97
97
  headers = { 'Access-Token' => token }
98
- endpoint = "#{ENDPOINT.fetch(:mega_sign)}/#{mega_sign_id}/auditTrail"
98
+ endpoint = "#{ENDPOINT.fetch(:megaSign, base_uri)}/#{mega_sign_id}/auditTrail"
99
99
  response = get(endpoint, headers)
100
100
  end
101
101
 
@@ -103,12 +103,14 @@ module Echosign::Request
103
103
  #
104
104
  # @param mega_sign_id [String] (REQUIRED)
105
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 mega_sign as provided by {mega_sign_info mega_sign_info}. If not provided, the latest version of the mega_sign is used.
106
+ # @param format [String] Content format of the supported documents. It can have two possible values ORIGINAL or
107
+ # CONVERTED_PDF. (REQUIRED)
108
+ # @param version_id [String] Version of the mega_sign as provided by {mega_sign_info mega_sign_info}. If not
109
+ # provided, the latest version of the mega_sign is used.
108
110
  # @return [Hash] MegaSign documents response body
109
- def self.mega_sign_documents(token, mega_sign_id, recipient_email=nil, format=nil, version_id=nil)
111
+ def self.mega_sign_documents(token, base_uri, mega_sign_id, recipient_email = nil, format = nil, version_id = nil)
110
112
  headers = { 'Access-Token' => token }
111
- endpoint = "#{ENDPOINT.fetch(:mega_sign)}/#{mega_sign_id}/documents"
113
+ endpoint = "#{ENDPOINT.fetch(:megaSign, base_uri)}/#{mega_sign_id}/documents"
112
114
  endpoint << add_query(endpoint, "versionId=#{version_id}") unless version_id.nil?
113
115
  endpoint << add_query(endpoint, "participantEmail=#{recipient_email}") unless version_id.nil?
114
116
  endpoint << add_query(endpoint, "supportingDocumentContentFormat=#{format}") unless format.nil?
@@ -116,29 +118,16 @@ module Echosign::Request
116
118
  JSON.parse(response.body)
117
119
  end
118
120
 
119
-
120
121
  # Performs REST PUT /mega_sign/:id operation
121
122
  #
122
123
  # @param token [String] Auth Token
123
124
  # @param mega_sign_id [String] ID of mega_sign to retrieve info on.
124
125
  # @param request_body [Hash] Hash for MegaSign status update
125
126
  # @return [Hash] MegaSigns response body
126
- def self.update_mega_sign_status(token, mega_sign_id, request_body)
127
+ def self.update_mega_sign_status(token, base_uri, mega_sign_id, request_body)
127
128
  headers = { 'Access-Token' => token }
128
- endpoint = "#{ENDPOINT.fetch(:mega_sign)}/#{mega_sign_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
-
129
+ endpoint = "#{ENDPOINT.fetch(:megaSign, base_uri)}/#{mega_sign_id}/status"
130
+ response = put(endpoint, request_body.to_json, headers)
140
131
  JSON.parse(response.body)
141
132
  end
142
-
143
-
144
133
  end
@@ -1,6 +1,5 @@
1
1
  module Echosign
2
2
  class Refresh < Hash
3
-
4
3
  include Validatable
5
4
 
6
5
  # Builds a Credentials object
@@ -9,17 +8,14 @@ module Echosign
9
8
  # @param client_secret [String] Application secret
10
9
  # @param refresh_token [String] OAuth Refresh Token
11
10
  def initialize(client_id, client_secret, refresh_token)
12
-
13
11
  merge!(
14
- {
15
- :client_id => client_id,
16
- :client_secret => client_secret,
17
- :refresh_token => refresh_token,
18
- :grant_type => "refresh_token"
19
- }
12
+ {
13
+ client_id: client_id,
14
+ client_secret: client_secret,
15
+ refresh_token: refresh_token,
16
+ grant_type: "refresh_token"
17
+ }
20
18
  )
21
19
  end
22
-
23
20
  end
24
21
  end
25
-
@@ -1,13 +1,13 @@
1
1
  module Echosign
2
2
  class Reminder < Hash
3
-
4
3
  include Validatable
5
4
 
6
5
  # Reminder options
7
6
  #
8
7
  # @param [Hash] params SYMBOL-referenced Hash containing exactly one of the following:
9
8
  # @option params [String] :agreementId (REQUIRED)
10
- # @option params [String] :comment An Optional message sent to the recipients, describing what is being sent and why their signatures are required.
9
+ # @option params [String] :comment An Optional message sent to the recipients, describing what is being sent and
10
+ # why their signatures are required.
11
11
  # @return [Echosign::Reminder]
12
12
  def initialize(params)
13
13
  require_keys([:agreementId], params)
@@ -13,42 +13,44 @@ module Echosign::Request
13
13
  end
14
14
  end
15
15
 
16
- BASE_URL = 'https://api.eu1.echosign.com/api/rest/v5'
17
- REFRESH_URL = 'https://api.eu1.echosign.com/oauth/refresh'
18
-
19
- ENDPOINT = {
20
- token: BASE_URL + '/auth/tokens',
21
- refresh: REFRESH_URL,
22
- user: BASE_URL + '/users',
23
- agreement: BASE_URL + '/agreements',
24
- mega_sign: BASE_URL + '/megaSigns',
25
- reminder: BASE_URL + '/reminders',
26
- transientDocument: BASE_URL + '/transientDocuments',
27
- libraryDocument: BASE_URL + '/libraryDocuments',
28
- widget: BASE_URL + '/widgets'
29
- }
30
-
31
- # Retrieves the authentication token
32
- #
33
- # @param credentials [Echosign::Credentials] Initialized Echosign::Credentials
34
- # @return [String] Valid authentication token
35
- def self.get_token(credentials)
36
- headers = {}
37
- response = post(ENDPOINT.fetch(:token), credentials, headers)
38
- response_body = JSON.parse(response.body)
39
- response_body.fetch("access_token")
16
+ BASE_URL = 'https://api.echosign.com/'
17
+ BASE_PATH = 'api/rest/v5'
18
+
19
+ class EndpointHash
20
+ def initialize(paths)
21
+ @paths = paths
22
+ end
23
+
24
+ # Get an endpoint by name, using the given base_uri
25
+ #
26
+ # @param endpoint [Symbol] A legal endpoint name, as a symbol
27
+ # @param base_uri [String] A URI that was retrieved from the base_uris API
28
+ # @return [String] Returns a URL for the endpoint that begins with the base_uri
29
+ def fetch(endpoint, base_uri)
30
+ File.join(base_uri, BASE_PATH, @paths.fetch(endpoint))
31
+ end
40
32
  end
41
33
 
42
- # Retrieves the authentication token
43
- #
44
- # @param credentials [Echosign::Credentials] Initialized Echosign::Credentials
45
- # @return [String] Valid authentication token
46
- def self.get_token_from_refresh(credentials)
47
- # headers = { :content_type => "application/x-www-form-urlencoded" }
48
- headers = {}
49
- response = post(ENDPOINT.fetch(:refresh), credentials, headers)
50
- response_body = JSON.parse(response.body)
51
- response_body.fetch("access_token")
34
+ ENDPOINT = EndpointHash.new({
35
+ base_uri: '/base_uris',
36
+ transientDocument: '/transientDocuments',
37
+ agreement: '/agreements',
38
+ reminder: '/reminders',
39
+ user: '/users',
40
+ libraryDocument: '/libraryDocuments',
41
+ widget: '/widgets',
42
+ view: '/views',
43
+ search: '/search',
44
+ workflow: '/workflows',
45
+ group: '/groups',
46
+ megaSign: '/megaSigns',
47
+ }).freeze
48
+
49
+ def self.get_base_uris(token)
50
+ endpoint = ENDPOINT.fetch(:base_uri, BASE_URL)
51
+ headers = { 'Access-Token' => token }
52
+ response = get(endpoint, headers)
53
+ JSON.parse(response.body)
52
54
  end
53
55
 
54
56
  # Performs REST create_user operation
@@ -56,23 +58,23 @@ module Echosign::Request
56
58
  # @param body [Hash] Valid request body
57
59
  # @param token [String] Auth Token
58
60
  # @return [Hash] New user response body
59
- def self.create_user(body, token)
60
- endpoint = ENDPOINT.fetch(:user)
61
- headers = { 'Access-Token' => token}
61
+ def self.create_user(token, base_uri, body)
62
+ endpoint = ENDPOINT.fetch(:user, base_uri)
63
+ headers = { 'Access-Token' => token }
62
64
  response = post(endpoint, body, headers)
63
65
  JSON.parse(response.body)
64
66
  end
65
-
67
+
66
68
  # Sends a reminder for an agreement.
67
69
  #
68
70
  # @param body [Hash] Valid request body
69
71
  # @param token [String] Auth Token
70
72
  # @return [Hash] Response body
71
- def self.create_reminder(token, body)
72
- endpoint = ENDPOINT.fetch(:reminder)
73
- headers = { 'Access-Token' => token}
74
- response = post(endpoint, body, headers)
75
- JSON.parse(response.body)
73
+ def self.create_reminder(token, base_uri, body)
74
+ endpoint = ENDPOINT.fetch(:reminder, base_uri)
75
+ headers = { 'Access-Token' => token }
76
+ response = post(endpoint, body, headers)
77
+ JSON.parse(response.body)
76
78
  end
77
79
 
78
80
  # Performs REST create_transient_document operation
@@ -82,70 +84,79 @@ module Echosign::Request
82
84
  # @param file_handle [File] File handle (REQUIRED)
83
85
  # @param mime_type [String] Mime type
84
86
  # @return [Hash] Transient Document Response Body
85
- def self.create_transient_document(token, file_name, file_handle, mime_type=nil)
87
+ def self.create_transient_document(token, base_uri, file_name, file_handle, mime_type = nil)
86
88
  headers = { 'Access-Token' => token }
89
+ if file_handle.is_a?(String)
90
+ raise "Cannot find file: #{file_handle}" unless File.exist?(file_handle)
87
91
 
88
- begin
89
- response = HTTParty.post(
90
- ENDPOINT.fetch(:transientDocument),
91
- { 'File-Name' => file_name,
92
- 'Mime-Type' => mime_type,
93
- 'File' => file_handle,
94
- :multipart => true},
95
- headers
96
- )
97
- rescue Exception => error
98
- raise_error(error)
92
+ file_handle = File.new(file_handle)
99
93
  end
94
+ body = { 'File-Name' => file_name, 'Mime-Type' => mime_type, 'File' => file_handle }
95
+ response = post(ENDPOINT.fetch(:transientDocument, base_uri), body, headers)
100
96
 
101
97
  JSON.parse(response.body)
102
98
  end
103
99
 
104
- # Gets all the users in an account that the caller has permissions to access.
100
+ # Gets all the users in an account that the caller has permissions to access.
105
101
  #
106
102
  # @param token [String] Auth Token
107
103
  # @param user_email [String] The email address of the user whose details are being requested.
108
104
  # @return [Hash] User info hash
109
- def self.get_users(token, user_email)
105
+ def self.get_users(token, base_uri, user_email)
110
106
  headers = { 'Access-Token' => token }
111
- endpoint = "#{ENDPOINT.fetch(:user)}?x-user-email=#{user_email}"
107
+ endpoint = "#{ENDPOINT.fetch(:user, base_uri)}?x-user-email=#{user_email}"
112
108
  response = get(endpoint, headers)
113
- JSON.parse(response)
109
+ JSON.parse(response.body)
114
110
  end
115
111
 
116
- # Gets all the users in an account that the caller has permissions to access.
112
+ # Gets all the users in an account that the caller has permissions to access.
117
113
  #
118
114
  # @param token [String] Auth Token
119
115
  # @param user_id [String]
120
116
  # @return [Hash] User info hash
121
- def self.get_user(token, user_id)
117
+ def self.get_user(token, base_uri, user_id)
122
118
  headers = { 'Access-Token' => token }
123
- endpoint = "#{ENDPOINT.fetch(:user)}/#{user_id}"
119
+ endpoint = "#{ENDPOINT.fetch(:user, base_uri)}/#{user_id}"
124
120
  response = get(endpoint, headers)
125
- JSON.parse(response)
121
+ JSON.parse(response.body)
126
122
  end
127
123
 
128
-
129
124
  private
130
125
 
131
126
  def self.get(endpoint, headers)
127
+ # puts "[Echosign] #{endpoint}"
132
128
  begin
133
- HTTParty.get(
134
- endpoint,
129
+ response = HTTParty.get(
130
+ endpoint,
135
131
  headers: headers
136
132
  )
133
+ response
137
134
  rescue Exception => error
138
135
  raise_error(error)
139
136
  end
140
137
  end
141
138
 
142
- def self.post(endpoint, body, headers)
139
+ def self.post(endpoint, body, headers, options = {})
140
+ option = { json: false }.merge(options)
141
+ # puts "[Echosign] #{endpoint}"
142
+ # puts "[Echosign] #{body}"
143
143
  begin
144
- HTTParty.post(
145
- endpoint,
146
- query: body,
147
- headers: headers
148
- )
144
+ if options[:json]
145
+ headers['Content-Type'] = 'application/json'
146
+ body = body.to_json if body.is_a?(Hash)
147
+ end
148
+ response = HTTParty.post(endpoint, body: body, headers: headers)
149
+ response
150
+ rescue Exception => error
151
+ raise_error(error)
152
+ end
153
+ end
154
+
155
+ def self.put(endpoint, query, headers)
156
+ begin
157
+ headers['Content-Type'] = 'application/json'
158
+ response = HTTParty.put(endpoint, body: query, headers: headers)
159
+ response
149
160
  rescue Exception => error
150
161
  raise_error(error)
151
162
  end
@@ -157,9 +168,8 @@ module Echosign::Request
157
168
 
158
169
  def self.raise_error(error)
159
170
  puts error
160
- message = "#{error.inspect}. \nSee Adobe Echosign REST API documentation for Error code meanings: https://secure.echosign.com/public/docs/restapi/v5"
171
+ message = "#{error.inspect}. \nSee Adobe Echosign REST API documentation for Error code meanings: " \
172
+ "https://secure.echosign.com/public/docs/restapi/v5"
161
173
  raise Failure.new message, error
162
174
  end
163
-
164
175
  end
165
-
@@ -1,6 +1,5 @@
1
1
  module Echosign
2
2
  class User < Hash
3
-
4
3
  include Validatable
5
4
 
6
5
  # Creates a user for the current application
@@ -10,20 +9,27 @@ module Echosign
10
9
  # @option params [String] :password The new user's password (REQUIRED)
11
10
  # @option params [String] :firstName The first name of the new user (REQUIRED)
12
11
  # @option params [String] :lastName The last name of the new user (REQUIRED)
13
- # @option params [String] :optIn 'YES' or 'NO' or 'UNKNOWN': Whether or not the user has opted in to recieve marketing information from EchoSign and its partners. Default value is UNKNOWN
14
- # @option params [String] :groupId Group in which the new user should be added. It can be obtained through GET /users call. Default is Group of the user making this call. The user is inferred from the access_token header
12
+ # @option params [String] :optIn 'YES' or 'NO' or 'UNKNOWN': Whether or not the user has opted in to recieve
13
+ # marketing information from EchoSign and its partners. Default value is UNKNOWN
14
+ # @option params [String] :groupId Group in which the new user should be added. It can be obtained through GET
15
+ # /users call. Default is Group of the user making this call. The user is inferred from the access_token header
15
16
  # @option params [String] :title The new user's job title
16
17
  # @option params [String] :phone The phone number of the new user
17
18
  # @option params [String] :company The name of the new user's company
18
- # @option params [String] :customField1 You can choose to use custom fields to record additional information about your new users. These fields are, however, available only with customized implementations - please contact EchoSign if you would like to make use of this functionality
19
- # @option params [String] :customField2 You can choose to use custom fields to record additional information about your new users. These fields are, however, available only with customized implementations - please contact EchoSign if you would like to make use of this functionality
20
- # @option params [String] :customField3 You can choose to use custom fields to record additional information about your new users. These fields are, however, available only with customized implementations - please contact EchoSign if you would like to make use of this functionality
19
+ # @option params [String] :customField1 You can choose to use custom fields to record additional information
20
+ # about your new users. These fields are, however, available only with customized implementations - please
21
+ # contact EchoSign if you would like to make use of this functionality
22
+ # @option params [String] :customField2 You can choose to use custom fields to record additional information
23
+ # about your new users. These fields are, however, available only with customized implementations - please
24
+ # contact EchoSign if you would like to make use of this functionality
25
+ # @option params [String] :customField3 You can choose to use custom fields to record additional information
26
+ # about your new users. These fields are, however, available only with customized implementations - please
27
+ # contact EchoSign if you would like to make use of this functionality
21
28
  # @return [String] User ID
22
29
 
23
30
  def initialize(params)
24
31
  require_keys([:firstName, :lastName, :email, :password], params)
25
32
  merge!(params)
26
33
  end
27
-
28
34
  end # class User
29
35
  end # module Echosign