trulioo_sdk 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +155 -0
  3. data/docs/Address.md +44 -0
  4. data/docs/AppendedField.md +20 -0
  5. data/docs/Business.md +36 -0
  6. data/docs/BusinessApi.md +155 -0
  7. data/docs/BusinessRecord.md +24 -0
  8. data/docs/BusinessRegistrationNumber.md +30 -0
  9. data/docs/BusinessRegistrationNumberMask.md +22 -0
  10. data/docs/BusinessResult.md +22 -0
  11. data/docs/BusinessSearchRequest.md +28 -0
  12. data/docs/BusinessSearchRequestBusinessSearchModel.md +26 -0
  13. data/docs/BusinessSearchResponse.md +28 -0
  14. data/docs/BusinessSearchResponseIndustryCode.md +20 -0
  15. data/docs/Communication.md +24 -0
  16. data/docs/ConfigurationApi.md +761 -0
  17. data/docs/ConnectionApi.md +213 -0
  18. data/docs/Consent.md +22 -0
  19. data/docs/CountrySubdivision.md +22 -0
  20. data/docs/DataField.md +22 -0
  21. data/docs/DataFields.md +34 -0
  22. data/docs/DatasourceField.md +24 -0
  23. data/docs/DatasourceResult.md +28 -0
  24. data/docs/Document.md +28 -0
  25. data/docs/DriverLicence.md +26 -0
  26. data/docs/Location.md +42 -0
  27. data/docs/LocationAdditionalFields.md +18 -0
  28. data/docs/NationalId.md +28 -0
  29. data/docs/NormalizedDatasourceField.md +20 -0
  30. data/docs/NormalizedDatasourceGroupCountry.md +34 -0
  31. data/docs/Passport.md +28 -0
  32. data/docs/PersonInfo.md +38 -0
  33. data/docs/PersonInfoAdditionalFields.md +18 -0
  34. data/docs/Record.md +26 -0
  35. data/docs/RecordRule.md +20 -0
  36. data/docs/Result.md +62 -0
  37. data/docs/ServiceError.md +20 -0
  38. data/docs/TestEntityDataFields.md +36 -0
  39. data/docs/TransactionRecordResult.md +32 -0
  40. data/docs/TransactionRecordResultAllOf.md +18 -0
  41. data/docs/TransactionStatus.md +26 -0
  42. data/docs/VerificationsApi.md +529 -0
  43. data/docs/VerifyRequest.md +38 -0
  44. data/docs/VerifyResult.md +30 -0
  45. data/lib/trulioo_sdk.rb +77 -0
  46. data/lib/trulioo_sdk/api/business_api.rb +158 -0
  47. data/lib/trulioo_sdk/api/configuration_api.rb +750 -0
  48. data/lib/trulioo_sdk/api/connection_api.rb +221 -0
  49. data/lib/trulioo_sdk/api/verifications_api.rb +515 -0
  50. data/lib/trulioo_sdk/api_client.rb +391 -0
  51. data/lib/trulioo_sdk/api_error.rb +53 -0
  52. data/lib/trulioo_sdk/configuration.rb +268 -0
  53. data/lib/trulioo_sdk/models/address.rb +356 -0
  54. data/lib/trulioo_sdk/models/appended_field.rb +237 -0
  55. data/lib/trulioo_sdk/models/business.rb +318 -0
  56. data/lib/trulioo_sdk/models/business_record.rb +261 -0
  57. data/lib/trulioo_sdk/models/business_registration_number.rb +410 -0
  58. data/lib/trulioo_sdk/models/business_registration_number_mask.rb +272 -0
  59. data/lib/trulioo_sdk/models/business_result.rb +249 -0
  60. data/lib/trulioo_sdk/models/business_search_request.rb +306 -0
  61. data/lib/trulioo_sdk/models/business_search_request_business_search_model.rb +364 -0
  62. data/lib/trulioo_sdk/models/business_search_response.rb +279 -0
  63. data/lib/trulioo_sdk/models/business_search_response_industry_code.rb +236 -0
  64. data/lib/trulioo_sdk/models/communication.rb +354 -0
  65. data/lib/trulioo_sdk/models/consent.rb +249 -0
  66. data/lib/trulioo_sdk/models/country_subdivision.rb +320 -0
  67. data/lib/trulioo_sdk/models/data_field.rb +245 -0
  68. data/lib/trulioo_sdk/models/data_fields.rb +306 -0
  69. data/lib/trulioo_sdk/models/datasource_field.rb +254 -0
  70. data/lib/trulioo_sdk/models/datasource_result.rb +281 -0
  71. data/lib/trulioo_sdk/models/document.rb +278 -0
  72. data/lib/trulioo_sdk/models/driver_licence.rb +268 -0
  73. data/lib/trulioo_sdk/models/location.rb +347 -0
  74. data/lib/trulioo_sdk/models/location_additional_fields.rb +229 -0
  75. data/lib/trulioo_sdk/models/national_id.rb +277 -0
  76. data/lib/trulioo_sdk/models/normalized_datasource_field.rb +286 -0
  77. data/lib/trulioo_sdk/models/normalized_datasource_group_country.rb +437 -0
  78. data/lib/trulioo_sdk/models/passport.rb +326 -0
  79. data/lib/trulioo_sdk/models/person_info.rb +448 -0
  80. data/lib/trulioo_sdk/models/person_info_additional_fields.rb +228 -0
  81. data/lib/trulioo_sdk/models/record.rb +270 -0
  82. data/lib/trulioo_sdk/models/record_rule.rb +239 -0
  83. data/lib/trulioo_sdk/models/result.rb +440 -0
  84. data/lib/trulioo_sdk/models/service_error.rb +236 -0
  85. data/lib/trulioo_sdk/models/test_entity_data_fields.rb +315 -0
  86. data/lib/trulioo_sdk/models/transaction_record_result.rb +307 -0
  87. data/lib/trulioo_sdk/models/transaction_record_result_all_of.rb +229 -0
  88. data/lib/trulioo_sdk/models/transaction_status.rb +341 -0
  89. data/lib/trulioo_sdk/models/verify_request.rb +410 -0
  90. data/lib/trulioo_sdk/models/verify_result.rb +288 -0
  91. data/lib/trulioo_sdk/version.rb +11 -0
  92. metadata +223 -0
@@ -0,0 +1,391 @@
1
+ =begin
2
+ Trulioo Ruby SDK
3
+
4
+ Gem version: 1.0.3
5
+ Trulioo OpenAPI version: v1
6
+ Generated by OpenAPI Generator version: 5.0.1
7
+ =end
8
+
9
+ require 'date'
10
+ require 'json'
11
+ require 'logger'
12
+ require 'tempfile'
13
+ require 'time'
14
+ require 'faraday'
15
+
16
+ module Trulioo
17
+ class ApiClient
18
+ # The Configuration object holding settings to be used in the API client.
19
+ attr_accessor :config
20
+
21
+ # Defines the headers to be used in HTTP requests of all API calls by default.
22
+ #
23
+ # @return [Hash]
24
+ attr_accessor :default_headers
25
+
26
+ # Initializes the ApiClient
27
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
28
+ def initialize(config = Configuration.default)
29
+ @config = config
30
+ @user_agent = "OpenAPI-Generator/#{VERSION}/ruby"
31
+ @default_headers = {
32
+ 'Content-Type' => 'application/json',
33
+ 'User-Agent' => @user_agent
34
+ }
35
+ end
36
+
37
+ def self.default
38
+ @@default ||= ApiClient.new
39
+ end
40
+
41
+ # Call an API with given options.
42
+ #
43
+ # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
44
+ # the data deserialized from response body (could be nil), response status code and response headers.
45
+ def call_api(http_method, path, opts = {})
46
+ ssl_options = {
47
+ :ca_file => @config.ssl_ca_file,
48
+ :verify => @config.ssl_verify,
49
+ :verify_mode => @config.ssl_verify_mode,
50
+ :client_cert => @config.ssl_client_cert,
51
+ :client_key => @config.ssl_client_key
52
+ }
53
+
54
+ connection = Faraday.new(:url => config.base_url, :ssl => ssl_options) do |conn|
55
+ conn.basic_auth(config.username, config.password)
56
+ if opts[:header_params]["Content-Type"] == "multipart/form-data"
57
+ conn.request :multipart
58
+ conn.request :url_encoded
59
+ end
60
+ conn.adapter(Faraday.default_adapter)
61
+ end
62
+
63
+ begin
64
+ response = connection.public_send(http_method.to_sym.downcase) do |req|
65
+ build_request(http_method, path, req, opts)
66
+ end
67
+
68
+ if @config.debugging
69
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
70
+ end
71
+
72
+ unless response.success?
73
+ if response.status == 0
74
+ # Errors from libcurl will be made visible here
75
+ fail ApiError.new(:code => 0,
76
+ :message => response.return_message)
77
+ else
78
+ fail ApiError.new(:code => response.status,
79
+ :response_headers => response.headers,
80
+ :response_body => response.body),
81
+ response.reason_phrase
82
+ end
83
+ end
84
+ rescue Faraday::TimeoutError
85
+ fail ApiError.new('Connection timed out')
86
+ end
87
+
88
+ if opts[:return_type]
89
+ data = deserialize(response, opts[:return_type])
90
+ else
91
+ data = nil
92
+ end
93
+ return data, response.status, response.headers
94
+ end
95
+
96
+ # Builds the HTTP request
97
+ #
98
+ # @param [String] http_method HTTP method/verb (e.g. POST)
99
+ # @param [String] path URL path (e.g. /account/new)
100
+ # @option opts [Hash] :header_params Header parameters
101
+ # @option opts [Hash] :query_params Query parameters
102
+ # @option opts [Hash] :form_params Query parameters
103
+ # @option opts [Object] :body HTTP body (JSON/XML)
104
+ # @return [Typhoeus::Request] A Typhoeus Request
105
+ def build_request(http_method, path, request, opts = {})
106
+ url = build_request_url(path, opts)
107
+ http_method = http_method.to_sym.downcase
108
+
109
+ header_params = @default_headers.merge(opts[:header_params] || {})
110
+ query_params = opts[:query_params] || {}
111
+ form_params = opts[:form_params] || {}
112
+
113
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
114
+
115
+ req_opts = {
116
+ :method => http_method,
117
+ :headers => header_params,
118
+ :params => query_params,
119
+ :params_encoding => @config.params_encoding,
120
+ :timeout => @config.timeout,
121
+ :verbose => @config.debugging
122
+ }
123
+
124
+ if [:post, :patch, :put, :delete].include?(http_method)
125
+ req_body = build_request_body(header_params, form_params, opts[:body])
126
+ req_opts.update :body => req_body
127
+ if @config.debugging
128
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
129
+ end
130
+ end
131
+ request.headers = header_params
132
+ request.body = req_body
133
+ request.url url
134
+ request.params = query_params
135
+ download_file(request) if opts[:return_type] == 'File'
136
+ request
137
+ end
138
+
139
+ # Builds the HTTP request body
140
+ #
141
+ # @param [Hash] header_params Header parameters
142
+ # @param [Hash] form_params Query parameters
143
+ # @param [Object] body HTTP body (JSON/XML)
144
+ # @return [String] HTTP body data in the form of string
145
+ def build_request_body(header_params, form_params, body)
146
+ # http form
147
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded'
148
+ data = URI.encode_www_form(form_params)
149
+ elsif header_params['Content-Type'] == 'multipart/form-data'
150
+ data = {}
151
+ form_params.each do |key, value|
152
+ case value
153
+ when ::File, ::Tempfile
154
+ # TODO hardcode to application/octet-stream, need better way to detect content type
155
+ data[key] = Faraday::UploadIO.new(value.path, 'application/octet-stream', value.path)
156
+ when ::Array, nil
157
+ # let Faraday handle Array and nil parameters
158
+ data[key] = value
159
+ else
160
+ data[key] = value.to_s
161
+ end
162
+ end
163
+ elsif body
164
+ data = body.is_a?(String) ? body : body.to_json
165
+ else
166
+ data = nil
167
+ end
168
+ data
169
+ end
170
+
171
+ def download_file(request)
172
+ @stream = []
173
+
174
+ # handle streaming Responses
175
+ request.options.on_data = Proc.new do |chunk, overall_received_bytes|
176
+ @stream << chunk
177
+ end
178
+ end
179
+
180
+ # Check if the given MIME is a JSON MIME.
181
+ # JSON MIME examples:
182
+ # application/json
183
+ # application/json; charset=UTF8
184
+ # APPLICATION/JSON
185
+ # */*
186
+ # @param [String] mime MIME
187
+ # @return [Boolean] True if the MIME is application/json
188
+ def json_mime?(mime)
189
+ (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
190
+ end
191
+
192
+ # Deserialize the response to the given return type.
193
+ #
194
+ # @param [Response] response HTTP response
195
+ # @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
196
+ def deserialize(response, return_type)
197
+ body = response.body
198
+
199
+ # handle file downloading - return the File instance processed in request callbacks
200
+ # note that response body is empty when the file is written in chunks in request on_body callback
201
+ if return_type == 'File'
202
+ content_disposition = response.headers['Content-Disposition']
203
+ if content_disposition && content_disposition =~ /filename=/i
204
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
205
+ prefix = sanitize_filename(filename)
206
+ else
207
+ prefix = 'download-'
208
+ end
209
+ prefix = prefix + '-' unless prefix.end_with?('-')
210
+ encoding = body.encoding
211
+ @tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
212
+ @tempfile.write(@stream.join.force_encoding(encoding))
213
+ @tempfile.close
214
+ @config.logger.info "Temp file written to #{@tempfile.path}, please copy the file to a proper folder "\
215
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
216
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
217
+ "explicitly with `tempfile.delete`"
218
+ return @tempfile
219
+ end
220
+
221
+ return nil if body.nil? || body.empty?
222
+
223
+ # return response body directly for String return type
224
+ return body if return_type == 'String'
225
+
226
+ # ensuring a default content type
227
+ content_type = response.headers['Content-Type'] || 'application/json'
228
+
229
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
230
+
231
+ begin
232
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
233
+ rescue JSON::ParserError => e
234
+ if %w(String Date Time).include?(return_type)
235
+ data = body
236
+ else
237
+ raise e
238
+ end
239
+ end
240
+
241
+ convert_to_type data, return_type
242
+ end
243
+
244
+ # Convert data to the given return type.
245
+ # @param [Object] data Data to be converted
246
+ # @param [String] return_type Return type
247
+ # @return [Mixed] Data in a particular type
248
+ def convert_to_type(data, return_type)
249
+ return nil if data.nil?
250
+ case return_type
251
+ when 'String'
252
+ data.to_s
253
+ when 'Integer'
254
+ data.to_i
255
+ when 'Float'
256
+ data.to_f
257
+ when 'Boolean'
258
+ data == true
259
+ when 'Time'
260
+ # parse date time (expecting ISO 8601 format)
261
+ Time.parse data
262
+ when 'Date'
263
+ # parse date time (expecting ISO 8601 format)
264
+ Date.parse data
265
+ when 'Object'
266
+ # generic object (usually a Hash), return directly
267
+ data
268
+ when /\AArray<(.+)>\z/
269
+ # e.g. Array<Pet>
270
+ sub_type = $1
271
+ data.map { |item| convert_to_type(item, sub_type) }
272
+ when /\AHash\<String, (.+)\>\z/
273
+ # e.g. Hash<String, Integer>
274
+ sub_type = $1
275
+ {}.tap do |hash|
276
+ data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
277
+ end
278
+ else
279
+ # models (e.g. Pet) or oneOf
280
+ klass = Trulioo.const_get(return_type)
281
+ klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
282
+ end
283
+ end
284
+
285
+ # Sanitize filename by removing path.
286
+ # e.g. ../../sun.gif becomes sun.gif
287
+ #
288
+ # @param [String] filename the filename to be sanitized
289
+ # @return [String] the sanitized filename
290
+ def sanitize_filename(filename)
291
+ filename.gsub(/.*[\/\\]/, '')
292
+ end
293
+
294
+ def build_request_url(path, opts = {})
295
+ # Add leading and trailing slashes to path
296
+ path = "/#{path}".gsub(/\/+/, '/')
297
+ @config.base_url(opts[:operation]) + path
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` or `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. openapi-generator/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
+ 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
+ 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
+ end
391
+ end
@@ -0,0 +1,53 @@
1
+ =begin
2
+ Trulioo Ruby SDK
3
+
4
+ Gem version: 1.0.3
5
+ Trulioo OpenAPI version: v1
6
+ Generated by OpenAPI Generator version: 5.0.1
7
+ =end
8
+
9
+ module Trulioo
10
+ class ApiError < StandardError
11
+ attr_reader :code, :response_headers, :response_body
12
+
13
+ # Usage examples:
14
+ # ApiError.new
15
+ # ApiError.new("message")
16
+ # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
17
+ # ApiError.new(:code => 404, :message => "Not Found")
18
+ def initialize(arg = nil)
19
+ if arg.is_a? Hash
20
+ if arg.key?(:message) || arg.key?('message')
21
+ super(arg[:message] || arg['message'])
22
+ else
23
+ super arg
24
+ end
25
+
26
+ arg.each do |k, v|
27
+ instance_variable_set "@#{k}", v
28
+ end
29
+ else
30
+ super arg
31
+ end
32
+ end
33
+
34
+ # Override to_s to display a friendly error message
35
+ def to_s
36
+ message
37
+ end
38
+
39
+ def message
40
+ if @message.nil?
41
+ msg = "Error message: the server returns an error"
42
+ else
43
+ msg = @message
44
+ end
45
+
46
+ msg += "\nHTTP status code: #{code}" if code
47
+ msg += "\nResponse headers: #{response_headers}" if response_headers
48
+ msg += "\nResponse body: #{response_body}" if response_body
49
+
50
+ msg
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,268 @@
1
+ =begin
2
+ Trulioo Ruby SDK
3
+
4
+ Gem version: 1.0.3
5
+ Trulioo OpenAPI version: v1
6
+ Generated by OpenAPI Generator version: 5.0.1
7
+ =end
8
+
9
+ module Trulioo
10
+ class Configuration
11
+ # Defines url scheme
12
+ attr_accessor :scheme
13
+
14
+ # Defines url host
15
+ attr_accessor :host
16
+
17
+ # Defines url base path
18
+ attr_accessor :base_path
19
+
20
+ # Define server configuration index
21
+ attr_accessor :server_index
22
+
23
+ # Define server operation configuration index
24
+ attr_accessor :server_operation_index
25
+
26
+ # Default server variables
27
+ attr_accessor :server_variables
28
+
29
+ # Default server operation variables
30
+ attr_accessor :server_operation_variables
31
+
32
+ # Defines API keys used with API Key authentications.
33
+ #
34
+ # @return [Hash] key: parameter name, value: parameter value (API key)
35
+ #
36
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
37
+ # config.api_key['api_key'] = 'xxx'
38
+ attr_accessor :api_key
39
+
40
+ # Defines API key prefixes used with API Key authentications.
41
+ #
42
+ # @return [Hash] key: parameter name, value: API key prefix
43
+ #
44
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
45
+ # config.api_key_prefix['api_key'] = 'Token'
46
+ attr_accessor :api_key_prefix
47
+
48
+ # Defines the username used with HTTP basic authentication.
49
+ #
50
+ # @return [String]
51
+ attr_accessor :username
52
+
53
+ # Defines the password used with HTTP basic authentication.
54
+ #
55
+ # @return [String]
56
+ attr_accessor :password
57
+
58
+ # Defines the access token (Bearer) used with OAuth2.
59
+ attr_accessor :access_token
60
+
61
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
62
+ # details will be logged with `logger.debug` (see the `logger` attribute).
63
+ # Default to false.
64
+ #
65
+ # @return [true, false]
66
+ attr_accessor :debugging
67
+
68
+ # Defines the logger used for debugging.
69
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
70
+ #
71
+ # @return [#debug]
72
+ attr_accessor :logger
73
+
74
+ # Defines the temporary folder to store downloaded files
75
+ # (for API endpoints that have file response).
76
+ # Default to use `Tempfile`.
77
+ #
78
+ # @return [String]
79
+ attr_accessor :temp_folder_path
80
+
81
+ # The time limit for HTTP request in seconds.
82
+ # Default to 0 (never times out).
83
+ attr_accessor :timeout
84
+
85
+ # Set this to false to skip client side validation in the operation.
86
+ # Default to true.
87
+ # @return [true, false]
88
+ attr_accessor :client_side_validation
89
+
90
+ ### TLS/SSL setting
91
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
92
+ # Default to true.
93
+ #
94
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
95
+ #
96
+ # @return [true, false]
97
+ attr_accessor :ssl_verify
98
+
99
+ ### TLS/SSL setting
100
+ # Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html)
101
+ #
102
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
103
+ #
104
+ attr_accessor :ssl_verify_mode
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
+ attr_accessor :ssl_ca_file
111
+
112
+ ### TLS/SSL setting
113
+ # Client certificate file (for client certificate)
114
+ attr_accessor :ssl_client_cert
115
+
116
+ ### TLS/SSL setting
117
+ # Client private key file (for client certificate)
118
+ attr_accessor :ssl_client_key
119
+
120
+ # Set this to customize parameters encoding of array parameter with multi collectionFormat.
121
+ # Default to nil.
122
+ #
123
+ # @see The params_encoding option of Ethon. Related source code:
124
+ # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
125
+ attr_accessor :params_encoding
126
+
127
+ attr_accessor :inject_format
128
+
129
+ attr_accessor :force_ending_format
130
+
131
+ def initialize
132
+ @scheme = 'https'
133
+ @host = 'gateway.trulioo.com'
134
+ @base_path = ''
135
+ @server_index = 0
136
+ @server_operation_index = {}
137
+ @server_variables = {}
138
+ @server_operation_variables = {}
139
+ @api_key = {}
140
+ @api_key_prefix = {}
141
+ @timeout = 0
142
+ @client_side_validation = true
143
+ @ssl_verify = true
144
+ @ssl_verify_mode = nil
145
+ @ssl_ca_file = nil
146
+ @ssl_client_cert = nil
147
+ @ssl_client_key = nil
148
+ @debugging = false
149
+ @inject_format = false
150
+ @force_ending_format = false
151
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
152
+
153
+ yield(self) if block_given?
154
+ end
155
+
156
+ # The default Configuration object.
157
+ def self.default
158
+ @@default ||= Configuration.new
159
+ end
160
+
161
+ def configure
162
+ yield(self) if block_given?
163
+ end
164
+
165
+ def scheme=(scheme)
166
+ # remove :// from scheme
167
+ @scheme = scheme.sub(/:\/\//, '')
168
+ end
169
+
170
+ def host=(host)
171
+ # remove http(s):// and anything after a slash
172
+ @host = host.sub(/https?:\/\//, '').split('/').first
173
+ end
174
+
175
+ def base_path=(base_path)
176
+ # Add leading and trailing slashes to base_path
177
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
178
+ @base_path = '' if @base_path == '/'
179
+ end
180
+
181
+ # Returns base URL for specified operation based on server settings
182
+ def base_url(operation = nil)
183
+ index = server_operation_index.fetch(operation, server_index)
184
+ return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if index == nil
185
+
186
+ server_url(index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
187
+ end
188
+
189
+ # Gets API key (with prefix if set).
190
+ # @param [String] param_name the parameter name of API key auth
191
+ def api_key_with_prefix(param_name, param_alias = nil)
192
+ key = @api_key[param_name]
193
+ key = @api_key.fetch(param_alias, key) unless param_alias.nil?
194
+ if @api_key_prefix[param_name]
195
+ "#{@api_key_prefix[param_name]} #{key}"
196
+ else
197
+ key
198
+ end
199
+ end
200
+
201
+ # Gets Basic Auth token string
202
+ def basic_auth_token
203
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
204
+ end
205
+
206
+ # Returns Auth Settings hash for api client.
207
+ def auth_settings
208
+ {
209
+ 'ApiKeyAuth' =>
210
+ {
211
+ type: 'api_key',
212
+ in: 'header',
213
+ key: 'x-trulioo-api-key',
214
+ value: api_key_with_prefix('ApiKeyAuth')
215
+ },
216
+ }
217
+ end
218
+
219
+ # Returns an array of Server setting
220
+ def server_settings
221
+ [
222
+ {
223
+ url: "https://gateway.trulioo.com",
224
+ description: "No description provided",
225
+ }
226
+ ]
227
+ end
228
+
229
+ def operation_server_settings
230
+ {
231
+ }
232
+ end
233
+
234
+ # Returns URL based on server settings
235
+ #
236
+ # @param index array index of the server settings
237
+ # @param variables hash of variable and the corresponding value
238
+ def server_url(index, variables = {}, servers = nil)
239
+ servers = server_settings if servers == nil
240
+
241
+ # check array index out of bound
242
+ if (index < 0 || index >= servers.size)
243
+ fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
244
+ end
245
+
246
+ server = servers[index]
247
+ url = server[:url]
248
+
249
+ return url unless server.key? :variables
250
+
251
+ # go through variable and assign a value
252
+ server[:variables].each do |name, variable|
253
+ if variables.key?(name)
254
+ if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
255
+ url.gsub! "{" + name.to_s + "}", variables[name]
256
+ else
257
+ fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
258
+ end
259
+ else
260
+ # use default value
261
+ url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
262
+ end
263
+ end
264
+
265
+ url
266
+ end
267
+ end
268
+ end