docusign_maestro 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +35 -0
  3. data/README.md +230 -0
  4. data/docusign_maestro.gemspec +48 -0
  5. data/lib/docusign_maestro/api/workflow_instance_management_api.rb +248 -0
  6. data/lib/docusign_maestro/api/workflow_management_api.rb +440 -0
  7. data/lib/docusign_maestro/api/workflow_trigger_api.rb +95 -0
  8. data/lib/docusign_maestro/client/api_client.rb +600 -0
  9. data/lib/docusign_maestro/client/api_error.rb +37 -0
  10. data/lib/docusign_maestro/client/auth/oauth.rb +1061 -0
  11. data/lib/docusign_maestro/configuration.rb +203 -0
  12. data/lib/docusign_maestro/models/access_token_response.rb +204 -0
  13. data/lib/docusign_maestro/models/access_token_token_types.rb +30 -0
  14. data/lib/docusign_maestro/models/account_id.rb +175 -0
  15. data/lib/docusign_maestro/models/aow_uuid.rb +174 -0
  16. data/lib/docusign_maestro/models/aow_uuid_string.rb +174 -0
  17. data/lib/docusign_maestro/models/cancel_response.rb +197 -0
  18. data/lib/docusign_maestro/models/create_or_update_workflow_definition_request_body.rb +184 -0
  19. data/lib/docusign_maestro/models/deploy_request.rb +188 -0
  20. data/lib/docusign_maestro/models/deploy_response.rb +220 -0
  21. data/lib/docusign_maestro/models/deploy_status.rb +30 -0
  22. data/lib/docusign_maestro/models/deployment_status.rb +33 -0
  23. data/lib/docusign_maestro/models/ds_do_until_step.rb +247 -0
  24. data/lib/docusign_maestro/models/ds_doc_gen_step.rb +261 -0
  25. data/lib/docusign_maestro/models/ds_doc_gen_step_input.rb +246 -0
  26. data/lib/docusign_maestro/models/ds_idv_step.rb +261 -0
  27. data/lib/docusign_maestro/models/ds_idv_step_input.rb +234 -0
  28. data/lib/docusign_maestro/models/ds_if_else_step.rb +264 -0
  29. data/lib/docusign_maestro/models/ds_loop_step.rb +247 -0
  30. data/lib/docusign_maestro/models/ds_parallel_step.rb +246 -0
  31. data/lib/docusign_maestro/models/ds_service_step.rb +175 -0
  32. data/lib/docusign_maestro/models/ds_sign_step.rb +261 -0
  33. data/lib/docusign_maestro/models/ds_sign_step_input.rb +241 -0
  34. data/lib/docusign_maestro/models/ds_step_id.rb +175 -0
  35. data/lib/docusign_maestro/models/ds_transformation_step.rb +279 -0
  36. data/lib/docusign_maestro/models/ds_web_forms_step.rb +265 -0
  37. data/lib/docusign_maestro/models/ds_web_forms_step_config.rb +188 -0
  38. data/lib/docusign_maestro/models/ds_workflow_boolean_expression.rb +219 -0
  39. data/lib/docusign_maestro/models/ds_workflow_comparison_expression.rb +232 -0
  40. data/lib/docusign_maestro/models/ds_workflow_comparison_operator_types.rb +39 -0
  41. data/lib/docusign_maestro/models/ds_workflow_concat_expression.rb +200 -0
  42. data/lib/docusign_maestro/models/ds_workflow_doc_gen_doc_output_format.rb +29 -0
  43. data/lib/docusign_maestro/models/ds_workflow_expression_types_boolean_expression.rb +28 -0
  44. data/lib/docusign_maestro/models/ds_workflow_expression_types_comparison_expression.rb +28 -0
  45. data/lib/docusign_maestro/models/ds_workflow_expression_types_parallel_expression.rb +28 -0
  46. data/lib/docusign_maestro/models/ds_workflow_index_of_expression.rb +218 -0
  47. data/lib/docusign_maestro/models/ds_workflow_lane.rb +205 -0
  48. data/lib/docusign_maestro/models/ds_workflow_lanes_record.rb +174 -0
  49. data/lib/docusign_maestro/models/ds_workflow_last_index_of_expression.rb +218 -0
  50. data/lib/docusign_maestro/models/ds_workflow_logical_operator_types.rb +29 -0
  51. data/lib/docusign_maestro/models/ds_workflow_parallel_expression.rb +204 -0
  52. data/lib/docusign_maestro/models/ds_workflow_participant_record.rb +175 -0
  53. data/lib/docusign_maestro/models/ds_workflow_replace_expression.rb +233 -0
  54. data/lib/docusign_maestro/models/ds_workflow_step.rb +175 -0
  55. data/lib/docusign_maestro/models/ds_workflow_step_types_do_until.rb +28 -0
  56. data/lib/docusign_maestro/models/ds_workflow_step_types_ds_doc_gen.rb +28 -0
  57. data/lib/docusign_maestro/models/ds_workflow_step_types_ds_idv.rb +28 -0
  58. data/lib/docusign_maestro/models/ds_workflow_step_types_ds_if_else.rb +28 -0
  59. data/lib/docusign_maestro/models/ds_workflow_step_types_ds_sign.rb +28 -0
  60. data/lib/docusign_maestro/models/ds_workflow_step_types_ds_transformation.rb +28 -0
  61. data/lib/docusign_maestro/models/ds_workflow_step_types_ds_web_forms.rb +28 -0
  62. data/lib/docusign_maestro/models/ds_workflow_step_types_loop.rb +28 -0
  63. data/lib/docusign_maestro/models/ds_workflow_step_types_parallel.rb +28 -0
  64. data/lib/docusign_maestro/models/ds_workflow_substring_expression.rb +228 -0
  65. data/lib/docusign_maestro/models/ds_workflow_to_lower_expression.rb +203 -0
  66. data/lib/docusign_maestro/models/ds_workflow_to_upper_expression.rb +203 -0
  67. data/lib/docusign_maestro/models/ds_workflow_transformation_expression.rb +175 -0
  68. data/lib/docusign_maestro/models/ds_workflow_transformation_expression_types_concat_expression.rb +28 -0
  69. data/lib/docusign_maestro/models/ds_workflow_transformation_expression_types_index_of_expression.rb +28 -0
  70. data/lib/docusign_maestro/models/ds_workflow_transformation_expression_types_last_index_of_expression.rb +28 -0
  71. data/lib/docusign_maestro/models/ds_workflow_transformation_expression_types_replace_expression.rb +28 -0
  72. data/lib/docusign_maestro/models/ds_workflow_transformation_expression_types_substring_expression.rb +28 -0
  73. data/lib/docusign_maestro/models/ds_workflow_transformation_expression_types_to_lower_expression.rb +28 -0
  74. data/lib/docusign_maestro/models/ds_workflow_transformation_expression_types_to_upper_expression.rb +28 -0
  75. data/lib/docusign_maestro/models/ds_workflow_trigger.rb +274 -0
  76. data/lib/docusign_maestro/models/ds_workflow_trigger_types.rb +29 -0
  77. data/lib/docusign_maestro/models/ds_workflow_variable.rb +175 -0
  78. data/lib/docusign_maestro/models/ds_workflow_variable_from_participant.rb +217 -0
  79. data/lib/docusign_maestro/models/ds_workflow_variable_from_step.rb +231 -0
  80. data/lib/docusign_maestro/models/ds_workflow_variable_from_variable.rb +231 -0
  81. data/lib/docusign_maestro/models/ds_workflow_variable_record.rb +175 -0
  82. data/lib/docusign_maestro/models/ds_workflow_variable_source_types_participant.rb +28 -0
  83. data/lib/docusign_maestro/models/ds_workflow_variable_source_types_step.rb +28 -0
  84. data/lib/docusign_maestro/models/ds_workflow_variable_source_types_variable.rb +28 -0
  85. data/lib/docusign_maestro/models/e_sign_document_from_e_sign_template.rb +231 -0
  86. data/lib/docusign_maestro/models/e_sign_document_from_previous_step.rb +232 -0
  87. data/lib/docusign_maestro/models/e_sign_document_types_from_ds_template.rb +28 -0
  88. data/lib/docusign_maestro/models/e_sign_document_types_from_previous_step.rb +28 -0
  89. data/lib/docusign_maestro/models/e_sign_documents.rb +175 -0
  90. data/lib/docusign_maestro/models/e_sign_locale_policy.rb +174 -0
  91. data/lib/docusign_maestro/models/e_sign_signer.rb +247 -0
  92. data/lib/docusign_maestro/models/e_sign_tabs.rb +416 -0
  93. data/lib/docusign_maestro/models/e_sign_tabs_record.rb +251 -0
  94. data/lib/docusign_maestro/models/error_codes.rb +44 -0
  95. data/lib/docusign_maestro/models/error_response.rb +193 -0
  96. data/lib/docusign_maestro/models/event_types.rb +31 -0
  97. data/lib/docusign_maestro/models/get_configuration_instance_response.rb +201 -0
  98. data/lib/docusign_maestro/models/get_configuration_instances_response.rb +203 -0
  99. data/lib/docusign_maestro/models/get_configuration_instances_response_config_instances.rb +192 -0
  100. data/lib/docusign_maestro/models/http_types.rb +31 -0
  101. data/lib/docusign_maestro/models/invalid_workflow_response.rb +204 -0
  102. data/lib/docusign_maestro/models/last_deployed_id.rb +174 -0
  103. data/lib/docusign_maestro/models/new_or_updated_workflow_definition_response.rb +232 -0
  104. data/lib/docusign_maestro/models/number_or_variable.rb +175 -0
  105. data/lib/docusign_maestro/models/participant.rb +231 -0
  106. data/lib/docusign_maestro/models/participant_keys.rb +30 -0
  107. data/lib/docusign_maestro/models/progress_instance.rb +205 -0
  108. data/lib/docusign_maestro/models/record_string_boolean.rb +174 -0
  109. data/lib/docusign_maestro/models/record_string_or_variable_or_transformation.rb +175 -0
  110. data/lib/docusign_maestro/models/record_to_never.rb +174 -0
  111. data/lib/docusign_maestro/models/replication_status.rb +37 -0
  112. data/lib/docusign_maestro/models/started_by_instance.rb +237 -0
  113. data/lib/docusign_maestro/models/string_or_variable_or_transformation.rb +175 -0
  114. data/lib/docusign_maestro/models/success_message_response.rb +184 -0
  115. data/lib/docusign_maestro/models/template_id.rb +175 -0
  116. data/lib/docusign_maestro/models/trigger_payload.rb +211 -0
  117. data/lib/docusign_maestro/models/trigger_workflow_via_post_response.rb +194 -0
  118. data/lib/docusign_maestro/models/user_id.rb +175 -0
  119. data/lib/docusign_maestro/models/validation_errors.rb +202 -0
  120. data/lib/docusign_maestro/models/version_string.rb +174 -0
  121. data/lib/docusign_maestro/models/workflow_creator_id.rb +175 -0
  122. data/lib/docusign_maestro/models/workflow_date_time.rb +174 -0
  123. data/lib/docusign_maestro/models/workflow_definition.rb +315 -0
  124. data/lib/docusign_maestro/models/workflow_definition_list.rb +197 -0
  125. data/lib/docusign_maestro/models/workflow_definition_metadata.rb +272 -0
  126. data/lib/docusign_maestro/models/workflow_definition_with_id.rb +292 -0
  127. data/lib/docusign_maestro/models/workflow_delete_response.rb +202 -0
  128. data/lib/docusign_maestro/models/workflow_instance.rb +304 -0
  129. data/lib/docusign_maestro/models/workflow_instance_id.rb +175 -0
  130. data/lib/docusign_maestro/models/workflow_instance_map.rb +174 -0
  131. data/lib/docusign_maestro/models/workflow_instance_state.rb +30 -0
  132. data/lib/docusign_maestro/models/workflow_instances_list.rb +175 -0
  133. data/lib/docusign_maestro/models/workflow_metadata_status.rb +33 -0
  134. data/lib/docusign_maestro/models/workflow_step_error.rb +224 -0
  135. data/lib/docusign_maestro/models/workflow_step_error_error.rb +194 -0
  136. data/lib/docusign_maestro/models/workflow_step_history.rb +298 -0
  137. data/lib/docusign_maestro/models/workflow_step_history_list.rb +175 -0
  138. data/lib/docusign_maestro/models/workflow_step_history_state.rb +30 -0
  139. data/lib/docusign_maestro/version.rb +14 -0
  140. data/lib/docusign_maestro.rb +160 -0
  141. data/runLinter.sh +1 -0
  142. metadata +446 -0
@@ -0,0 +1,600 @@
1
+ =begin
2
+ #Maestro API
3
+
4
+ #Maestro authors and executes experiences that allow non-coders the ability to define Simple Business Process without having to write code and to deploy them seamlessly without having to have development expertise
5
+
6
+ OpenAPI spec version: 1.0.0
7
+ Contact: devcenter@docusign.com
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+
10
+ =end
11
+
12
+ require 'date'
13
+ require 'json'
14
+ require 'logger'
15
+ require 'tempfile'
16
+ require 'typhoeus'
17
+ require 'uri'
18
+ require 'jwt'
19
+ require 'addressable/uri'
20
+
21
+ module DocuSign_Maestro
22
+ class ApiClient
23
+ # The Configuration object holding settings to be used in the API client.
24
+ attr_accessor :config
25
+
26
+ # Defines the headers to be used in HTTP requests of all API calls by default.
27
+ #
28
+ # @return [Hash]
29
+ attr_accessor :default_headers
30
+
31
+ attr_accessor :base_path
32
+ attr_accessor :oauth_base_path
33
+
34
+ # Initializes the ApiClient
35
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
36
+ def initialize(config = Configuration.default)
37
+ @config = config
38
+ @user_agent = "Swagger-Codegen/1.0.0/1.0.0.rc1/ruby-#{RUBY_VERSION}p#{RUBY_PATCHLEVEL}"
39
+ @default_headers = {
40
+ 'Content-Type' => "application/json",
41
+ 'User-Agent' => @user_agent
42
+ }
43
+ end
44
+
45
+ def self.default
46
+ @@default ||= ApiClient.new
47
+ end
48
+
49
+ # Call an API with given options.
50
+ #
51
+ # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
52
+ # the data deserialized from response body (could be nil), response status code and response headers.
53
+ def call_api(http_method, path, opts = {})
54
+ request = build_request(http_method, path, opts)
55
+ response = request.run
56
+
57
+ if @config.debugging
58
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
59
+ end
60
+
61
+ unless response.success?
62
+ if response.timed_out?
63
+ fail ApiError.new('Connection timed out')
64
+ elsif response.code == 0
65
+ # Errors from libcurl will be made visible here
66
+ fail ApiError.new(:code => 0,
67
+ :message => response.return_message)
68
+ else
69
+ fail ApiError.new(:code => response.code,
70
+ :response_headers => response.headers,
71
+ :response_body => response.body),
72
+ response.status_message
73
+ end
74
+ end
75
+
76
+ if opts[:return_type]
77
+ data = deserialize(response, opts[:return_type])
78
+ else
79
+ data = nil
80
+ end
81
+ return data, response.code, response.headers
82
+ end
83
+
84
+ # Builds the HTTP request
85
+ #
86
+ # @param [String] http_method HTTP method/verb (e.g. POST)
87
+ # @param [String] path URL path (e.g. /account/new)
88
+ # @option opts [Hash] :header_params Header parameters
89
+ # @option opts [Hash] :query_params Query parameters
90
+ # @option opts [Hash] :form_params Query parameters
91
+ # @option opts [Object] :body HTTP body (JSON/XML)
92
+ # @return [Typhoeus::Request] A Typhoeus Request
93
+ def build_request(http_method, path, opts = {})
94
+ url = build_request_url(path, opts)
95
+ http_method = http_method.to_sym.downcase
96
+
97
+ header_params = @default_headers.merge(opts[:header_params] || {})
98
+
99
+ # Add SDK default header
100
+ header_params.store("X-DocuSign-SDK", "Ruby")
101
+
102
+ query_params = opts[:query_params] || {}
103
+ form_params = opts[:form_params] || {}
104
+
105
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
106
+
107
+ # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
108
+ _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
109
+
110
+ req_opts = {
111
+ :method => http_method,
112
+ :headers => header_params,
113
+ :params => query_params,
114
+ :params_encoding => @config.params_encoding,
115
+ :timeout => @config.timeout,
116
+ :ssl_verifypeer => @config.verify_ssl,
117
+ :ssl_verifyhost => _verify_ssl_host,
118
+ :sslcert => @config.cert_file,
119
+ :sslkey => @config.key_file,
120
+ :verbose => @config.debugging
121
+ }
122
+
123
+ # set custom cert, if provided
124
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
125
+
126
+ if [:post, :patch, :put, :delete].include?(http_method)
127
+ req_body = build_request_body(header_params, form_params, opts[:body])
128
+ req_opts.update :body => req_body
129
+ if @config.debugging
130
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
131
+ end
132
+ end
133
+
134
+ Typhoeus::Request.new(url, req_opts)
135
+ end
136
+
137
+ # Check if the given MIME is a JSON MIME.
138
+ # JSON MIME examples:
139
+ # application/json
140
+ # application/json; charset=UTF8
141
+ # APPLICATION/JSON
142
+ # */*
143
+ # @param [String] mime MIME
144
+ # @return [Boolean] True if the MIME is application/json
145
+ def json_mime?(mime)
146
+ (mime == "*/*") || !(mime =~ /\Aapplication\/json(;.*)?\z/i).nil?
147
+ end
148
+
149
+ # Deserialize the response to the given return type.
150
+ #
151
+ # @param [Response] response HTTP response
152
+ # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
153
+ def deserialize(response, return_type)
154
+ body = response.body
155
+ return nil if body.nil? || body.empty?
156
+
157
+ # return response body directly for String return type
158
+ return body if return_type == 'String'
159
+
160
+ # handle file downloading - save response body into a tmp file and return the File instance
161
+ return download_file(response) if return_type == 'File'
162
+
163
+ # ensuring a default content type
164
+ content_type = response.headers['Content-Type'] || 'application/json'
165
+
166
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
167
+
168
+ begin
169
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
170
+ rescue JSON::ParserError => e
171
+ if %w(String Date DateTime).include?(return_type)
172
+ data = body
173
+ else
174
+ raise e
175
+ end
176
+ end
177
+
178
+ convert_to_type data, return_type
179
+ end
180
+
181
+ # Convert data to the given return type.
182
+ # @param [Object] data Data to be converted
183
+ # @param [String] return_type Return type
184
+ # @return [Mixed] Data in a particular type
185
+ def convert_to_type(data, return_type)
186
+ return nil if data.nil?
187
+ case return_type
188
+ when 'String'
189
+ data.to_s
190
+ when 'Integer'
191
+ data.to_i
192
+ when 'Float'
193
+ data.to_f
194
+ when 'BOOLEAN'
195
+ data == true
196
+ when 'DateTime'
197
+ # parse date time (expecting ISO 8601 format)
198
+ DateTime.parse data
199
+ when 'Date'
200
+ # parse date time (expecting ISO 8601 format)
201
+ Date.parse data
202
+ when 'Object'
203
+ # generic object (usually a Hash), return directly
204
+ data
205
+ when /\AArray<(.+)>\z/
206
+ # e.g. Array<Pet>
207
+ sub_type = $1
208
+ data.map {|item| convert_to_type(item, sub_type) }
209
+ when /\AHash\<String, (.+)\>\z/
210
+ # e.g. Hash<String, Integer>
211
+ sub_type = $1
212
+ {}.tap do |hash|
213
+ data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
214
+ end
215
+ else
216
+ # models, e.g. Pet
217
+ DocuSign_Maestro.const_get(return_type).new.tap do |model|
218
+ model.build_from_hash data
219
+ end
220
+ end
221
+ end
222
+
223
+ # Save response body into a file in (the defined) temporary folder, using the filename
224
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
225
+ #
226
+ # @see Configuration#temp_folder_path
227
+ # @return [Tempfile] the file downloaded
228
+ def download_file(response)
229
+ content_disposition = response.headers['Content-Disposition']
230
+ if content_disposition and content_disposition =~ /filename=/i
231
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
232
+ prefix = sanitize_filename(filename)
233
+ else
234
+ prefix = 'download-'
235
+ end
236
+ prefix = prefix + '-' unless prefix.end_with?('-')
237
+
238
+ tempfile = nil
239
+ encoding = response.body.encoding
240
+ Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) do |file|
241
+ file.write(response.body)
242
+ tempfile = file
243
+ end
244
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
245
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
246
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
247
+ "explicitly with `tempfile.delete`"
248
+ tempfile
249
+ end
250
+
251
+ # Sanitize filename by removing path.
252
+ # e.g. ../../sun.gif becomes sun.gif
253
+ #
254
+ # @param [String] filename the filename to be sanitized
255
+ # @return [String] the sanitized filename
256
+ def sanitize_filename(filename)
257
+ filename.gsub(/.*[\/\\]/, '')
258
+ end
259
+
260
+ def build_request_url(path, opts)
261
+ # Add leading and trailing slashes to path
262
+ path = "/#{path}".gsub(/\/+/, '/')
263
+ return Addressable::URI.encode("https://" + self.get_oauth_base_path + path) if opts[:oauth]
264
+ Addressable::URI.encode(@config.base_url + path)
265
+ end
266
+
267
+ # Builds the HTTP request body
268
+ #
269
+ # @param [Hash] header_params Header parameters
270
+ # @param [Hash] form_params Query parameters
271
+ # @param [Object] body HTTP body (JSON/XML)
272
+ # @return [String] HTTP body data in the form of string
273
+ def build_request_body(header_params, form_params, body)
274
+ # http form
275
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
276
+ header_params['Content-Type'] == 'multipart/form-data'
277
+ data = {}
278
+ form_params.each do |key, value|
279
+ case value
280
+ when File, Array, nil
281
+ # let typhoeus handle File, Array and nil parameters
282
+ data[key] = value
283
+ else
284
+ if header_params['Content-Type'] == 'multipart/form-data'
285
+ header_params['Content-Disposition'] = 'form-data; name=file; filename=' + key
286
+ data = value
287
+ else
288
+ data[key] = value.to_s
289
+ end
290
+ end
291
+ end
292
+ elsif body
293
+ data = body.is_a?(String) ? body : body.to_json
294
+ else
295
+ data = nil
296
+ end
297
+ data
298
+ end
299
+
300
+ # Update hearder and query params based on authentication settings.
301
+ #
302
+ # @param [Hash] header_params Header parameters
303
+ # @param [Hash] query_params Query parameters
304
+ # @param [String] auth_names Authentication scheme name
305
+ def update_params_for_auth!(header_params, query_params, auth_names)
306
+ Array(auth_names).each do |auth_name|
307
+ auth_setting = @config.auth_settings[auth_name]
308
+ next unless auth_setting
309
+ case auth_setting[:in]
310
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
311
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
312
+ else fail ArgumentError, 'Authentication token must be in `query` of `header`'
313
+ end
314
+ end
315
+ end
316
+
317
+ # Sets user agent in HTTP header
318
+ #
319
+ # @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
320
+ def user_agent=(user_agent)
321
+ @user_agent = user_agent
322
+ @default_headers['User-Agent'] = @user_agent
323
+ end
324
+
325
+ # Return Accept header based on an array of accepts provided.
326
+ # @param [Array] accepts array for Accept
327
+ # @return [String] the Accept header (e.g. application/json)
328
+ def select_header_accept(accepts)
329
+ return nil if accepts.nil? || accepts.empty?
330
+ # use JSON when present, otherwise use all of the provided
331
+ json_accept = accepts.find { |s| json_mime?(s) }
332
+ return json_accept || accepts.join(',')
333
+ end
334
+
335
+ # Return Content-Type header based on an array of content types provided.
336
+ # @param [Array] content_types array for Content-Type
337
+ # @return [String] the Content-Type header (e.g. application/json)
338
+ def select_header_content_type(content_types)
339
+ # use application/json by default
340
+ return 'application/json' if content_types.nil? || content_types.empty?
341
+ # use JSON when present, otherwise use the first one
342
+ json_content_type = content_types.find { |s| json_mime?(s) }
343
+ return json_content_type || content_types.first
344
+ end
345
+
346
+ # Convert object (array, hash, object, etc) to JSON string.
347
+ # @param [Object] model object to be converted into JSON string
348
+ # @return [String] JSON string representation of the object
349
+ def object_to_http_body(model)
350
+ return model if model.nil? || model.is_a?(String)
351
+ local_body = nil
352
+ if model.is_a?(Array)
353
+ local_body = model.map{|m| object_to_hash(m) }
354
+ else
355
+ local_body = object_to_hash(model)
356
+ end
357
+ local_body.to_json
358
+ end
359
+
360
+ # Convert object(non-array) to hash.
361
+ # @param [Object] obj object to be converted into JSON string
362
+ # @return [String] JSON string representation of the object
363
+ def object_to_hash(obj)
364
+ if obj.respond_to?(:to_hash)
365
+ obj.to_hash
366
+ else
367
+ obj
368
+ end
369
+ end
370
+
371
+ # Build parameter value according to the given collection format.
372
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
373
+ def build_collection_param(param, collection_format)
374
+ case collection_format
375
+ when :csv
376
+ param.join(',')
377
+ when :ssv
378
+ param.join(' ')
379
+ when :tsv
380
+ param.join("\t")
381
+ when :pipes
382
+ param.join('|')
383
+ when :multi
384
+ # return the array directly as typhoeus will handle it as expected
385
+ param
386
+ else
387
+ fail "unknown collection format: #{collection_format.inspect}"
388
+ end
389
+ end
390
+
391
+ # Helper method to set base_path
392
+ # @param [String] base_path
393
+ def set_base_path(base_path)
394
+ self.base_path = base_path
395
+ end
396
+
397
+ # Helper method to set oauth base path
398
+ # @param [String] oauth_base_path if passed nil it will determined from base_path
399
+ def set_oauth_base_path(oauth_base_path=nil)
400
+ if oauth_base_path
401
+ raise ArgumentError.new('OAuth base path should only include domain name (without https://)') if oauth_base_path.include? "//"
402
+ self.oauth_base_path = oauth_base_path
403
+ return
404
+ end
405
+
406
+ # did we need this check as we can determine it from base path
407
+ #raise ArgumentError.new('oAuthBasePath cannot be empty') unless oauth_base_path
408
+
409
+ # Derive OAuth Base Path if not given
410
+ if self.base_path.nil? or self.base_path.start_with?("https://demo") or self.base_path.start_with?("http://demo") or self.base_path.start_with?("https://apps-d") or self.base_path.start_with?("http://apps-d")
411
+ self.oauth_base_path = OAuth::DEMO_OAUTH_BASE_PATH
412
+ elsif self.base_path.start_with?("https://stage") or self.base_path.start_with?("http://stage") or self.base_path.start_with?("https://apps-s") or self.base_path.start_with?("http://apps-s")
413
+ self.oauth_base_path = OAuth::STAGE_OAUTH_BASE_PATH
414
+ else
415
+ self.oauth_base_path = OAuth::PRODUCTION_OAUTH_BASE_PATH
416
+ end
417
+ end
418
+
419
+ # Helper method to get oauth base path
420
+ def get_oauth_base_path
421
+ if !self.oauth_base_path
422
+ self.set_oauth_base_path()
423
+ end
424
+
425
+ self.oauth_base_path
426
+ end
427
+
428
+ # Helper method to configure the OAuth accessCode/implicit flow parameters
429
+ # @param [String] client_id DocuSign OAuth Client Id(AKA Integrator Key)
430
+ # @param scopes The list of requested scopes. Client applications may be scoped to a limited set of system access.
431
+ # @param [String] redirect_uri This determines where to deliver the response containing the authorization code
432
+ # @param [String] response_type Determines the response type of the authorization request, NOTE: these response types are mutually exclusive for a client application. A public/native client application may only request a response type
433
+ # of "token". A private/trusted client application may only request a response type of "code".
434
+ # @param [String] state Allows for arbitrary state that may be useful to your application. The value in this parameter
435
+ # will be round-tripped along with the response so you can make sure it didn't change.
436
+ # @return [String]
437
+ def get_authorization_uri(client_id, scopes, redirect_uri, response_type, state=nil)
438
+ self.oauth_base_path ||= self.get_oauth_base_path
439
+
440
+ scopes = scopes.join(' ') if scopes.kind_of?(Array)
441
+ scopes = OAuth::SCOPE_SIGNATURE if scopes.empty?
442
+
443
+ uri = "https://%{base_path}/oauth/auth?response_type=%{response_type}&scope=%{scopes}&client_id=%{client_id}&redirect_uri=%{redirect_uri}"
444
+ uri += "&state=%{state}" if state
445
+ uri % {base_path: self.oauth_base_path, response_type:response_type, scopes: scopes, client_id: client_id, redirect_uri: redirect_uri, state: state}
446
+ end
447
+
448
+ # Request JWT User Token
449
+ # @param [String] client_id DocuSign OAuth Client Id(AKA Integrator Key)
450
+ # @param [String] user_id DocuSign user Id to be impersonated
451
+ # @param [String] private_key_or_filename the RSA private key
452
+ # @param [Number] expires_in number of seconds remaining before the JWT assertion is considered as invalid
453
+ # @param scopes The list of requested scopes. Client applications may be scoped to a limited set of system access.
454
+ # @return [OAuth::OAuthToken]
455
+ def request_jwt_user_token(client_id, user_id, private_key_or_filename, expires_in = 3600,scopes=OAuth::SCOPE_SIGNATURE)
456
+ raise ArgumentError.new('client_id cannot be empty') if client_id.empty?
457
+ raise ArgumentError.new('user_id cannot be empty') if user_id.empty?
458
+ raise ArgumentError.new('private_key_or_filename cannot be empty') if private_key_or_filename.empty?
459
+
460
+ scopes = scopes.join(' ') if scopes.kind_of?(Array)
461
+ scopes = OAuth::SCOPE_SIGNATURE if scopes.empty?
462
+ expires_in = 3600 if expires_in > 3600
463
+ now = Time.now.to_i
464
+ claim = {
465
+ "iss" => client_id,
466
+ "sub" => user_id,
467
+ "aud" => self.get_oauth_base_path,
468
+ "iat" => now,
469
+ "exp" => now + expires_in,
470
+ "scope"=> scopes
471
+ }
472
+
473
+ private_key = if private_key_or_filename.include?("-----BEGIN RSA PRIVATE KEY-----")
474
+ private_key_or_filename
475
+ else
476
+ File.read(private_key_or_filename)
477
+ end
478
+
479
+ private_key_bytes = OpenSSL::PKey::RSA.new private_key
480
+ token = JWT.encode claim, private_key_bytes, 'RS256'
481
+ params = {
482
+ :header_params => {"Content-Type" => "application/x-www-form-urlencoded"},
483
+ :form_params => {
484
+ "assertion" => token,
485
+ "grant_type" => OAuth::GRANT_TYPE_JWT
486
+ },
487
+ :return_type => 'OAuth::OAuthToken',
488
+ :oauth => true
489
+ }
490
+ data, status_code, headers = self.call_api("POST", "/oauth/token", params)
491
+
492
+
493
+ raise ApiError.new('Some error accrued during process') if data.nil?
494
+
495
+ self.set_default_header('Authorization', data.token_type + ' ' + data.access_token)
496
+ data
497
+ end
498
+
499
+ # Request JWT User Token
500
+ # @param [String] client_id DocuSign OAuth Client Id(AKA Integrator Key)
501
+ # @param [String] private_key_or_filename the RSA private key
502
+ # @param [Number] expires_in number of seconds remaining before the JWT assertion is considered as invalid
503
+ # @param scopes The list of requested scopes. Client applications may be scoped to a limited set of system access.
504
+ # @return [OAuth::OAuthToken]
505
+ def request_jwt_application_token(client_id, private_key_or_filename, expires_in = 3600,scopes=OAuth::SCOPE_SIGNATURE)
506
+ raise ArgumentError.new('client_id cannot be empty') if client_id.empty?
507
+ raise ArgumentError.new('private_key_or_filename cannot be empty') if private_key_or_filename.empty?
508
+
509
+ scopes = scopes.join(' ') if scopes.kind_of?(Array)
510
+ scopes = OAuth::SCOPE_SIGNATURE if scopes.empty?
511
+ expires_in = 3600 if expires_in > 3600
512
+ now = Time.now.to_i
513
+ claim = {
514
+ "iss" => client_id,
515
+ "aud" => self.get_oauth_base_path,
516
+ "iat" => now,
517
+ "exp" => now + expires_in,
518
+ "scope"=> scopes
519
+ }
520
+
521
+ private_key = if private_key_or_filename.include?("-----BEGIN RSA PRIVATE KEY-----")
522
+ private_key_or_filename
523
+ else
524
+ File.read(private_key_or_filename)
525
+ end
526
+
527
+ private_key_bytes = OpenSSL::PKey::RSA.new private_key
528
+ token = JWT.encode claim, private_key_bytes, 'RS256'
529
+ params = {
530
+ :header_params => {"Content-Type" => "application/x-www-form-urlencoded"},
531
+ :form_params => {
532
+ "assertion" => token,
533
+ "grant_type" => OAuth::GRANT_TYPE_JWT
534
+ },
535
+ :return_type => 'OAuth::OAuthToken',
536
+ :oauth => true
537
+ }
538
+ data, status_code, headers = self.call_api("POST", "/oauth/token", params)
539
+
540
+ raise ApiError.new('Some error accrued during process') if data.nil?
541
+
542
+ self.set_default_header('Authorization', data.token_type + ' ' + data.access_token)
543
+ data
544
+ end
545
+
546
+ # Get User Info method takes the accessToken to retrieve User Account Data.
547
+ # @param [String] access_token
548
+ # @return [OAuth::UserInfo]
549
+ def get_user_info(access_token)
550
+ raise ArgumentError.new('Cannot find a valid access token. Cannot find a valid access token.') if access_token.empty?
551
+
552
+ params = {
553
+ :header_params => {"Authorization" => 'Bearer ' + access_token},
554
+ :return_type => 'OAuth::UserInfo',
555
+ :oauth => true
556
+ }
557
+ data, status_code, headers = self.call_api("GET", '/oauth/userinfo', params)
558
+ data
559
+ end
560
+
561
+ # GenerateAccessToken will exchange the authorization code for an access token and refresh tokens.
562
+ # @param [String] client_id DocuSign OAuth Client Id(AKA Integrator Key)
563
+ # @param [String] client_secret The secret key you generated when you set up the integration in DocuSign Admin console.
564
+ # @param [String] code The authorization code
565
+ def generate_access_token(client_id, client_secret, code)
566
+ raise ArgumentError.new('client_id cannot be empty') if client_id.empty?
567
+ raise ArgumentError.new('client_secret cannot be empty') if client_secret.empty?
568
+ raise ArgumentError.new('code cannot be empty') if code.empty?
569
+
570
+ authcode = "Basic " + Base64.strict_encode64("#{client_id}:#{client_secret}")
571
+ params = {
572
+ :header_params => {
573
+ "Authorization" => authcode,
574
+ "Content-Type" => "application/x-www-form-urlencoded"
575
+ },
576
+ :form_params => {
577
+ "grant_type" => 'authorization_code',
578
+ "code" => code,
579
+ },
580
+ :return_type => 'OAuth::OAuthToken',
581
+ :oauth => true
582
+ }
583
+
584
+ token, status_code, headers = self.call_api("POST", '/oauth/token', params)
585
+
586
+ if status_code == 200
587
+ self.default_headers.store('Authorization', "#{token.token_type} #{token.access_token}")
588
+
589
+ token
590
+ end
591
+ end
592
+
593
+ # Helper method to add default header params
594
+ # @param [String] header_name
595
+ # @param [String] header_value
596
+ def set_default_header(header_name, header_value)
597
+ @default_headers[header_name] = header_value
598
+ end
599
+ end
600
+ end
@@ -0,0 +1,37 @@
1
+ =begin
2
+ #Maestro API
3
+
4
+ #Maestro authors and executes experiences that allow non-coders the ability to define Simple Business Process without having to write code and to deploy them seamlessly without having to have development expertise
5
+
6
+ OpenAPI spec version: 1.0.0
7
+ Contact: devcenter@docusign.com
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+
10
+ =end
11
+
12
+ module DocuSign_Maestro
13
+ class ApiError < StandardError
14
+ attr_reader :code, :response_headers, :response_body
15
+
16
+ # Usage examples:
17
+ # ApiError.new
18
+ # ApiError.new("message")
19
+ # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
20
+ # ApiError.new(:code => 404, :message => "Not Found")
21
+ def initialize(arg = nil)
22
+ if arg.is_a? Hash
23
+ if arg.key?(:message) || arg.key?('message')
24
+ super(arg[:message] || arg['message'])
25
+ else
26
+ super arg
27
+ end
28
+
29
+ arg.each do |k, v|
30
+ instance_variable_set "@#{k}", v
31
+ end
32
+ else
33
+ super arg
34
+ end
35
+ end
36
+ end
37
+ end