avalara_sdk 2.4.5.6

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 (51) hide show
  1. checksums.yaml +7 -0
  2. data/Avalara.SDK.gemspec +38 -0
  3. data/Gemfile +9 -0
  4. data/README.md +129 -0
  5. data/Rakefile +10 -0
  6. data/TAGS +441 -0
  7. data/avalara_sdk.gemspec +36 -0
  8. data/docs/AgeVerificationApi.md +87 -0
  9. data/docs/AgeVerifyFailureCode.md +15 -0
  10. data/docs/AgeVerifyRequest.md +24 -0
  11. data/docs/AgeVerifyRequestAddress.md +26 -0
  12. data/docs/AgeVerifyResult.md +20 -0
  13. data/docs/ErrorDetails.md +18 -0
  14. data/docs/ErrorDetailsError.md +22 -0
  15. data/docs/ErrorDetailsErrorDetails.md +30 -0
  16. data/docs/ShippingVerificationApi.md +327 -0
  17. data/docs/ShippingVerifyResult.md +30 -0
  18. data/docs/ShippingVerifyResultLines.md +28 -0
  19. data/example/test.rb +25 -0
  20. data/git_push.sh +57 -0
  21. data/lib/avalara_sdk/api/age_verification_api.rb +95 -0
  22. data/lib/avalara_sdk/api/shipping_verification_api.rb +322 -0
  23. data/lib/avalara_sdk/api_client.rb +411 -0
  24. data/lib/avalara_sdk/api_error.rb +57 -0
  25. data/lib/avalara_sdk/configuration.rb +231 -0
  26. data/lib/avalara_sdk/models/age_verify_failure_code.rb +39 -0
  27. data/lib/avalara_sdk/models/age_verify_request.rb +245 -0
  28. data/lib/avalara_sdk/models/age_verify_request_address.rb +288 -0
  29. data/lib/avalara_sdk/models/age_verify_result.rb +230 -0
  30. data/lib/avalara_sdk/models/error_details.rb +217 -0
  31. data/lib/avalara_sdk/models/error_details_error.rb +271 -0
  32. data/lib/avalara_sdk/models/error_details_error_details.rb +324 -0
  33. data/lib/avalara_sdk/models/shipping_verify_result.rb +306 -0
  34. data/lib/avalara_sdk/models/shipping_verify_result_lines.rb +303 -0
  35. data/lib/avalara_sdk/version.rb +13 -0
  36. data/lib/avalara_sdk.rb +48 -0
  37. data/spec/api/age_verification_api_spec.rb +48 -0
  38. data/spec/api/shipping_verification_api_spec.rb +88 -0
  39. data/spec/api_client_spec.rb +224 -0
  40. data/spec/configuration_spec.rb +40 -0
  41. data/spec/models/age_verify_failure_code_spec.rb +28 -0
  42. data/spec/models/age_verify_request_address_spec.rb +62 -0
  43. data/spec/models/age_verify_request_spec.rb +52 -0
  44. data/spec/models/age_verify_result_spec.rb +40 -0
  45. data/spec/models/error_details_error_details_spec.rb +78 -0
  46. data/spec/models/error_details_error_spec.rb +50 -0
  47. data/spec/models/error_details_spec.rb +34 -0
  48. data/spec/models/shipping_verify_result_lines_spec.rb +72 -0
  49. data/spec/models/shipping_verify_result_spec.rb +78 -0
  50. data/spec/spec_helper.rb +108 -0
  51. metadata +147 -0
@@ -0,0 +1,411 @@
1
+ =begin
2
+ #Avalara Shipping Verification for Beverage Alcohol
3
+
4
+ #API for evaluating transactions against direct-to-consumer Beverage Alcohol shipping regulations. This API is currently in beta.
5
+
6
+ The version of the OpenAPI document: 2.1.0-beta
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.3.1
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'json'
15
+ require 'logger'
16
+ require 'tempfile'
17
+ require 'time'
18
+ require 'typhoeus'
19
+
20
+ module AvalaraSdk
21
+ class ApiClient
22
+ # The Configuration object holding settings to be used in the API client.
23
+ attr_accessor :config
24
+
25
+ # The sdk version to be set in header
26
+ attr_accessor :sdk_version
27
+
28
+ # Defines the headers to be used in HTTP requests of all API calls by default.
29
+ #
30
+ # @return [Hash]
31
+ attr_accessor :default_headers
32
+
33
+ # Initializes the ApiClient
34
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
35
+ def initialize(config)
36
+
37
+ if (config.nil?)
38
+ fail ArgumentError,'configuration is nil'
39
+ end
40
+
41
+ @base_path=config.base_url()
42
+ @sdk_version=""
43
+ @config = config
44
+ @default_headers = {
45
+ 'Content-Type' => 'application/json',
46
+ 'User-Agent' => @user_agent
47
+
48
+ }
49
+
50
+ end
51
+
52
+ def self.default
53
+ @@default ||= ApiClient.new
54
+ end
55
+
56
+ def set_sdk_version(sdk_version="")
57
+ @sdk_version=sdk_version
58
+ end
59
+ # Call an API with given options.
60
+ #
61
+ # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
62
+ # the data deserialized from response body (could be nil), response status code and response headers.
63
+ def call_api(http_method, path, opts = {})
64
+ request = build_request(http_method, path, opts)
65
+ response = request.run
66
+
67
+ if @config.debugging
68
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
69
+ end
70
+
71
+ unless response.success?
72
+ if response.timed_out?
73
+ fail ApiError.new('Connection timed out')
74
+ elsif response.code == 0
75
+ # Errors from libcurl will be made visible here
76
+ fail ApiError.new(:code => 0,
77
+ :message => response.return_message)
78
+ else
79
+ fail ApiError.new(:code => response.code,
80
+ :response_headers => response.headers,
81
+ :response_body => response.body),
82
+ response.status_message
83
+ end
84
+ end
85
+
86
+ if opts[:return_type]
87
+ data = deserialize(response, opts[:return_type])
88
+ else
89
+ data = nil
90
+ end
91
+ return data, response.code, response.headers
92
+ end
93
+
94
+ # Builds the HTTP request
95
+ #
96
+ # @param [String] http_method HTTP method/verb (e.g. POST)
97
+ # @param [String] path URL path (e.g. /account/new)
98
+ # @option opts [Hash] :header_params Header parameters
99
+ # @option opts [Hash] :query_params Query parameters
100
+ # @option opts [Hash] :form_params Query parameters
101
+ # @option opts [Object] :body HTTP body (JSON/XML)
102
+ # @return [Typhoeus::Request] A Typhoeus Request
103
+ def build_request(http_method, path, opts = {})
104
+ url = build_request_url(path, opts)
105
+ http_method = http_method.to_sym.downcase
106
+
107
+ header_params = @default_headers.merge(opts[:header_params] || {})
108
+ header_params['X-Avalara-Client']="#{@config.app_name};#{@config.app_version};RubySdk;#{@sdk_version};#{@config.machine_name}"
109
+ query_params = opts[:query_params] || {}
110
+ form_params = opts[:form_params] || {}
111
+
112
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
113
+
114
+ # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
115
+ _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
116
+
117
+ req_opts = {
118
+ :method => http_method,
119
+ :headers => header_params,
120
+ :params => query_params,
121
+ :params_encoding => @config.params_encoding,
122
+ :timeout => @config.timeout,
123
+ :ssl_verifypeer => @config.verify_ssl,
124
+ :ssl_verifyhost => _verify_ssl_host,
125
+ :sslcert => @config.cert_file,
126
+ :sslkey => @config.key_file,
127
+ :verbose => @config.debugging
128
+ }
129
+
130
+ # set custom cert, if provided
131
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
132
+
133
+ if [:post, :patch, :put, :delete].include?(http_method)
134
+ req_body = build_request_body(header_params, form_params, opts[:body])
135
+ req_opts.update :body => req_body
136
+ if @config.debugging
137
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
138
+ end
139
+ end
140
+
141
+ request = Typhoeus::Request.new(url, req_opts)
142
+ download_file(request) if opts[:return_type] == 'File'
143
+ request
144
+ end
145
+
146
+ # Builds the HTTP request body
147
+ #
148
+ # @param [Hash] header_params Header parameters
149
+ # @param [Hash] form_params Query parameters
150
+ # @param [Object] body HTTP body (JSON/XML)
151
+ # @return [String] HTTP body data in the form of string
152
+ def build_request_body(header_params, form_params, body)
153
+ # http form
154
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
155
+ header_params['Content-Type'] == 'multipart/form-data'
156
+ data = {}
157
+ form_params.each do |key, value|
158
+ case value
159
+ when ::File, ::Array, nil
160
+ # let typhoeus handle File, Array and nil parameters
161
+ data[key] = value
162
+ else
163
+ data[key] = value.to_s
164
+ end
165
+ end
166
+ elsif body
167
+ data = body.is_a?(String) ? body : body.to_json
168
+ else
169
+ data = nil
170
+ end
171
+ data
172
+ end
173
+
174
+ # Save response body into a file in (the defined) temporary folder, using the filename
175
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
176
+ # The response body is written to the file in chunks in order to handle files which
177
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
178
+ # process can use.
179
+ #
180
+ # @see Configuration#temp_folder_path
181
+ def download_file(request)
182
+ tempfile = nil
183
+ encoding = nil
184
+ request.on_headers do |response|
185
+ content_disposition = response.headers['Content-Disposition']
186
+ if content_disposition && content_disposition =~ /filename=/i
187
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
188
+ prefix = sanitize_filename(filename)
189
+ else
190
+ prefix = 'download-'
191
+ end
192
+ prefix = prefix + '-' unless prefix.end_with?('-')
193
+ encoding = response.body.encoding
194
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
195
+ @tempfile = tempfile
196
+ end
197
+ request.on_body do |chunk|
198
+ chunk.force_encoding(encoding)
199
+ tempfile.write(chunk)
200
+ end
201
+ request.on_complete do |response|
202
+ if tempfile
203
+ tempfile.close
204
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
205
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
206
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
207
+ "explicitly with `tempfile.delete`"
208
+ end
209
+ end
210
+ end
211
+
212
+ # Check if the given MIME is a JSON MIME.
213
+ # JSON MIME examples:
214
+ # application/json
215
+ # application/json; charset=UTF8
216
+ # APPLICATION/JSON
217
+ # */*
218
+ # @param [String] mime MIME
219
+ # @return [Boolean] True if the MIME is application/json
220
+ def json_mime?(mime)
221
+ (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
222
+ end
223
+
224
+ # Deserialize the response to the given return type.
225
+ #
226
+ # @param [Response] response HTTP response
227
+ # @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
228
+ def deserialize(response, return_type)
229
+ body = response.body
230
+
231
+ # handle file downloading - return the File instance processed in request callbacks
232
+ # note that response body is empty when the file is written in chunks in request on_body callback
233
+ return @tempfile if return_type == 'File'
234
+
235
+ return nil if body.nil? || body.empty?
236
+
237
+ # return response body directly for String return type
238
+ return body if return_type == 'String'
239
+
240
+ # ensuring a default content type
241
+ content_type = response.headers['Content-Type'] || 'application/json'
242
+
243
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
244
+
245
+ begin
246
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
247
+ rescue JSON::ParserError => e
248
+ if %w(String Date Time).include?(return_type)
249
+ data = body
250
+ else
251
+ raise e
252
+ end
253
+ end
254
+
255
+ convert_to_type data, return_type
256
+ end
257
+
258
+ # Convert data to the given return type.
259
+ # @param [Object] data Data to be converted
260
+ # @param [String] return_type Return type
261
+ # @return [Mixed] Data in a particular type
262
+ def convert_to_type(data, return_type)
263
+ return nil if data.nil?
264
+ case return_type
265
+ when 'String'
266
+ data.to_s
267
+ when 'Integer'
268
+ data.to_i
269
+ when 'Float'
270
+ data.to_f
271
+ when 'Boolean'
272
+ data == true
273
+ when 'Time'
274
+ # parse date time (expecting ISO 8601 format)
275
+ Time.parse data
276
+ when 'Date'
277
+ # parse date time (expecting ISO 8601 format)
278
+ Date.parse data
279
+ when 'Object'
280
+ # generic object (usually a Hash), return directly
281
+ data
282
+ when /\AArray<(.+)>\z/
283
+ # e.g. Array<Pet>
284
+ sub_type = $1
285
+ data.map { |item| convert_to_type(item, sub_type) }
286
+ when /\AHash\<String, (.+)\>\z/
287
+ # e.g. Hash<String, Integer>
288
+ sub_type = $1
289
+ {}.tap do |hash|
290
+ data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
291
+ end
292
+ else
293
+ # models (e.g. Pet) or oneOf
294
+ klass = AvalaraSdk.const_get(return_type)
295
+ klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
296
+ end
297
+ end
298
+
299
+ # Sanitize filename by removing path.
300
+ # e.g. ../../sun.gif becomes sun.gif
301
+ #
302
+ # @param [String] filename the filename to be sanitized
303
+ # @return [String] the sanitized filename
304
+ def sanitize_filename(filename)
305
+ filename.gsub(/.*[\/\\]/, '')
306
+ end
307
+
308
+ def build_request_url(path, opts = {})
309
+ # Add leading and trailing slashes to path
310
+ path = "/#{path}".gsub(/\/+/, '/')
311
+ @config.base_url() + path
312
+ end
313
+
314
+ # Update header and query params based on authentication settings.
315
+ #
316
+ # @param [Hash] header_params Header parameters
317
+ # @param [Hash] query_params Query parameters
318
+ # @param [String] auth_names Authentication scheme name
319
+ def update_params_for_auth!(header_params, query_params, auth_names)
320
+ Array(auth_names).each do |auth_name|
321
+ auth_setting = @config.auth_settings[auth_name]
322
+ next unless auth_setting
323
+ case auth_setting[:in]
324
+ when 'header' then
325
+ unless auth_setting[:value].nil?
326
+ header_params[auth_setting[:key]] = auth_setting[:value]
327
+ end
328
+ when 'query' then
329
+ unless auth_setting[:value].nil?
330
+ query_params[auth_setting[:key]] = auth_setting[:value]
331
+ end
332
+ else fail ArgumentError, 'Authentication token must be in `query` or `header`'
333
+ end
334
+ end
335
+ end
336
+
337
+ # Sets user agent in HTTP header
338
+ #
339
+ # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
340
+ def user_agent=(user_agent)
341
+ @user_agent = user_agent
342
+ @default_headers['User-Agent'] = @user_agent
343
+ end
344
+
345
+ # Return Accept header based on an array of accepts provided.
346
+ # @param [Array] accepts array for Accept
347
+ # @return [String] the Accept header (e.g. application/json)
348
+ def select_header_accept(accepts)
349
+ return nil if accepts.nil? || accepts.empty?
350
+ # use JSON when present, otherwise use all of the provided
351
+ json_accept = accepts.find { |s| json_mime?(s) }
352
+ json_accept || accepts.join(',')
353
+ end
354
+
355
+ # Return Content-Type header based on an array of content types provided.
356
+ # @param [Array] content_types array for Content-Type
357
+ # @return [String] the Content-Type header (e.g. application/json)
358
+ def select_header_content_type(content_types)
359
+ # return nil by default
360
+ return if content_types.nil? || content_types.empty?
361
+ # use JSON when present, otherwise use the first one
362
+ json_content_type = content_types.find { |s| json_mime?(s) }
363
+ json_content_type || content_types.first
364
+ end
365
+
366
+ # Convert object (array, hash, object, etc) to JSON string.
367
+ # @param [Object] model object to be converted into JSON string
368
+ # @return [String] JSON string representation of the object
369
+ def object_to_http_body(model)
370
+ return model if model.nil? || model.is_a?(String)
371
+ local_body = nil
372
+ if model.is_a?(Array)
373
+ local_body = model.map { |m| object_to_hash(m) }
374
+ else
375
+ local_body = object_to_hash(model)
376
+ end
377
+ local_body.to_json
378
+ end
379
+
380
+ # Convert object(non-array) to hash.
381
+ # @param [Object] obj object to be converted into JSON string
382
+ # @return [String] JSON string representation of the object
383
+ def object_to_hash(obj)
384
+ if obj.respond_to?(:to_hash)
385
+ obj.to_hash
386
+ else
387
+ obj
388
+ end
389
+ end
390
+
391
+ # Build parameter value according to the given collection format.
392
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
393
+ def build_collection_param(param, collection_format)
394
+ case collection_format
395
+ when :csv
396
+ param.join(',')
397
+ when :ssv
398
+ param.join(' ')
399
+ when :tsv
400
+ param.join("\t")
401
+ when :pipes
402
+ param.join('|')
403
+ when :multi
404
+ # return the array directly as typhoeus will handle it as expected
405
+ param
406
+ else
407
+ fail "unknown collection format: #{collection_format.inspect}"
408
+ end
409
+ end
410
+ end
411
+ end
@@ -0,0 +1,57 @@
1
+ =begin
2
+ #Avalara Shipping Verification for Beverage Alcohol
3
+
4
+ #API for evaluating transactions against direct-to-consumer Beverage Alcohol shipping regulations. This API is currently in beta.
5
+
6
+ The version of the OpenAPI document: 2.1.0-beta
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.3.1
10
+
11
+ =end
12
+
13
+ module AvalaraSdk
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
+
38
+ # Override to_s to display a friendly error message
39
+ def to_s
40
+ message
41
+ end
42
+
43
+ def message
44
+ if @message.nil?
45
+ msg = "Error message: the server returns an error"
46
+ else
47
+ msg = @message
48
+ end
49
+
50
+ msg += "\nHTTP status code: #{code}" if code
51
+ msg += "\nResponse headers: #{response_headers}" if response_headers
52
+ msg += "\nResponse body: #{response_body}" if response_body
53
+
54
+ msg
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,231 @@
1
+ =begin
2
+ #Avalara Shipping Verification for Beverage Alcohol
3
+
4
+ #API for evaluating transactions against direct-to-consumer Beverage Alcohol shipping regulations. This API is currently in beta.
5
+
6
+ =end
7
+
8
+
9
+ module AvalaraSdk
10
+ class Configuration
11
+
12
+ # Defines environment
13
+ attr_accessor :environment
14
+
15
+ # Defines environment
16
+ attr_accessor :test_url
17
+
18
+ # Defines url base path
19
+ attr_reader :base_path
20
+
21
+ # Defines API keys used with API Key authentications.
22
+ #
23
+ # @return [Hash] key: parameter name, value: parameter value (API key)
24
+ #
25
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
26
+ # config.api_key['api_key'] = 'xxx'
27
+ attr_accessor :api_key
28
+
29
+ # Defines API key prefixes used with API Key authentications.
30
+ #
31
+ # @return [Hash] key: parameter name, value: API key prefix
32
+ #
33
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
34
+ # config.api_key_prefix['api_key'] = 'Token'
35
+ attr_accessor :api_key_prefix
36
+
37
+ # Defines the username used with HTTP basic authentication.
38
+ #
39
+ # @return [String]
40
+ attr_accessor :username
41
+
42
+ # Defines the password used with HTTP basic authentication.
43
+ #
44
+ # @return [String]
45
+ attr_accessor :password
46
+
47
+ # Defines the access token (Bearer) used with OAuth2.
48
+ attr_accessor :access_token
49
+
50
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
51
+ # details will be logged with `logger.debug` (see the `logger` attribute).
52
+ # Default to false.
53
+ #
54
+ # @return [true, false]
55
+ attr_accessor :debugging
56
+
57
+ # Defines the logger used for debugging.
58
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
59
+ #
60
+ # @return [#debug]
61
+ attr_accessor :logger
62
+
63
+ # Defines the temporary folder to store downloaded files
64
+ # (for API endpoints that have file response).
65
+ # Default to use `Tempfile`.
66
+ #
67
+ # @return [String]
68
+ attr_accessor :temp_folder_path
69
+
70
+ # The time limit for HTTP request in seconds.
71
+ # Default to 0 (never times out).
72
+ attr_accessor :timeout
73
+
74
+ # Set this to false to skip client side validation in the operation.
75
+ # Default to true.
76
+ # @return [true, false]
77
+ attr_accessor :client_side_validation
78
+
79
+ ### TLS/SSL setting
80
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
81
+ # Default to true.
82
+ #
83
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
84
+ #
85
+ # @return [true, false]
86
+ attr_accessor :verify_ssl
87
+
88
+ ### TLS/SSL setting
89
+ # Set this to false to skip verifying SSL host name
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_host
96
+
97
+ ### TLS/SSL setting
98
+ # Set this to customize the certificate file to verify the peer.
99
+ #
100
+ # @return [String] the path to the certificate file
101
+ #
102
+ # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
103
+ # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
104
+ attr_accessor :ssl_ca_cert
105
+
106
+ ### TLS/SSL setting
107
+ # Client certificate file (for client certificate)
108
+ attr_accessor :cert_file
109
+
110
+ ### TLS/SSL setting
111
+ # Client private key file (for client certificate)
112
+ attr_accessor :key_file
113
+
114
+ # Set this to customize parameters encoding of array parameter with multi collectionFormat.
115
+ # Default to nil.
116
+ #
117
+ # @see The params_encoding option of Ethon. Related source code:
118
+ # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
119
+ attr_accessor :params_encoding
120
+
121
+ attr_accessor :inject_format
122
+
123
+ attr_accessor :force_ending_format
124
+
125
+ # Defines the application name
126
+ #
127
+ # @return [String]
128
+ attr_accessor :app_name
129
+
130
+ # Defines the application version
131
+ #
132
+ # @return [String]
133
+ attr_accessor :app_version
134
+
135
+ # Defines the machine name
136
+ #
137
+ # @return [String]
138
+ attr_accessor :machine_name
139
+
140
+ def initialize
141
+ @base_path = ''
142
+ @environment=''
143
+ @test_url=''
144
+ @app_name=''
145
+ @app_version=''
146
+ @machine_name=''
147
+ @api_key = {}
148
+ @api_key_prefix = {}
149
+ @client_side_validation = true
150
+ @verify_ssl = true
151
+ @verify_ssl_host = true
152
+ @params_encoding = nil
153
+ @cert_file = nil
154
+ @key_file = nil
155
+ @timeout = 0
156
+ @debugging = false
157
+ @inject_format = false
158
+ @force_ending_format = false
159
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
160
+
161
+ yield(self) if block_given?
162
+ end
163
+
164
+ # The default Configuration object.
165
+ def self.default
166
+ @@default ||= Configuration.new
167
+ end
168
+
169
+ def configure
170
+ yield(self) if block_given?
171
+ end
172
+
173
+
174
+ def base_path=(base_path)
175
+ @base_path=base_path
176
+ end
177
+
178
+ # Returns base URL for specified operation based on server settings
179
+ def base_url()
180
+
181
+ case environment.downcase
182
+ when 'sandbox'
183
+ return 'https://sandbox-rest.avatax.com'
184
+ when 'production'
185
+ return 'https://rest.avatax.com'
186
+ when 'test'
187
+ return test_url
188
+ else
189
+ fail ArgumentError, "Invalid environment value"
190
+ end
191
+ end
192
+
193
+ # Gets API key (with prefix if set).
194
+ # @param [String] param_name the parameter name of API key auth
195
+ def api_key_with_prefix(param_name, param_alias = nil)
196
+ key = @api_key[param_name]
197
+ key = @api_key.fetch(param_alias, key) unless param_alias.nil?
198
+ if @api_key_prefix[param_name]
199
+ "#{@api_key_prefix[param_name]} #{key}"
200
+ else
201
+ key
202
+ end
203
+ end
204
+
205
+ # Gets Basic Auth token string
206
+ def basic_auth_token
207
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
208
+ end
209
+
210
+ # Returns Auth Settings hash for api client.
211
+ def auth_settings
212
+ {
213
+ 'BasicAuth' =>
214
+ {
215
+ type: 'basic',
216
+ in: 'header',
217
+ key: 'Authorization',
218
+ value: basic_auth_token
219
+ },
220
+ 'Bearer' =>
221
+ {
222
+ type: 'api_key',
223
+ in: 'header',
224
+ key: 'Authorization',
225
+ value: api_key_with_prefix('Bearer')
226
+ },
227
+ }
228
+ end
229
+
230
+ end
231
+ end