docspring 1.4.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +26 -0
- data/.openapi-generator/FILES +220 -0
- data/.openapi-generator/VERSION +1 -1
- data/.rubocop.yml +6 -12
- data/.travis.yml +11 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +5 -1
- data/Gemfile.lock +85 -48
- data/README.md +47 -16
- data/docs/AddFieldsData.md +13 -3
- data/docs/AddFieldsTemplateResponse.md +17 -5
- data/docs/AuthenticationError.md +15 -4
- data/docs/AuthenticationSuccessResponse.md +13 -3
- data/docs/CombinePdfsData.md +23 -7
- data/docs/CombinedSubmission.md +37 -12
- data/docs/CombinedSubmissionAction.md +23 -8
- data/docs/CombinedSubmissionData.md +21 -6
- data/docs/CopyTemplateData.md +15 -4
- data/docs/CreateCombinedSubmissionResponse.md +17 -5
- data/docs/CreateCustomFileData.md +13 -3
- data/docs/CreateCustomFileResponse.md +17 -5
- data/docs/CreateFolderAttributes.md +20 -0
- data/docs/CreateFolderData.md +13 -3
- data/docs/CreateHtmlTemplateData.md +13 -3
- data/docs/CreateSubmissionBatchResponse.md +21 -7
- data/docs/CreateSubmissionBatchSubmissionsResponse.md +17 -5
- data/docs/CreateSubmissionData.md +36 -0
- data/docs/CreateSubmissionDataRequestData.md +37 -15
- data/docs/CreateSubmissionDataRequestEventRequest.md +24 -0
- data/docs/CreateSubmissionDataRequestEventResponse.md +22 -0
- data/docs/CreateSubmissionDataRequestTokenResponse.md +17 -5
- data/docs/CreateSubmissionResponse.md +17 -5
- data/docs/CreateTemplateFromUploadData.md +13 -3
- data/docs/DataRequestToken.md +24 -0
- data/docs/DeleteTemplateResponse.md +20 -0
- data/docs/ErrorResponse.md +20 -0
- data/docs/Folder.md +19 -6
- data/docs/FullTemplate.md +94 -0
- data/docs/HtmlTemplateData.md +51 -19
- data/docs/HtmlTemplateDataWebhookOptions.md +18 -0
- data/docs/InvalidRequest.md +15 -4
- data/docs/InvalidRequestSingleError.md +20 -0
- data/docs/ListSubmissionsResponse.md +22 -0
- data/docs/MoveFolderData.md +13 -3
- data/docs/MoveTemplateData.md +13 -3
- data/docs/PDFApi.md +1746 -495
- data/docs/PendingTemplate.md +45 -19
- data/docs/PreviewPdfResponse.md +20 -0
- data/docs/PublishTemplateVersion404Response.md +20 -0
- data/docs/PublishTemplateVersion422Response.md +20 -0
- data/docs/PublishTemplateVersionResponse.md +20 -0
- data/docs/PublishTemplateVersionResponseResult.md +24 -0
- data/docs/PublishVersionData.md +20 -0
- data/docs/RenameFolderData.md +13 -3
- data/docs/RestoreTemplateVersionResponse.md +18 -0
- data/docs/RestoreVersionData.md +18 -0
- data/docs/Submission.md +49 -21
- data/docs/SubmissionAction.md +23 -8
- data/docs/SubmissionBatch.md +29 -11
- data/docs/SubmissionBatchData.md +21 -6
- data/docs/SubmissionData.md +23 -9
- data/docs/SubmissionDataBatchRequest.md +25 -8
- data/docs/SubmissionDataRequest.md +53 -22
- data/docs/SubmissionDataRequestEvent.md +30 -0
- data/docs/Template.md +51 -22
- data/docs/TemplateData.md +49 -18
- data/docs/TemplateDefaults.md +22 -0
- data/docs/TemplateDocument.md +22 -0
- data/docs/TemplateDocumentMetadata.md +22 -0
- data/docs/TemplateSchema.md +34 -0
- data/docs/UpdateDataRequestResponse.md +17 -5
- data/docs/UpdateSubmissionDataRequestData.md +37 -15
- data/docs/UpdateTemplateData.md +13 -3
- data/docs/UpdateTemplateResponse.md +15 -4
- data/docs/UploadPresign.md +24 -0
- data/docs/UploadTemplateData.md +53 -20
- data/docspring.gemspec +14 -11
- data/git_push.sh +11 -9
- data/lib/docspring/api/pdf_api.rb +1485 -497
- data/lib/docspring/api_client.rb +106 -98
- data/lib/docspring/api_error.rb +22 -2
- data/lib/docspring/configuration.rb +127 -16
- data/lib/docspring/models/add_fields_data.rb +59 -26
- data/lib/docspring/models/add_fields_template_response.rb +81 -43
- data/lib/docspring/models/authentication_error.rb +62 -29
- data/lib/docspring/models/authentication_success_response.rb +66 -28
- data/lib/docspring/models/combine_pdfs_data.rb +74 -32
- data/lib/docspring/models/combined_submission.rb +167 -68
- data/lib/docspring/models/combined_submission_action.rb +83 -39
- data/lib/docspring/models/combined_submission_data.rb +72 -30
- data/lib/docspring/models/copy_template_data.rb +59 -26
- data/lib/docspring/models/create_combined_submission_response.rb +86 -41
- data/lib/docspring/models/create_custom_file_data.rb +58 -25
- data/lib/docspring/models/create_custom_file_response.rb +86 -41
- data/lib/docspring/models/create_folder_attributes.rb +230 -0
- data/lib/docspring/models/create_folder_data.rb +59 -26
- data/lib/docspring/models/create_html_template_data.rb +58 -25
- data/lib/docspring/models/create_submission_batch_response.rb +104 -52
- data/lib/docspring/models/create_submission_batch_submissions_response.rb +79 -41
- data/lib/docspring/models/create_submission_data.rb +304 -0
- data/lib/docspring/models/create_submission_data_request_data.rb +139 -90
- data/lib/docspring/models/create_submission_data_request_event_request.rb +297 -0
- data/lib/docspring/models/create_submission_data_request_event_response.rb +282 -0
- data/lib/docspring/models/create_submission_data_request_token_response.rb +85 -40
- data/lib/docspring/models/create_submission_response.rb +86 -41
- data/lib/docspring/models/create_template_from_upload_data.rb +58 -25
- data/lib/docspring/models/{custom_file.rb → data_request_token.rb} +110 -33
- data/lib/docspring/models/delete_template_response.rb +266 -0
- data/lib/docspring/models/{error.rb → error_response.rb} +65 -30
- data/lib/docspring/models/folder.rb +78 -46
- data/lib/docspring/models/full_template.rb +801 -0
- data/lib/docspring/models/html_template_data.rb +180 -110
- data/lib/docspring/models/{folders_folder.rb → html_template_data_webhook_options.rb} +63 -41
- data/lib/docspring/models/invalid_request.rb +64 -29
- data/lib/docspring/models/invalid_request_single_error.rb +271 -0
- data/lib/docspring/models/list_submissions_response.rb +251 -0
- data/lib/docspring/models/move_folder_data.rb +56 -25
- data/lib/docspring/models/move_template_data.rb +58 -25
- data/lib/docspring/models/pending_template.rb +221 -118
- data/lib/docspring/models/preview_pdf_response.rb +264 -0
- data/lib/docspring/models/publish_template_version404_response.rb +271 -0
- data/lib/docspring/models/publish_template_version422_response.rb +273 -0
- data/lib/docspring/models/publish_template_version_response.rb +271 -0
- data/lib/docspring/models/publish_template_version_response_result.rb +263 -0
- data/lib/docspring/models/publish_version_data.rb +230 -0
- data/lib/docspring/models/rename_folder_data.rb +58 -25
- data/lib/docspring/models/restore_template_version_response.rb +255 -0
- data/lib/docspring/models/{create_submission_data_request_token_response_token.rb → restore_version_data.rb} +69 -58
- data/lib/docspring/models/submission.rb +98 -49
- data/lib/docspring/models/submission_action.rb +83 -39
- data/lib/docspring/models/submission_batch.rb +158 -75
- data/lib/docspring/models/submission_batch_data.rb +74 -30
- data/lib/docspring/models/submission_data.rb +65 -41
- data/lib/docspring/models/submission_data_batch_request.rb +100 -49
- data/lib/docspring/models/submission_data_request.rb +123 -54
- data/lib/docspring/models/submission_data_request_event.rb +309 -0
- data/lib/docspring/models/template.rb +267 -132
- data/lib/docspring/models/template_data.rb +173 -105
- data/lib/docspring/models/template_defaults.rb +249 -0
- data/lib/docspring/models/{upload_template_data_document.rb → template_document.rb} +91 -39
- data/lib/docspring/models/{upload_template_data_document_metadata.rb → template_document_metadata.rb} +94 -42
- data/lib/docspring/models/template_schema.rb +288 -0
- data/lib/docspring/models/update_data_request_response.rb +86 -41
- data/lib/docspring/models/update_submission_data_request_data.rb +82 -43
- data/lib/docspring/models/update_template_data.rb +58 -25
- data/lib/docspring/models/update_template_response.rb +79 -41
- data/lib/docspring/models/upload_presign.rb +296 -0
- data/lib/docspring/models/upload_template_data.rb +186 -116
- data/lib/docspring/version.rb +3 -3
- data/lib/docspring.rb +30 -10
- data/spec/api/client_integration_spec.rb +26 -19
- data/spec/api/pdf_api_integration_spec.rb +21 -19
- data/spec/api/pdf_api_spec_original.skipped.rb +469 -98
- data/spec/models/add_fields_data_spec.rb +8 -13
- data/spec/models/add_fields_template_response_spec.rb +16 -21
- data/spec/models/authentication_error_spec.rb +10 -15
- data/spec/models/authentication_success_response_spec.rb +9 -14
- data/spec/models/combine_pdfs_data_spec.rb +18 -17
- data/spec/models/combined_submission_action_spec.rb +16 -21
- data/spec/models/combined_submission_data_spec.rb +17 -16
- data/spec/models/combined_submission_spec.rb +45 -32
- data/spec/models/copy_template_data_spec.rb +9 -14
- data/spec/models/create_combined_submission_response_spec.rb +16 -21
- data/spec/models/create_custom_file_data_spec.rb +8 -13
- data/spec/models/create_custom_file_response_spec.rb +16 -21
- data/spec/models/create_folder_attributes_spec.rb +42 -0
- data/spec/models/create_folder_data_spec.rb +8 -13
- data/spec/models/create_html_template_data_spec.rb +8 -13
- data/spec/models/create_submission_batch_response_spec.rb +21 -26
- data/spec/models/create_submission_batch_submissions_response_spec.rb +16 -21
- data/spec/models/create_submission_data_request_data_spec.rb +33 -38
- data/spec/models/create_submission_data_request_event_request_spec.rb +62 -0
- data/spec/models/create_submission_data_request_event_response_spec.rb +52 -0
- data/spec/models/create_submission_data_request_token_response_spec.rb +15 -20
- data/spec/models/create_submission_data_spec.rb +90 -0
- data/spec/models/create_submission_response_spec.rb +16 -21
- data/spec/models/create_template_from_upload_data_spec.rb +8 -13
- data/spec/models/data_request_token_spec.rb +54 -0
- data/spec/models/delete_template_response_spec.rb +46 -0
- data/spec/models/error_response_spec.rb +46 -0
- data/spec/models/folder_spec.rb +15 -20
- data/spec/models/full_template_spec.rb +268 -0
- data/spec/models/html_template_data_spec.rb +62 -49
- data/spec/models/html_template_data_webhook_options_spec.rb +36 -0
- data/spec/models/invalid_request_single_error_spec.rb +46 -0
- data/spec/models/invalid_request_spec.rb +10 -15
- data/spec/models/list_submissions_response_spec.rb +48 -0
- data/spec/models/move_folder_data_spec.rb +8 -13
- data/spec/models/move_template_data_spec.rb +8 -13
- data/spec/models/pending_template_spec.rb +45 -50
- data/spec/models/preview_pdf_response_spec.rb +46 -0
- data/spec/models/publish_template_version404_response_spec.rb +46 -0
- data/spec/models/publish_template_version422_response_spec.rb +46 -0
- data/spec/models/publish_template_version_response_result_spec.rb +54 -0
- data/spec/models/publish_template_version_response_spec.rb +46 -0
- data/spec/models/publish_version_data_spec.rb +42 -0
- data/spec/models/rename_folder_data_spec.rb +8 -13
- data/spec/models/restore_template_version_response_spec.rb +40 -0
- data/spec/models/restore_version_data_spec.rb +36 -0
- data/spec/models/submission_action_spec.rb +16 -21
- data/spec/models/submission_batch_data_spec.rb +17 -16
- data/spec/models/submission_batch_spec.rb +29 -34
- data/spec/models/submission_data_batch_request_spec.rb +24 -23
- data/spec/models/submission_data_request_event_spec.rb +72 -0
- data/spec/models/submission_data_request_spec.rb +36 -35
- data/spec/models/submission_data_spec.rb +13 -24
- data/spec/models/submission_spec.rb +27 -32
- data/spec/models/template_data_spec.rb +59 -46
- data/spec/models/template_defaults_spec.rb +48 -0
- data/spec/models/template_document_metadata_spec.rb +52 -0
- data/spec/models/template_document_spec.rb +52 -0
- data/spec/models/template_schema_spec.rb +84 -0
- data/spec/models/template_spec.rb +50 -55
- data/spec/models/update_data_request_response_spec.rb +16 -21
- data/spec/models/update_submission_data_request_data_spec.rb +22 -27
- data/spec/models/update_template_data_spec.rb +8 -13
- data/spec/models/update_template_response_spec.rb +14 -19
- data/spec/models/upload_presign_spec.rb +58 -0
- data/spec/models/upload_template_data_spec.rb +64 -51
- data/spec/spec_helper.rb +5 -5
- metadata +112 -124
- data/docs/CreateSubmissionDataRequestTokenResponseToken.md +0 -11
- data/docs/CustomFile.md +0 -9
- data/docs/Error.md +0 -9
- data/docs/FoldersFolder.md +0 -9
- data/docs/TemplatestemplateIdaddFieldsFields.md +0 -92
- data/docs/UploadTemplateDataDocument.md +0 -10
- data/docs/UploadTemplateDataDocumentMetadata.md +0 -10
- data/lib/docspring/models/templatestemplate_idadd_fields_fields.rb +0 -1306
- data/spec/api_client_spec.rb +0 -226
- data/spec/configuration_spec.rb +0 -53
- data/spec/models/create_submission_data_request_token_response_token_spec.rb +0 -59
- data/spec/models/custom_file_spec.rb +0 -47
- data/spec/models/error_spec.rb +0 -51
- data/spec/models/folders_folder_spec.rb +0 -47
- data/spec/models/templatestemplate_idadd_fields_fields_spec.rb +0 -589
- data/spec/models/upload_template_data_document_metadata_spec.rb +0 -57
- data/spec/models/upload_template_data_document_spec.rb +0 -57
data/lib/docspring/api_client.rb
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
|
4
4
|
#DocSpring is a service that helps you fill out and sign PDF templates.
|
5
5
|
|
6
|
-
OpenAPI
|
6
|
+
The version of the OpenAPI document: v1
|
7
7
|
|
8
8
|
Generated by: https://openapi-generator.tech
|
9
|
-
|
9
|
+
Generator version: 7.11.0
|
10
10
|
|
11
11
|
=end
|
12
12
|
|
@@ -14,8 +14,9 @@ require 'date'
|
|
14
14
|
require 'json'
|
15
15
|
require 'logger'
|
16
16
|
require 'tempfile'
|
17
|
+
require 'time'
|
17
18
|
require 'typhoeus'
|
18
|
-
|
19
|
+
|
19
20
|
|
20
21
|
module DocSpring
|
21
22
|
class ApiClient
|
@@ -44,10 +45,11 @@ module DocSpring
|
|
44
45
|
|
45
46
|
# Call an API with given options.
|
46
47
|
#
|
47
|
-
# @return [Array<(Object,
|
48
|
-
# the data deserialized from response body (
|
48
|
+
# @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
|
49
|
+
# the data deserialized from response body (may be a Tempfile or nil), response status code and response headers.
|
49
50
|
def call_api(http_method, path, opts = {})
|
50
51
|
request = build_request(http_method, path, opts)
|
52
|
+
tempfile = download_file(request) if opts[:return_type] == 'File'
|
51
53
|
response = request.run
|
52
54
|
|
53
55
|
if @config.debugging
|
@@ -62,6 +64,8 @@ module DocSpring
|
|
62
64
|
fail ApiError.new(:code => 0,
|
63
65
|
:message => response.return_message)
|
64
66
|
else
|
67
|
+
# <--------------- BEGIN DOCSPRING CUSTOMIZATION ----------------->
|
68
|
+
# Description: Custom error handling for API responses
|
65
69
|
exception_message = nil
|
66
70
|
response_json = JSON.parse(response.body) rescue nil
|
67
71
|
if response_json.is_a? Hash
|
@@ -83,10 +87,13 @@ module DocSpring
|
|
83
87
|
:response_headers => response.headers,
|
84
88
|
:response_body => response.body),
|
85
89
|
exception_message
|
90
|
+
# <--------------- END DOCSPRING CUSTOMIZATION ----------------->
|
86
91
|
end
|
87
92
|
end
|
88
93
|
|
89
|
-
if opts[:return_type]
|
94
|
+
if opts[:return_type] == 'File'
|
95
|
+
data = tempfile
|
96
|
+
elsif opts[:return_type]
|
90
97
|
data = deserialize(response, opts[:return_type])
|
91
98
|
else
|
92
99
|
data = nil
|
@@ -104,12 +111,13 @@ module DocSpring
|
|
104
111
|
# @option opts [Object] :body HTTP body (JSON/XML)
|
105
112
|
# @return [Typhoeus::Request] A Typhoeus Request
|
106
113
|
def build_request(http_method, path, opts = {})
|
107
|
-
url = build_request_url(path)
|
114
|
+
url = build_request_url(path, opts)
|
108
115
|
http_method = http_method.to_sym.downcase
|
109
116
|
|
110
117
|
header_params = @default_headers.merge(opts[:header_params] || {})
|
111
118
|
query_params = opts[:query_params] || {}
|
112
119
|
form_params = opts[:form_params] || {}
|
120
|
+
follow_location = opts[:follow_location] || true
|
113
121
|
|
114
122
|
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
115
123
|
|
@@ -126,7 +134,8 @@ module DocSpring
|
|
126
134
|
:ssl_verifyhost => _verify_ssl_host,
|
127
135
|
:sslcert => @config.cert_file,
|
128
136
|
:sslkey => @config.key_file,
|
129
|
-
:verbose => @config.debugging
|
137
|
+
:verbose => @config.debugging,
|
138
|
+
:followlocation => follow_location
|
130
139
|
}
|
131
140
|
|
132
141
|
# set custom cert, if provided
|
@@ -140,9 +149,78 @@ module DocSpring
|
|
140
149
|
end
|
141
150
|
end
|
142
151
|
|
143
|
-
|
144
|
-
|
145
|
-
|
152
|
+
Typhoeus::Request.new(url, req_opts)
|
153
|
+
end
|
154
|
+
|
155
|
+
# Builds the HTTP request body
|
156
|
+
#
|
157
|
+
# @param [Hash] header_params Header parameters
|
158
|
+
# @param [Hash] form_params Query parameters
|
159
|
+
# @param [Object] body HTTP body (JSON/XML)
|
160
|
+
# @return [String] HTTP body data in the form of string
|
161
|
+
def build_request_body(header_params, form_params, body)
|
162
|
+
# http form
|
163
|
+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
164
|
+
header_params['Content-Type'] == 'multipart/form-data'
|
165
|
+
data = {}
|
166
|
+
form_params.each do |key, value|
|
167
|
+
case value
|
168
|
+
when ::File, ::Array, nil
|
169
|
+
# let typhoeus handle File, Array and nil parameters
|
170
|
+
data[key] = value
|
171
|
+
else
|
172
|
+
data[key] = value.to_s
|
173
|
+
end
|
174
|
+
end
|
175
|
+
elsif body
|
176
|
+
data = body.is_a?(String) ? body : body.to_json
|
177
|
+
else
|
178
|
+
data = nil
|
179
|
+
end
|
180
|
+
data
|
181
|
+
end
|
182
|
+
|
183
|
+
# Save response body into a file in (the defined) temporary folder, using the filename
|
184
|
+
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
185
|
+
# The response body is written to the file in chunks in order to handle files which
|
186
|
+
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
|
187
|
+
# process can use.
|
188
|
+
#
|
189
|
+
# @see Configuration#temp_folder_path
|
190
|
+
#
|
191
|
+
# @return [Tempfile] the tempfile generated
|
192
|
+
def download_file(request)
|
193
|
+
tempfile = nil
|
194
|
+
encoding = nil
|
195
|
+
request.on_headers do |response|
|
196
|
+
content_disposition = response.headers['Content-Disposition']
|
197
|
+
if content_disposition && content_disposition =~ /filename=/i
|
198
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
199
|
+
prefix = sanitize_filename(filename)
|
200
|
+
else
|
201
|
+
prefix = 'download-'
|
202
|
+
end
|
203
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
204
|
+
encoding = response.body.encoding
|
205
|
+
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
206
|
+
end
|
207
|
+
request.on_body do |chunk|
|
208
|
+
chunk.force_encoding(encoding)
|
209
|
+
tempfile.write(chunk)
|
210
|
+
end
|
211
|
+
# run the request to ensure the tempfile is created successfully before returning it
|
212
|
+
request.run
|
213
|
+
if tempfile
|
214
|
+
tempfile.close
|
215
|
+
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
216
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
217
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
218
|
+
"explicitly with `tempfile.delete`"
|
219
|
+
else
|
220
|
+
fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
|
221
|
+
end
|
222
|
+
|
223
|
+
tempfile
|
146
224
|
end
|
147
225
|
|
148
226
|
# Check if the given MIME is a JSON MIME.
|
@@ -154,24 +232,19 @@ module DocSpring
|
|
154
232
|
# @param [String] mime MIME
|
155
233
|
# @return [Boolean] True if the MIME is application/json
|
156
234
|
def json_mime?(mime)
|
157
|
-
(mime == '*/*') || !(mime =~
|
235
|
+
(mime == '*/*') || !(mime =~ /^Application\/.*json(?!p)(;.*)?/i).nil?
|
158
236
|
end
|
159
237
|
|
160
238
|
# Deserialize the response to the given return type.
|
161
239
|
#
|
162
240
|
# @param [Response] response HTTP response
|
163
|
-
# @param [String] return_type some examples: "User", "Array
|
241
|
+
# @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
|
164
242
|
def deserialize(response, return_type)
|
165
243
|
body = response.body
|
166
|
-
|
167
|
-
# handle file downloading - return the File instance processed in request callbacks
|
168
|
-
# note that response body is empty when the file is written in chunks in request on_body callback
|
169
|
-
return @tempfile if return_type == 'File'
|
170
|
-
|
171
244
|
return nil if body.nil? || body.empty?
|
172
245
|
|
173
246
|
# return response body directly for String return type
|
174
|
-
return body if return_type == 'String'
|
247
|
+
return body.to_s if return_type == 'String'
|
175
248
|
|
176
249
|
# ensuring a default content type
|
177
250
|
content_type = response.headers['Content-Type'] || 'application/json'
|
@@ -181,7 +254,7 @@ module DocSpring
|
|
181
254
|
begin
|
182
255
|
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
183
256
|
rescue JSON::ParserError => e
|
184
|
-
if %w(String Date
|
257
|
+
if %w(String Date Time).include?(return_type)
|
185
258
|
data = body
|
186
259
|
else
|
187
260
|
raise e
|
@@ -204,11 +277,11 @@ module DocSpring
|
|
204
277
|
data.to_i
|
205
278
|
when 'Float'
|
206
279
|
data.to_f
|
207
|
-
when '
|
280
|
+
when 'Boolean'
|
208
281
|
data == true
|
209
|
-
when '
|
282
|
+
when 'Time'
|
210
283
|
# parse date time (expecting ISO 8601 format)
|
211
|
-
|
284
|
+
Time.parse data
|
212
285
|
when 'Date'
|
213
286
|
# parse date time (expecting ISO 8601 format)
|
214
287
|
Date.parse data
|
@@ -226,46 +299,9 @@ module DocSpring
|
|
226
299
|
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
227
300
|
end
|
228
301
|
else
|
229
|
-
# models
|
230
|
-
DocSpring.const_get(return_type)
|
231
|
-
|
232
|
-
end
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
# Save response body into a file in (the defined) temporary folder, using the filename
|
237
|
-
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
238
|
-
# The response body is written to the file in chunks in order to handle files which
|
239
|
-
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
|
240
|
-
# process can use.
|
241
|
-
#
|
242
|
-
# @see Configuration#temp_folder_path
|
243
|
-
def download_file(request)
|
244
|
-
tempfile = nil
|
245
|
-
encoding = nil
|
246
|
-
request.on_headers do |response|
|
247
|
-
content_disposition = response.headers['Content-Disposition']
|
248
|
-
if content_disposition && content_disposition =~ /filename=/i
|
249
|
-
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
250
|
-
prefix = sanitize_filename(filename)
|
251
|
-
else
|
252
|
-
prefix = 'download-'
|
253
|
-
end
|
254
|
-
prefix = prefix + '-' unless prefix.end_with?('-')
|
255
|
-
encoding = response.body.encoding
|
256
|
-
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
257
|
-
@tempfile = tempfile
|
258
|
-
end
|
259
|
-
request.on_body do |chunk|
|
260
|
-
chunk.force_encoding(encoding)
|
261
|
-
tempfile.write(chunk)
|
262
|
-
end
|
263
|
-
request.on_complete do |response|
|
264
|
-
tempfile.close if tempfile
|
265
|
-
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
266
|
-
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
267
|
-
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
268
|
-
"explicitly with `tempfile.delete`"
|
302
|
+
# models (e.g. Pet) or oneOf
|
303
|
+
klass = DocSpring.const_get(return_type)
|
304
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
|
269
305
|
end
|
270
306
|
end
|
271
307
|
|
@@ -275,44 +311,16 @@ module DocSpring
|
|
275
311
|
# @param [String] filename the filename to be sanitized
|
276
312
|
# @return [String] the sanitized filename
|
277
313
|
def sanitize_filename(filename)
|
278
|
-
filename.
|
314
|
+
filename.split(/[\/\\]/).last
|
279
315
|
end
|
280
316
|
|
281
|
-
def build_request_url(path)
|
317
|
+
def build_request_url(path, opts = {})
|
282
318
|
# Add leading and trailing slashes to path
|
283
319
|
path = "/#{path}".gsub(/\/+/, '/')
|
284
|
-
@config.base_url + path
|
285
|
-
end
|
286
|
-
|
287
|
-
# Builds the HTTP request body
|
288
|
-
#
|
289
|
-
# @param [Hash] header_params Header parameters
|
290
|
-
# @param [Hash] form_params Query parameters
|
291
|
-
# @param [Object] body HTTP body (JSON/XML)
|
292
|
-
# @return [String] HTTP body data in the form of string
|
293
|
-
def build_request_body(header_params, form_params, body)
|
294
|
-
# http form
|
295
|
-
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
296
|
-
header_params['Content-Type'] == 'multipart/form-data'
|
297
|
-
data = {}
|
298
|
-
form_params.each do |key, value|
|
299
|
-
case value
|
300
|
-
when ::File, ::Array, nil
|
301
|
-
# let typhoeus handle File, Array and nil parameters
|
302
|
-
data[key] = value
|
303
|
-
else
|
304
|
-
data[key] = value.to_s
|
305
|
-
end
|
306
|
-
end
|
307
|
-
elsif body
|
308
|
-
data = body.is_a?(String) ? body : body.to_json
|
309
|
-
else
|
310
|
-
data = nil
|
311
|
-
end
|
312
|
-
data
|
320
|
+
@config.base_url(opts[:operation]) + path
|
313
321
|
end
|
314
322
|
|
315
|
-
# Update
|
323
|
+
# Update header and query params based on authentication settings.
|
316
324
|
#
|
317
325
|
# @param [Hash] header_params Header parameters
|
318
326
|
# @param [Hash] query_params Query parameters
|
@@ -324,7 +332,7 @@ module DocSpring
|
|
324
332
|
case auth_setting[:in]
|
325
333
|
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
326
334
|
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
327
|
-
else fail ArgumentError, 'Authentication token must be in `query`
|
335
|
+
else fail ArgumentError, 'Authentication token must be in `query` or `header`'
|
328
336
|
end
|
329
337
|
end
|
330
338
|
end
|
@@ -351,8 +359,8 @@ module DocSpring
|
|
351
359
|
# @param [Array] content_types array for Content-Type
|
352
360
|
# @return [String] the Content-Type header (e.g. application/json)
|
353
361
|
def select_header_content_type(content_types)
|
354
|
-
#
|
355
|
-
return
|
362
|
+
# return nil by default
|
363
|
+
return if content_types.nil? || content_types.empty?
|
356
364
|
# use JSON when present, otherwise use the first one
|
357
365
|
json_content_type = content_types.find { |s| json_mime?(s) }
|
358
366
|
json_content_type || content_types.first
|
data/lib/docspring/api_error.rb
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
|
4
4
|
#DocSpring is a service that helps you fill out and sign PDF templates.
|
5
5
|
|
6
|
-
OpenAPI
|
6
|
+
The version of the OpenAPI document: v1
|
7
7
|
|
8
8
|
Generated by: https://openapi-generator.tech
|
9
|
-
|
9
|
+
Generator version: 7.11.0
|
10
10
|
|
11
11
|
=end
|
12
12
|
|
@@ -32,7 +32,27 @@ module DocSpring
|
|
32
32
|
end
|
33
33
|
else
|
34
34
|
super arg
|
35
|
+
@message = arg
|
35
36
|
end
|
36
37
|
end
|
38
|
+
|
39
|
+
# Override to_s to display a friendly error message
|
40
|
+
def to_s
|
41
|
+
message
|
42
|
+
end
|
43
|
+
|
44
|
+
def message
|
45
|
+
if @message.nil?
|
46
|
+
msg = "Error message: the server returns an error"
|
47
|
+
else
|
48
|
+
msg = @message
|
49
|
+
end
|
50
|
+
|
51
|
+
msg += "\nHTTP status code: #{code}" if code
|
52
|
+
msg += "\nResponse headers: #{response_headers}" if response_headers
|
53
|
+
msg += "\nResponse body: #{response_body}" if response_body
|
54
|
+
|
55
|
+
msg
|
56
|
+
end
|
37
57
|
end
|
38
58
|
end
|
@@ -3,18 +3,19 @@
|
|
3
3
|
|
4
4
|
#DocSpring is a service that helps you fill out and sign PDF templates.
|
5
5
|
|
6
|
-
OpenAPI
|
6
|
+
The version of the OpenAPI document: v1
|
7
7
|
|
8
8
|
Generated by: https://openapi-generator.tech
|
9
|
-
|
9
|
+
Generator version: 7.11.0
|
10
10
|
|
11
11
|
=end
|
12
12
|
|
13
|
-
require 'uri'
|
14
|
-
|
15
13
|
module DocSpring
|
16
14
|
class Configuration
|
15
|
+
# <--------------- BEGIN DOCSPRING CUSTOMIZATION ----------------->
|
16
|
+
# Description: Add SCHEME_REGEX constant to extract scheme from host
|
17
17
|
SCHEME_REGEX = /^(https?):\/\//
|
18
|
+
# <--------------- END DOCSPRING CUSTOMIZATION ----------------->
|
18
19
|
|
19
20
|
# Defines url scheme
|
20
21
|
attr_accessor :scheme
|
@@ -25,6 +26,18 @@ module DocSpring
|
|
25
26
|
# Defines url base path
|
26
27
|
attr_accessor :base_path
|
27
28
|
|
29
|
+
# Define server configuration index
|
30
|
+
attr_accessor :server_index
|
31
|
+
|
32
|
+
# Define server operation configuration index
|
33
|
+
attr_accessor :server_operation_index
|
34
|
+
|
35
|
+
# Default server variables
|
36
|
+
attr_accessor :server_variables
|
37
|
+
|
38
|
+
# Default server operation variables
|
39
|
+
attr_accessor :server_operation_variables
|
40
|
+
|
28
41
|
# Defines API keys used with API Key authentications.
|
29
42
|
#
|
30
43
|
# @return [Hash] key: parameter name, value: parameter value (API key)
|
@@ -41,14 +54,16 @@ module DocSpring
|
|
41
54
|
# config.api_key_prefix['api_key'] = 'Token'
|
42
55
|
attr_accessor :api_key_prefix
|
43
56
|
|
57
|
+
# <--------------- BEGIN DOCSPRING CUSTOMIZATION ----------------->
|
58
|
+
# Description: Note that we also add a getter/setter for api_token_id and api_token_secret,
|
59
|
+
# aliases for username and password.
|
60
|
+
# <--------------- END DOCSPRING CUSTOMIZATION ----------------->
|
44
61
|
# Defines the username used with HTTP basic authentication.
|
45
|
-
# (DocSpring override: We also add a getter/setter for api_token_id)
|
46
62
|
#
|
47
63
|
# @return [String]
|
48
64
|
attr_accessor :username
|
49
65
|
|
50
66
|
# Defines the password used with HTTP basic authentication.
|
51
|
-
# (DocSpring override: We also add a getter/setter for api_token_secret)
|
52
67
|
#
|
53
68
|
# @return [String]
|
54
69
|
attr_accessor :password
|
@@ -56,6 +71,16 @@ module DocSpring
|
|
56
71
|
# Defines the access token (Bearer) used with OAuth2.
|
57
72
|
attr_accessor :access_token
|
58
73
|
|
74
|
+
# Defines a Proc used to fetch or refresh access tokens (Bearer) used with OAuth2.
|
75
|
+
# Overrides the access_token if set
|
76
|
+
# @return [Proc]
|
77
|
+
attr_accessor :access_token_getter
|
78
|
+
|
79
|
+
# Set this to return data as binary instead of downloading a temp file. When enabled (set to true)
|
80
|
+
# HTTP responses with return type `File` will be returned as a stream of binary data.
|
81
|
+
# Default to false.
|
82
|
+
attr_accessor :return_binary_data
|
83
|
+
|
59
84
|
# Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
|
60
85
|
# details will be logged with `logger.debug` (see the `logger` attribute).
|
61
86
|
# Default to false.
|
@@ -63,6 +88,14 @@ module DocSpring
|
|
63
88
|
# @return [true, false]
|
64
89
|
attr_accessor :debugging
|
65
90
|
|
91
|
+
# Set this to ignore operation servers for the API client. This is useful when you need to
|
92
|
+
# send requests to a different server than the one specified in the OpenAPI document.
|
93
|
+
# Will default to the base url defined in the spec but can be overridden by setting
|
94
|
+
# `scheme`, `host`, `base_path` directly.
|
95
|
+
# Default to false.
|
96
|
+
# @return [true, false]
|
97
|
+
attr_accessor :ignore_operation_servers
|
98
|
+
|
66
99
|
# Defines the logger used for debugging.
|
67
100
|
# Default to `Rails.logger` (when in Rails) or logging to STDOUT.
|
68
101
|
#
|
@@ -127,6 +160,7 @@ module DocSpring
|
|
127
160
|
# https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
|
128
161
|
attr_accessor :params_encoding
|
129
162
|
|
163
|
+
|
130
164
|
attr_accessor :inject_format
|
131
165
|
|
132
166
|
attr_accessor :force_ending_format
|
@@ -135,27 +169,36 @@ module DocSpring
|
|
135
169
|
@scheme = 'https'
|
136
170
|
@host = 'api.docspring.com'
|
137
171
|
@base_path = '/api/v1'
|
172
|
+
@server_index = nil
|
173
|
+
@server_operation_index = {}
|
174
|
+
@server_variables = {}
|
175
|
+
@server_operation_variables = {}
|
138
176
|
@api_key = {}
|
139
177
|
@api_key_prefix = {}
|
140
|
-
@timeout = 0
|
141
178
|
@client_side_validation = true
|
142
179
|
@verify_ssl = true
|
143
180
|
@verify_ssl_host = true
|
144
|
-
@params_encoding = nil
|
145
181
|
@cert_file = nil
|
146
182
|
@key_file = nil
|
183
|
+
@timeout = 0
|
184
|
+
@params_encoding = nil
|
147
185
|
@debugging = false
|
186
|
+
@ignore_operation_servers = false
|
148
187
|
@inject_format = false
|
149
188
|
@force_ending_format = false
|
150
189
|
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
151
190
|
|
152
|
-
#
|
191
|
+
# <--------------- BEGIN DOCSPRING CUSTOMIZATION ----------------->
|
192
|
+
# Description: Use ENV variables by default if they are provided.
|
153
193
|
@username = ENV['DOCSPRING_TOKEN_ID']
|
154
194
|
@password = ENV['DOCSPRING_TOKEN_SECRET']
|
195
|
+
# <--------------- END DOCSPRING CUSTOMIZATION ----------------->
|
155
196
|
|
156
197
|
yield(self) if block_given?
|
157
198
|
end
|
158
199
|
|
200
|
+
# <--------------- BEGIN DOCSPRING CUSTOMIZATION ----------------->
|
201
|
+
# Description: Add getter/setter for api_token_id and api_token_secret, aliases for username and password
|
159
202
|
def api_token_id=(api_token_id)
|
160
203
|
@username = api_token_id
|
161
204
|
end
|
@@ -165,7 +208,7 @@ module DocSpring
|
|
165
208
|
@password = api_token_secret
|
166
209
|
end
|
167
210
|
alias api_token_secret password
|
168
|
-
|
211
|
+
# <--------------- END DOCSPRING CUSTOMIZATION ----------------->
|
169
212
|
|
170
213
|
# The default Configuration object.
|
171
214
|
def self.default
|
@@ -182,10 +225,12 @@ module DocSpring
|
|
182
225
|
end
|
183
226
|
|
184
227
|
def host=(host)
|
185
|
-
#
|
228
|
+
# <--------------- BEGIN DOCSPRING CUSTOMIZATION ----------------->
|
229
|
+
# Decription: Set scheme automatically when setting host from a URL
|
186
230
|
@scheme = host[SCHEME_REGEX, 1] if host.match?(SCHEME_REGEX)
|
187
231
|
# remove http(s):// and anything after a slash
|
188
232
|
@host = host.sub(SCHEME_REGEX, '').split('/').first
|
233
|
+
# <--------------- END DOCSPRING CUSTOMIZATION ----------------->
|
189
234
|
end
|
190
235
|
|
191
236
|
def base_path=(base_path)
|
@@ -194,20 +239,35 @@ module DocSpring
|
|
194
239
|
@base_path = '' if @base_path == '/'
|
195
240
|
end
|
196
241
|
|
197
|
-
|
198
|
-
|
242
|
+
# Returns base URL for specified operation based on server settings
|
243
|
+
def base_url(operation = nil)
|
244
|
+
return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if ignore_operation_servers
|
245
|
+
if operation_server_settings.key?(operation) then
|
246
|
+
index = server_operation_index.fetch(operation, server_index)
|
247
|
+
server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
|
248
|
+
else
|
249
|
+
server_index.nil? ? "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') : server_url(server_index, server_variables, nil)
|
250
|
+
end
|
199
251
|
end
|
200
252
|
|
201
253
|
# Gets API key (with prefix if set).
|
202
254
|
# @param [String] param_name the parameter name of API key auth
|
203
|
-
def api_key_with_prefix(param_name)
|
255
|
+
def api_key_with_prefix(param_name, param_alias = nil)
|
256
|
+
key = @api_key[param_name]
|
257
|
+
key = @api_key.fetch(param_alias, key) unless param_alias.nil?
|
204
258
|
if @api_key_prefix[param_name]
|
205
|
-
"#{@api_key_prefix[param_name]} #{
|
259
|
+
"#{@api_key_prefix[param_name]} #{key}"
|
206
260
|
else
|
207
|
-
|
261
|
+
key
|
208
262
|
end
|
209
263
|
end
|
210
264
|
|
265
|
+
# Gets access_token using access_token_getter or uses the static access_token
|
266
|
+
def access_token_with_refresh
|
267
|
+
return access_token if access_token_getter.nil?
|
268
|
+
access_token_getter.call
|
269
|
+
end
|
270
|
+
|
211
271
|
# Gets Basic Auth token string
|
212
272
|
def basic_auth_token
|
213
273
|
'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
|
@@ -225,5 +285,56 @@ module DocSpring
|
|
225
285
|
},
|
226
286
|
}
|
227
287
|
end
|
288
|
+
|
289
|
+
# Returns an array of Server setting
|
290
|
+
def server_settings
|
291
|
+
[
|
292
|
+
{
|
293
|
+
url: "https://api.docspring.com/api/v1",
|
294
|
+
description: "No description provided",
|
295
|
+
}
|
296
|
+
]
|
297
|
+
end
|
298
|
+
|
299
|
+
def operation_server_settings
|
300
|
+
{
|
301
|
+
}
|
302
|
+
end
|
303
|
+
|
304
|
+
# Returns URL based on server settings
|
305
|
+
#
|
306
|
+
# @param index array index of the server settings
|
307
|
+
# @param variables hash of variable and the corresponding value
|
308
|
+
def server_url(index, variables = {}, servers = nil)
|
309
|
+
servers = server_settings if servers == nil
|
310
|
+
|
311
|
+
# check array index out of bound
|
312
|
+
if (index.nil? || index < 0 || index >= servers.size)
|
313
|
+
fail ArgumentError, "Invalid index #{index} when selecting the server. Must not be nil and must be less than #{servers.size}"
|
314
|
+
end
|
315
|
+
|
316
|
+
server = servers[index]
|
317
|
+
url = server[:url]
|
318
|
+
|
319
|
+
return url unless server.key? :variables
|
320
|
+
|
321
|
+
# go through variable and assign a value
|
322
|
+
server[:variables].each do |name, variable|
|
323
|
+
if variables.key?(name)
|
324
|
+
if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
|
325
|
+
url.gsub! "{" + name.to_s + "}", variables[name]
|
326
|
+
else
|
327
|
+
fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
|
328
|
+
end
|
329
|
+
else
|
330
|
+
# use default value
|
331
|
+
url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
url
|
336
|
+
end
|
337
|
+
|
338
|
+
|
228
339
|
end
|
229
340
|
end
|