docspring 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +39 -0
  3. data/.openapi-generator-ignore +23 -0
  4. data/.openapi-generator/VERSION +1 -0
  5. data/.rspec +2 -0
  6. data/.rubocop.yml +154 -0
  7. data/.swagger-codegen-ignore +31 -0
  8. data/.swagger-codegen/VERSION +1 -0
  9. data/.swagger-revision +1 -0
  10. data/.travis.yml +8 -0
  11. data/CHANGELOG.md +48 -0
  12. data/Gemfile +8 -0
  13. data/Gemfile.lock +80 -0
  14. data/LICENSE +7 -0
  15. data/README.md +162 -0
  16. data/Rakefile +10 -0
  17. data/docs/AuthenticationError.md +9 -0
  18. data/docs/AuthenticationSuccessResponse.md +8 -0
  19. data/docs/CombinePdfsData.md +12 -0
  20. data/docs/CombinedSubmission.md +16 -0
  21. data/docs/CombinedSubmissionAction.md +13 -0
  22. data/docs/CombinedSubmissionData.md +11 -0
  23. data/docs/CreateCombinedSubmissionResponse.md +10 -0
  24. data/docs/CreateCustomFileData.md +8 -0
  25. data/docs/CreateCustomFileResponse.md +10 -0
  26. data/docs/CreateFolderData.md +8 -0
  27. data/docs/CreateSubmissionBatchResponse.md +12 -0
  28. data/docs/CreateSubmissionBatchSubmissionsResponse.md +10 -0
  29. data/docs/CreateSubmissionDataRequestData.md +20 -0
  30. data/docs/CreateSubmissionDataRequestTokenResponse.md +10 -0
  31. data/docs/CreateSubmissionDataRequestTokenResponseToken.md +11 -0
  32. data/docs/CreateSubmissionResponse.md +10 -0
  33. data/docs/CreateTemplateData.md +8 -0
  34. data/docs/CustomFile.md +9 -0
  35. data/docs/Error.md +9 -0
  36. data/docs/Folder.md +11 -0
  37. data/docs/FoldersFolder.md +9 -0
  38. data/docs/InvalidRequest.md +9 -0
  39. data/docs/MoveFolderData.md +8 -0
  40. data/docs/MoveTemplateData.md +8 -0
  41. data/docs/PDFApi.md +1385 -0
  42. data/docs/PendingTemplate.md +22 -0
  43. data/docs/RenameFolderData.md +8 -0
  44. data/docs/Submission.md +21 -0
  45. data/docs/SubmissionAction.md +13 -0
  46. data/docs/SubmissionBatch.md +16 -0
  47. data/docs/SubmissionBatchData.md +11 -0
  48. data/docs/SubmissionData.md +13 -0
  49. data/docs/SubmissionDataBatchRequest.md +13 -0
  50. data/docs/SubmissionDataRequest.md +24 -0
  51. data/docs/Template.md +25 -0
  52. data/docs/Templatesv2Template.md +19 -0
  53. data/docs/Templatesv2TemplateDocument.md +10 -0
  54. data/docs/Templatesv2TemplateDocumentMetadata.md +10 -0
  55. data/docs/UpdateDataRequestResponse.md +10 -0
  56. data/docs/UpdateSubmissionDataRequestData.md +20 -0
  57. data/docspring.gemspec +47 -0
  58. data/git_push.sh +55 -0
  59. data/lib/docspring.rb +82 -0
  60. data/lib/docspring/api/client.rb +174 -0
  61. data/lib/docspring/api/pdf_api.rb +1481 -0
  62. data/lib/docspring/api_client.rb +406 -0
  63. data/lib/docspring/api_error.rb +38 -0
  64. data/lib/docspring/configuration.rb +230 -0
  65. data/lib/docspring/models/authentication_error.rb +231 -0
  66. data/lib/docspring/models/authentication_success_response.rb +217 -0
  67. data/lib/docspring/models/combine_pdfs_data.rb +226 -0
  68. data/lib/docspring/models/combined_submission.rb +295 -0
  69. data/lib/docspring/models/combined_submission_action.rb +316 -0
  70. data/lib/docspring/models/combined_submission_data.rb +217 -0
  71. data/lib/docspring/models/create_combined_submission_response.rb +237 -0
  72. data/lib/docspring/models/create_custom_file_data.rb +207 -0
  73. data/lib/docspring/models/create_custom_file_response.rb +237 -0
  74. data/lib/docspring/models/create_folder_data.rb +188 -0
  75. data/lib/docspring/models/create_submission_batch_response.rb +257 -0
  76. data/lib/docspring/models/create_submission_batch_submissions_response.rb +237 -0
  77. data/lib/docspring/models/create_submission_data_request_data.rb +339 -0
  78. data/lib/docspring/models/create_submission_data_request_token_response.rb +237 -0
  79. data/lib/docspring/models/create_submission_data_request_token_response_token.rb +210 -0
  80. data/lib/docspring/models/create_submission_response.rb +237 -0
  81. data/lib/docspring/models/create_template_data.rb +188 -0
  82. data/lib/docspring/models/custom_file.rb +192 -0
  83. data/lib/docspring/models/error.rb +236 -0
  84. data/lib/docspring/models/folder.rb +210 -0
  85. data/lib/docspring/models/folders_folder.rb +192 -0
  86. data/lib/docspring/models/invalid_request.rb +238 -0
  87. data/lib/docspring/models/move_folder_data.rb +183 -0
  88. data/lib/docspring/models/move_template_data.rb +183 -0
  89. data/lib/docspring/models/pending_template.rb +343 -0
  90. data/lib/docspring/models/rename_folder_data.rb +188 -0
  91. data/lib/docspring/models/submission.rb +358 -0
  92. data/lib/docspring/models/submission_action.rb +316 -0
  93. data/lib/docspring/models/submission_batch.rb +291 -0
  94. data/lib/docspring/models/submission_batch_data.rb +217 -0
  95. data/lib/docspring/models/submission_data.rb +235 -0
  96. data/lib/docspring/models/submission_data_batch_request.rb +228 -0
  97. data/lib/docspring/models/submission_data_request.rb +422 -0
  98. data/lib/docspring/models/template.rb +372 -0
  99. data/lib/docspring/models/templatesv2_template.rb +316 -0
  100. data/lib/docspring/models/templatesv2_template_document.rb +235 -0
  101. data/lib/docspring/models/templatesv2_template_document_metadata.rb +235 -0
  102. data/lib/docspring/models/update_data_request_response.rb +237 -0
  103. data/lib/docspring/models/update_submission_data_request_data.rb +339 -0
  104. data/lib/docspring/version.rb +15 -0
  105. data/spec/api/client_integration_spec.rb +259 -0
  106. data/spec/api/pdf_api_integration_spec.rb +377 -0
  107. data/spec/api/pdf_api_spec_original.skipped.rb +397 -0
  108. data/spec/api_client_spec.rb +226 -0
  109. data/spec/configuration_spec.rb +53 -0
  110. data/spec/models/authentication_error_spec.rb +51 -0
  111. data/spec/models/authentication_success_response_spec.rb +45 -0
  112. data/spec/models/combine_pdfs_data_spec.rb +65 -0
  113. data/spec/models/combined_submission_action_spec.rb +83 -0
  114. data/spec/models/combined_submission_data_spec.rb +59 -0
  115. data/spec/models/combined_submission_spec.rb +93 -0
  116. data/spec/models/create_combined_submission_response_spec.rb +57 -0
  117. data/spec/models/create_custom_file_data_spec.rb +41 -0
  118. data/spec/models/create_custom_file_response_spec.rb +57 -0
  119. data/spec/models/create_folder_data_spec.rb +41 -0
  120. data/spec/models/create_submission_batch_response_spec.rb +69 -0
  121. data/spec/models/create_submission_batch_submissions_response_spec.rb +57 -0
  122. data/spec/models/create_submission_data_request_data_spec.rb +121 -0
  123. data/spec/models/create_submission_data_request_token_response_spec.rb +57 -0
  124. data/spec/models/create_submission_data_request_token_response_token_spec.rb +59 -0
  125. data/spec/models/create_submission_response_spec.rb +57 -0
  126. data/spec/models/create_template_data_spec.rb +41 -0
  127. data/spec/models/custom_file_spec.rb +47 -0
  128. data/spec/models/error_spec.rb +51 -0
  129. data/spec/models/folder_spec.rb +59 -0
  130. data/spec/models/folders_folder_spec.rb +47 -0
  131. data/spec/models/invalid_request_spec.rb +51 -0
  132. data/spec/models/move_folder_data_spec.rb +41 -0
  133. data/spec/models/move_template_data_spec.rb +41 -0
  134. data/spec/models/pending_template_spec.rb +129 -0
  135. data/spec/models/rename_folder_data_spec.rb +41 -0
  136. data/spec/models/submission_action_spec.rb +83 -0
  137. data/spec/models/submission_batch_data_spec.rb +59 -0
  138. data/spec/models/submission_batch_spec.rb +93 -0
  139. data/spec/models/submission_data_batch_request_spec.rb +71 -0
  140. data/spec/models/submission_data_request_spec.rb +149 -0
  141. data/spec/models/submission_data_spec.rb +71 -0
  142. data/spec/models/submission_spec.rb +123 -0
  143. data/spec/models/template_spec.rb +147 -0
  144. data/spec/models/templatesv2_template_document_metadata_spec.rb +57 -0
  145. data/spec/models/templatesv2_template_document_spec.rb +57 -0
  146. data/spec/models/templatesv2_template_spec.rb +111 -0
  147. data/spec/models/update_data_request_response_spec.rb +57 -0
  148. data/spec/models/update_submission_data_request_data_spec.rb +121 -0
  149. data/spec/spec_helper.rb +117 -0
  150. metadata +430 -0
@@ -0,0 +1,406 @@
1
+ =begin
2
+ #API v1
3
+
4
+ #DocSpring is a service that helps you fill out and sign PDF templates.
5
+
6
+ OpenAPI spec version: v1
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 3.3.0-SNAPSHOT
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'json'
15
+ require 'logger'
16
+ require 'tempfile'
17
+ require 'typhoeus'
18
+ require 'uri'
19
+
20
+ module DocSpring
21
+ class ApiClient
22
+ # The Configuration object holding settings to be used in the API client.
23
+ attr_accessor :config
24
+
25
+ # Defines the headers to be used in HTTP requests of all API calls by default.
26
+ #
27
+ # @return [Hash]
28
+ attr_accessor :default_headers
29
+
30
+ # Initializes the ApiClient
31
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
32
+ def initialize(config = Configuration.default)
33
+ @config = config
34
+ @user_agent = "docspring-ruby-#{VERSION}"
35
+ @default_headers = {
36
+ 'Content-Type' => 'application/json',
37
+ 'User-Agent' => @user_agent
38
+ }
39
+ end
40
+
41
+ def self.default
42
+ @@default ||= ApiClient.new
43
+ end
44
+
45
+ # Call an API with given options.
46
+ #
47
+ # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
48
+ # the data deserialized from response body (could be nil), response status code and response headers.
49
+ def call_api(http_method, path, opts = {})
50
+ request = build_request(http_method, path, opts)
51
+ response = request.run
52
+
53
+ if @config.debugging
54
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
55
+ end
56
+
57
+ unless response.success?
58
+ if response.timed_out?
59
+ fail ApiError.new('Connection timed out')
60
+ elsif response.code == 0
61
+ # Errors from libcurl will be made visible here
62
+ fail ApiError.new(:code => 0,
63
+ :message => response.return_message)
64
+ else
65
+ exception_message = nil
66
+ response_json = JSON.parse(response.body) rescue nil
67
+ if response_json.is_a? Hash
68
+ if response_json['errors'].is_a? Array
69
+ response_errors = response_json['errors'].join(', ')
70
+ elsif response_json['error']
71
+ response_errors = response_json['error']
72
+ end
73
+ if response_errors
74
+ exception_message = "#{response.status_message}: #{response_errors}"
75
+ end
76
+ end
77
+
78
+ unless exception_message
79
+ exception_message = "#{response.status_message}: [Could not parse errors from response body]"
80
+ end
81
+
82
+ fail ApiError.new(:code => response.code,
83
+ :response_headers => response.headers,
84
+ :response_body => response.body),
85
+ exception_message
86
+ end
87
+ end
88
+
89
+ if opts[:return_type]
90
+ data = deserialize(response, opts[:return_type])
91
+ else
92
+ data = nil
93
+ end
94
+ return data, response.code, response.headers
95
+ end
96
+
97
+ # Builds the HTTP request
98
+ #
99
+ # @param [String] http_method HTTP method/verb (e.g. POST)
100
+ # @param [String] path URL path (e.g. /account/new)
101
+ # @option opts [Hash] :header_params Header parameters
102
+ # @option opts [Hash] :query_params Query parameters
103
+ # @option opts [Hash] :form_params Query parameters
104
+ # @option opts [Object] :body HTTP body (JSON/XML)
105
+ # @return [Typhoeus::Request] A Typhoeus Request
106
+ def build_request(http_method, path, opts = {})
107
+ url = build_request_url(path)
108
+ http_method = http_method.to_sym.downcase
109
+
110
+ header_params = @default_headers.merge(opts[:header_params] || {})
111
+ query_params = opts[:query_params] || {}
112
+ form_params = opts[:form_params] || {}
113
+
114
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
115
+
116
+ # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
117
+ _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
118
+
119
+ req_opts = {
120
+ :method => http_method,
121
+ :headers => header_params,
122
+ :params => query_params,
123
+ :params_encoding => @config.params_encoding,
124
+ :timeout => @config.timeout,
125
+ :ssl_verifypeer => @config.verify_ssl,
126
+ :ssl_verifyhost => _verify_ssl_host,
127
+ :sslcert => @config.cert_file,
128
+ :sslkey => @config.key_file,
129
+ :verbose => @config.debugging
130
+ }
131
+
132
+ # set custom cert, if provided
133
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
134
+
135
+ if [:post, :patch, :put, :delete].include?(http_method)
136
+ req_body = build_request_body(header_params, form_params, opts[:body])
137
+ req_opts.update :body => req_body
138
+ if @config.debugging
139
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
140
+ end
141
+ end
142
+
143
+ request = Typhoeus::Request.new(url, req_opts)
144
+ download_file(request) if opts[:return_type] == 'File'
145
+ request
146
+ end
147
+
148
+ # Check if the given MIME is a JSON MIME.
149
+ # JSON MIME examples:
150
+ # application/json
151
+ # application/json; charset=UTF8
152
+ # APPLICATION/JSON
153
+ # */*
154
+ # @param [String] mime MIME
155
+ # @return [Boolean] True if the MIME is application/json
156
+ def json_mime?(mime)
157
+ (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
158
+ end
159
+
160
+ # Deserialize the response to the given return type.
161
+ #
162
+ # @param [Response] response HTTP response
163
+ # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
164
+ def deserialize(response, return_type)
165
+ 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
+ return nil if body.nil? || body.empty?
172
+
173
+ # return response body directly for String return type
174
+ return body if return_type == 'String'
175
+
176
+ # ensuring a default content type
177
+ content_type = response.headers['Content-Type'] || 'application/json'
178
+
179
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
180
+
181
+ begin
182
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
183
+ rescue JSON::ParserError => e
184
+ if %w(String Date DateTime).include?(return_type)
185
+ data = body
186
+ else
187
+ raise e
188
+ end
189
+ end
190
+
191
+ convert_to_type data, return_type
192
+ end
193
+
194
+ # Convert data to the given return type.
195
+ # @param [Object] data Data to be converted
196
+ # @param [String] return_type Return type
197
+ # @return [Mixed] Data in a particular type
198
+ def convert_to_type(data, return_type)
199
+ return nil if data.nil?
200
+ case return_type
201
+ when 'String'
202
+ data.to_s
203
+ when 'Integer'
204
+ data.to_i
205
+ when 'Float'
206
+ data.to_f
207
+ when 'BOOLEAN'
208
+ data == true
209
+ when 'DateTime'
210
+ # parse date time (expecting ISO 8601 format)
211
+ DateTime.parse data
212
+ when 'Date'
213
+ # parse date time (expecting ISO 8601 format)
214
+ Date.parse data
215
+ when 'Object'
216
+ # generic object (usually a Hash), return directly
217
+ data
218
+ when /\AArray<(.+)>\z/
219
+ # e.g. Array<Pet>
220
+ sub_type = $1
221
+ data.map { |item| convert_to_type(item, sub_type) }
222
+ when /\AHash\<String, (.+)\>\z/
223
+ # e.g. Hash<String, Integer>
224
+ sub_type = $1
225
+ {}.tap do |hash|
226
+ data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
227
+ end
228
+ else
229
+ # models, e.g. Pet
230
+ DocSpring.const_get(return_type).new.tap do |model|
231
+ model.build_from_hash data
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`"
269
+ end
270
+ end
271
+
272
+ # Sanitize filename by removing path.
273
+ # e.g. ../../sun.gif becomes sun.gif
274
+ #
275
+ # @param [String] filename the filename to be sanitized
276
+ # @return [String] the sanitized filename
277
+ def sanitize_filename(filename)
278
+ filename.gsub(/.*[\/\\]/, '')
279
+ end
280
+
281
+ def build_request_url(path)
282
+ # Add leading and trailing slashes to path
283
+ path = "/#{path}".gsub(/\/+/, '/')
284
+ URI.encode(@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
313
+ end
314
+
315
+ # Update hearder and query params based on authentication settings.
316
+ #
317
+ # @param [Hash] header_params Header parameters
318
+ # @param [Hash] query_params Query parameters
319
+ # @param [String] auth_names Authentication scheme name
320
+ def update_params_for_auth!(header_params, query_params, auth_names)
321
+ Array(auth_names).each do |auth_name|
322
+ auth_setting = @config.auth_settings[auth_name]
323
+ next unless auth_setting
324
+ case auth_setting[:in]
325
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
326
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
327
+ else fail ArgumentError, 'Authentication token must be in `query` of `header`'
328
+ end
329
+ end
330
+ end
331
+
332
+ # Sets user agent in HTTP header
333
+ #
334
+ # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
335
+ def user_agent=(user_agent)
336
+ @user_agent = user_agent
337
+ @default_headers['User-Agent'] = @user_agent
338
+ end
339
+
340
+ # Return Accept header based on an array of accepts provided.
341
+ # @param [Array] accepts array for Accept
342
+ # @return [String] the Accept header (e.g. application/json)
343
+ def select_header_accept(accepts)
344
+ return nil if accepts.nil? || accepts.empty?
345
+ # use JSON when present, otherwise use all of the provided
346
+ json_accept = accepts.find { |s| json_mime?(s) }
347
+ json_accept || accepts.join(',')
348
+ end
349
+
350
+ # Return Content-Type header based on an array of content types provided.
351
+ # @param [Array] content_types array for Content-Type
352
+ # @return [String] the Content-Type header (e.g. application/json)
353
+ def select_header_content_type(content_types)
354
+ # use application/json by default
355
+ return 'application/json' if content_types.nil? || content_types.empty?
356
+ # use JSON when present, otherwise use the first one
357
+ json_content_type = content_types.find { |s| json_mime?(s) }
358
+ json_content_type || content_types.first
359
+ end
360
+
361
+ # Convert object (array, hash, object, etc) to JSON string.
362
+ # @param [Object] model object to be converted into JSON string
363
+ # @return [String] JSON string representation of the object
364
+ def object_to_http_body(model)
365
+ return model if model.nil? || model.is_a?(String)
366
+ local_body = nil
367
+ if model.is_a?(Array)
368
+ local_body = model.map { |m| object_to_hash(m) }
369
+ else
370
+ local_body = object_to_hash(model)
371
+ end
372
+ local_body.to_json
373
+ end
374
+
375
+ # Convert object(non-array) to hash.
376
+ # @param [Object] obj object to be converted into JSON string
377
+ # @return [String] JSON string representation of the object
378
+ def object_to_hash(obj)
379
+ if obj.respond_to?(:to_hash)
380
+ obj.to_hash
381
+ else
382
+ obj
383
+ end
384
+ end
385
+
386
+ # Build parameter value according to the given collection format.
387
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
388
+ def build_collection_param(param, collection_format)
389
+ case collection_format
390
+ when :csv
391
+ param.join(',')
392
+ when :ssv
393
+ param.join(' ')
394
+ when :tsv
395
+ param.join("\t")
396
+ when :pipes
397
+ param.join('|')
398
+ when :multi
399
+ # return the array directly as typhoeus will handle it as expected
400
+ param
401
+ else
402
+ fail "unknown collection format: #{collection_format.inspect}"
403
+ end
404
+ end
405
+ end
406
+ end
@@ -0,0 +1,38 @@
1
+ =begin
2
+ #API v1
3
+
4
+ #DocSpring is a service that helps you fill out and sign PDF templates.
5
+
6
+ OpenAPI spec version: v1
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 3.3.0-SNAPSHOT
10
+
11
+ =end
12
+
13
+ module DocSpring
14
+ class ApiError < StandardError
15
+ attr_reader :code, :response_headers, :response_body
16
+
17
+ # Usage examples:
18
+ # ApiError.new
19
+ # ApiError.new("message")
20
+ # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
21
+ # ApiError.new(:code => 404, :message => "Not Found")
22
+ def initialize(arg = nil)
23
+ if arg.is_a? Hash
24
+ if arg.key?(:message) || arg.key?('message')
25
+ super(arg[:message] || arg['message'])
26
+ else
27
+ super arg
28
+ end
29
+
30
+ arg.each do |k, v|
31
+ instance_variable_set "@#{k}", v
32
+ end
33
+ else
34
+ super arg
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,230 @@
1
+ =begin
2
+ #API v1
3
+
4
+ #DocSpring is a service that helps you fill out and sign PDF templates.
5
+
6
+ OpenAPI spec version: v1
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 3.3.0-SNAPSHOT
10
+
11
+ =end
12
+
13
+ require 'uri'
14
+
15
+ module DocSpring
16
+ class Configuration
17
+ SCHEME_REGEX = /^(https?):\/\//
18
+
19
+ # Defines url scheme
20
+ attr_accessor :scheme
21
+
22
+ # Defines url host
23
+ attr_accessor :host
24
+
25
+ # Defines url base path
26
+ attr_accessor :base_path
27
+
28
+ # Defines API keys used with API Key authentications.
29
+ #
30
+ # @return [Hash] key: parameter name, value: parameter value (API key)
31
+ #
32
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
33
+ # config.api_key['api_key'] = 'xxx'
34
+ attr_accessor :api_key
35
+
36
+ # Defines API key prefixes used with API Key authentications.
37
+ #
38
+ # @return [Hash] key: parameter name, value: API key prefix
39
+ #
40
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
41
+ # config.api_key_prefix['api_key'] = 'Token'
42
+ attr_accessor :api_key_prefix
43
+
44
+ # Defines the username used with HTTP basic authentication.
45
+ # (DocSpring override: We also add a getter/setter for api_token_id)
46
+ #
47
+ # @return [String]
48
+ attr_accessor :username
49
+
50
+ # Defines the password used with HTTP basic authentication.
51
+ # (DocSpring override: We also add a getter/setter for api_token_secret)
52
+ #
53
+ # @return [String]
54
+ attr_accessor :password
55
+
56
+ # Defines the access token (Bearer) used with OAuth2.
57
+ attr_accessor :access_token
58
+
59
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
60
+ # details will be logged with `logger.debug` (see the `logger` attribute).
61
+ # Default to false.
62
+ #
63
+ # @return [true, false]
64
+ attr_accessor :debugging
65
+
66
+ # Defines the logger used for debugging.
67
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
68
+ #
69
+ # @return [#debug]
70
+ attr_accessor :logger
71
+
72
+ # Defines the temporary folder to store downloaded files
73
+ # (for API endpoints that have file response).
74
+ # Default to use `Tempfile`.
75
+ #
76
+ # @return [String]
77
+ attr_accessor :temp_folder_path
78
+
79
+ # The time limit for HTTP request in seconds.
80
+ # Default to 0 (never times out).
81
+ attr_accessor :timeout
82
+
83
+ # Set this to false to skip client side validation in the operation.
84
+ # Default to true.
85
+ # @return [true, false]
86
+ attr_accessor :client_side_validation
87
+
88
+ ### TLS/SSL setting
89
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
90
+ # Default to true.
91
+ #
92
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
93
+ #
94
+ # @return [true, false]
95
+ attr_accessor :verify_ssl
96
+
97
+ ### TLS/SSL setting
98
+ # Set this to false to skip verifying SSL host name
99
+ # Default to true.
100
+ #
101
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
102
+ #
103
+ # @return [true, false]
104
+ attr_accessor :verify_ssl_host
105
+
106
+ ### TLS/SSL setting
107
+ # Set this to customize the certificate file to verify the peer.
108
+ #
109
+ # @return [String] the path to the certificate file
110
+ #
111
+ # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
112
+ # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
113
+ attr_accessor :ssl_ca_cert
114
+
115
+ ### TLS/SSL setting
116
+ # Client certificate file (for client certificate)
117
+ attr_accessor :cert_file
118
+
119
+ ### TLS/SSL setting
120
+ # Client private key file (for client certificate)
121
+ attr_accessor :key_file
122
+
123
+ # Set this to customize parameters encoding of array parameter with multi collectionFormat.
124
+ # Default to nil.
125
+ #
126
+ # @see The params_encoding option of Ethon. Related source code:
127
+ # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
128
+ attr_accessor :params_encoding
129
+
130
+ attr_accessor :inject_format
131
+
132
+ attr_accessor :force_ending_format
133
+
134
+ def initialize
135
+ @scheme = 'https'
136
+ @host = 'api.docspring.com'
137
+ @base_path = '/api/v1'
138
+ @api_key = {}
139
+ @api_key_prefix = {}
140
+ @timeout = 0
141
+ @client_side_validation = true
142
+ @verify_ssl = true
143
+ @verify_ssl_host = true
144
+ @params_encoding = nil
145
+ @cert_file = nil
146
+ @key_file = nil
147
+ @debugging = false
148
+ @inject_format = false
149
+ @force_ending_format = false
150
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
151
+
152
+ # Use ENV variables by default if they are provided.
153
+ @username = ENV['DOCSPRING_TOKEN_ID']
154
+ @password = ENV['DOCSPRING_TOKEN_SECRET']
155
+
156
+ yield(self) if block_given?
157
+ end
158
+
159
+ def api_token_id=(api_token_id)
160
+ @username = api_token_id
161
+ end
162
+ alias api_token_id username
163
+
164
+ def api_token_secret=(api_token_secret)
165
+ @password = api_token_secret
166
+ end
167
+ alias api_token_secret password
168
+
169
+
170
+ # The default Configuration object.
171
+ def self.default
172
+ @@default ||= Configuration.new
173
+ end
174
+
175
+ def configure
176
+ yield(self) if block_given?
177
+ end
178
+
179
+ def scheme=(scheme)
180
+ # remove :// from scheme
181
+ @scheme = scheme.sub(/:\/\//, '')
182
+ end
183
+
184
+ def host=(host)
185
+ # Also set scheme when setting host.
186
+ @scheme = host[SCHEME_REGEX, 1] if host.match?(SCHEME_REGEX)
187
+ # remove http(s):// and anything after a slash
188
+ @host = host.sub(SCHEME_REGEX, '').split('/').first
189
+ end
190
+
191
+ def base_path=(base_path)
192
+ # Add leading and trailing slashes to base_path
193
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
194
+ @base_path = '' if @base_path == '/'
195
+ end
196
+
197
+ def base_url
198
+ url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
199
+ URI.encode(url)
200
+ end
201
+
202
+ # Gets API key (with prefix if set).
203
+ # @param [String] param_name the parameter name of API key auth
204
+ def api_key_with_prefix(param_name)
205
+ if @api_key_prefix[param_name]
206
+ "#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
207
+ else
208
+ @api_key[param_name]
209
+ end
210
+ end
211
+
212
+ # Gets Basic Auth token string
213
+ def basic_auth_token
214
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
215
+ end
216
+
217
+ # Returns Auth Settings hash for api client.
218
+ def auth_settings
219
+ {
220
+ 'api_token_basic' =>
221
+ {
222
+ type: 'basic',
223
+ in: 'header',
224
+ key: 'Authorization',
225
+ value: basic_auth_token
226
+ },
227
+ }
228
+ end
229
+ end
230
+ end