pier-sdk-ruby 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/README.md +141 -0
  2. data/docs/AuthToken.md +12 -0
  3. data/docs/BodyAccessToken.md +10 -0
  4. data/docs/CancelarCartaoResponse.md +11 -0
  5. data/docs/CartaoApi.md +252 -0
  6. data/docs/CartaoResponse.md +29 -0
  7. data/docs/ConsultarCartaoResponse.md +10 -0
  8. data/docs/ConsultarContaCartaoResponse.md +18 -0
  9. data/docs/ConsultarContaResponse.md +11 -0
  10. data/docs/ConsultarExtratoContaResponse.md +23 -0
  11. data/docs/ConsultarSaldoLimitesResponse.md +23 -0
  12. data/docs/ContaApi.md +238 -0
  13. data/docs/ContaCartaoResponse.md +21 -0
  14. data/docs/ContaResponse.md +41 -0
  15. data/docs/DesbloquearCartaoResponse.md +9 -0
  16. data/docs/ExtraInfo.md +8 -0
  17. data/docs/ExtratoResponse.md +35 -0
  18. data/docs/PessoaFisicaResponse.md +26 -0
  19. data/docs/SaldoLimiteResponse.md +39 -0
  20. data/docs/TokenApi.md +114 -0
  21. data/git_push.sh +52 -0
  22. data/lib/pier-sdk-ruby.rb +62 -0
  23. data/lib/pier-sdk-ruby/api/cartao_api.rb +355 -0
  24. data/lib/pier-sdk-ruby/api/conta_api.rb +324 -0
  25. data/lib/pier-sdk-ruby/api/token_api.rb +157 -0
  26. data/lib/pier-sdk-ruby/api_client.rb +368 -0
  27. data/lib/pier-sdk-ruby/api_error.rb +40 -0
  28. data/lib/pier-sdk-ruby/configuration.rb +177 -0
  29. data/lib/pier-sdk-ruby/models/auth_token.rb +325 -0
  30. data/lib/pier-sdk-ruby/models/body_access_token.rb +275 -0
  31. data/lib/pier-sdk-ruby/models/cancelar_cartao_response.rb +286 -0
  32. data/lib/pier-sdk-ruby/models/cartao_response.rb +736 -0
  33. data/lib/pier-sdk-ruby/models/consultar_cartao_response.rb +263 -0
  34. data/lib/pier-sdk-ruby/models/consultar_conta_cartao_response.rb +461 -0
  35. data/lib/pier-sdk-ruby/models/consultar_conta_response.rb +288 -0
  36. data/lib/pier-sdk-ruby/models/consultar_extrato_conta_response.rb +588 -0
  37. data/lib/pier-sdk-ruby/models/consultar_saldo_limites_response.rb +586 -0
  38. data/lib/pier-sdk-ruby/models/conta_cartao_response.rb +536 -0
  39. data/lib/pier-sdk-ruby/models/conta_response.rb +1036 -0
  40. data/lib/pier-sdk-ruby/models/desbloquear_cartao_response.rb +236 -0
  41. data/lib/pier-sdk-ruby/models/extra_info.rb +211 -0
  42. data/lib/pier-sdk-ruby/models/extrato_response.rb +886 -0
  43. data/lib/pier-sdk-ruby/models/pessoa_fisica_response.rb +661 -0
  44. data/lib/pier-sdk-ruby/models/saldo_limite_response.rb +986 -0
  45. data/lib/pier-sdk-ruby/version.rb +19 -0
  46. data/pier-sdk-ruby.gemspec +33 -0
  47. data/spec/api/cartao_api_spec.rb +110 -0
  48. data/spec/api/conta_api_spec.rb +107 -0
  49. data/spec/api/token_api_spec.rb +71 -0
  50. data/spec/models/auth_token_spec.rb +90 -0
  51. data/spec/models/body_access_token_spec.rb +70 -0
  52. data/spec/models/cancelar_cartao_response_spec.rb +80 -0
  53. data/spec/models/cartao_response_spec.rb +260 -0
  54. data/spec/models/consultar_cartao_response_spec.rb +70 -0
  55. data/spec/models/consultar_conta_cartao_response_spec.rb +150 -0
  56. data/spec/models/consultar_conta_response_spec.rb +80 -0
  57. data/spec/models/consultar_extrato_conta_response_spec.rb +200 -0
  58. data/spec/models/consultar_saldo_limites_response_spec.rb +200 -0
  59. data/spec/models/conta_cartao_response_spec.rb +180 -0
  60. data/spec/models/conta_response_spec.rb +380 -0
  61. data/spec/models/desbloquear_cartao_response_spec.rb +60 -0
  62. data/spec/models/extra_info_spec.rb +50 -0
  63. data/spec/models/extrato_response_spec.rb +320 -0
  64. data/spec/models/pessoa_fisica_response_spec.rb +230 -0
  65. data/spec/models/saldo_limite_response_spec.rb +360 -0
  66. metadata +310 -0
@@ -0,0 +1,368 @@
1
+ =begin
2
+ CaaS - Conductor as a Service
3
+
4
+ Gest\u00C3\u00A3o de pagamento eletr\u00C3\u00B4nicos como servi\u00C3\u00A7o
5
+
6
+ OpenAPI spec version: 0.0.1
7
+ Contact: contato@conductor.com.br
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+
10
+ License: Apache 2.0
11
+ http://www.apache.org/licenses/LICENSE-2.0.html
12
+
13
+ Terms of Service: http://dev.conductor.com.br/terms/
14
+
15
+ =end
16
+
17
+ require 'date'
18
+ require 'json'
19
+ require 'logger'
20
+ require 'tempfile'
21
+ require 'typhoeus'
22
+ require 'uri'
23
+
24
+ module Pier
25
+ class ApiClient
26
+ # The Configuration object holding settings to be used in the API client.
27
+ attr_accessor :config
28
+
29
+ # Defines the headers to be used in HTTP requests of all API calls by default.
30
+ #
31
+ # @return [Hash]
32
+ attr_accessor :default_headers
33
+
34
+ # Initializes the ApiClient
35
+ # @option config [Configuration] Configuraiton for initializing the object, default to Configuration.default
36
+ def initialize(config = Configuration.default)
37
+ @config = config
38
+ @user_agent = "Swagger-Codegen/#{VERSION}/ruby"
39
+ @default_headers = {
40
+ 'Content-Type' => "application/json",
41
+ 'User-Agent' => @user_agent
42
+ }
43
+ end
44
+
45
+ def self.default
46
+ @@default ||= ApiClient.new
47
+ end
48
+
49
+ # Call an API with given options.
50
+ #
51
+ # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
52
+ # the data deserialized from response body (could be nil), response status code and response headers.
53
+ def call_api(http_method, path, opts = {})
54
+ request = build_request(http_method, path, opts)
55
+ response = request.run
56
+
57
+ if @config.debugging
58
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
59
+ end
60
+
61
+ unless response.success?
62
+ fail ApiError.new(:code => response.code,
63
+ :response_headers => response.headers,
64
+ :response_body => response.body),
65
+ response.status_message
66
+ end
67
+
68
+ if opts[:return_type]
69
+ data = deserialize(response, opts[:return_type])
70
+ else
71
+ data = nil
72
+ end
73
+ return data, response.code, response.headers
74
+ end
75
+
76
+ # Builds the HTTP request
77
+ #
78
+ # @param [String] http_method HTTP method/verb (e.g. POST)
79
+ # @param [String] path URL path (e.g. /account/new)
80
+ # @option opts [Hash] :header_params Header parameters
81
+ # @option opts [Hash] :query_params Query parameters
82
+ # @option opts [Hash] :form_params Query parameters
83
+ # @option opts [Object] :body HTTP body (JSON/XML)
84
+ # @return [Typhoeus::Request] A Typhoeus Request
85
+ def build_request(http_method, path, opts = {})
86
+ url = build_request_url(path)
87
+ http_method = http_method.to_sym.downcase
88
+
89
+ header_params = @default_headers.merge(opts[:header_params] || {})
90
+ query_params = opts[:query_params] || {}
91
+ form_params = opts[:form_params] || {}
92
+
93
+
94
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
95
+
96
+
97
+ req_opts = {
98
+ :method => http_method,
99
+ :headers => header_params,
100
+ :params => query_params,
101
+ :timeout => @config.timeout,
102
+ :ssl_verifypeer => @config.verify_ssl,
103
+ :sslcert => @config.cert_file,
104
+ :sslkey => @config.key_file,
105
+ :verbose => @config.debugging
106
+ }
107
+
108
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
109
+
110
+ if [:post, :patch, :put, :delete].include?(http_method)
111
+ req_body = build_request_body(header_params, form_params, opts[:body])
112
+ req_opts.update :body => req_body
113
+ if @config.debugging
114
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
115
+ end
116
+ end
117
+
118
+ Typhoeus::Request.new(url, req_opts)
119
+ end
120
+
121
+ # Check if the given MIME is a JSON MIME.
122
+ # JSON MIME examples:
123
+ # application/json
124
+ # application/json; charset=UTF8
125
+ # APPLICATION/JSON
126
+ # @param [String] mime MIME
127
+ # @return [Boolean] True if the MIME is applicaton/json
128
+ def json_mime?(mime)
129
+ !(mime =~ /\Aapplication\/json(;.*)?\z/i).nil?
130
+ end
131
+
132
+ # Deserialize the response to the given return type.
133
+ #
134
+ # @param [Response] response HTTP response
135
+ # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
136
+ def deserialize(response, return_type)
137
+ body = response.body
138
+ return nil if body.nil? || body.empty?
139
+
140
+ # return response body directly for String return type
141
+ return body if return_type == 'String'
142
+
143
+ # handle file downloading - save response body into a tmp file and return the File instance
144
+ return download_file(response) if return_type == 'File'
145
+
146
+ # ensuring a default content type
147
+ content_type = response.headers['Content-Type'] || 'application/json'
148
+
149
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
150
+
151
+ begin
152
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
153
+ rescue JSON::ParserError => e
154
+ if %w(String Date DateTime).include?(return_type)
155
+ data = body
156
+ else
157
+ raise e
158
+ end
159
+ end
160
+
161
+ convert_to_type data, return_type
162
+ end
163
+
164
+ # Convert data to the given return type.
165
+ # @param [Object] data Data to be converted
166
+ # @param [String] return_type Return type
167
+ # @return [Mixed] Data in a particular type
168
+ def convert_to_type(data, return_type)
169
+ return nil if data.nil?
170
+ case return_type
171
+ when 'String'
172
+ data.to_s
173
+ when 'Integer'
174
+ data.to_i
175
+ when 'Float'
176
+ data.to_f
177
+ when 'BOOLEAN'
178
+ data == true
179
+ when 'DateTime'
180
+ # parse date time (expecting ISO 8601 format)
181
+ DateTime.parse data
182
+ when 'Date'
183
+ # parse date time (expecting ISO 8601 format)
184
+ Date.parse data
185
+ when 'Object'
186
+ # generic object (usually a Hash), return directly
187
+ data
188
+ when /\AArray<(.+)>\z/
189
+ # e.g. Array<Pet>
190
+ sub_type = $1
191
+ data.map {|item| convert_to_type(item, sub_type) }
192
+ when /\AHash\<String, (.+)\>\z/
193
+ # e.g. Hash<String, Integer>
194
+ sub_type = $1
195
+ {}.tap do |hash|
196
+ data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
197
+ end
198
+ else
199
+ # models, e.g. Pet
200
+ Pier.const_get(return_type).new.tap do |model|
201
+ model.build_from_hash data
202
+ end
203
+ end
204
+ end
205
+
206
+ # Save response body into a file in (the defined) temporary folder, using the filename
207
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
208
+ #
209
+ # @see Configuration#temp_folder_path
210
+ # @return [Tempfile] the file downloaded
211
+ def download_file(response)
212
+ content_disposition = response.headers['Content-Disposition']
213
+ if content_disposition
214
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
215
+ prefix = sanitize_filename(filename)
216
+ else
217
+ prefix = 'download-'
218
+ end
219
+ prefix = prefix + '-' unless prefix.end_with?('-')
220
+
221
+ tempfile = nil
222
+ encoding = response.body.encoding
223
+ Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) do |file|
224
+ file.write(response.body)
225
+ tempfile = file
226
+ end
227
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
228
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
229
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
230
+ "explicitly with `tempfile.delete`"
231
+ tempfile
232
+ end
233
+
234
+ # Sanitize filename by removing path.
235
+ # e.g. ../../sun.gif becomes sun.gif
236
+ #
237
+ # @param [String] filename the filename to be sanitized
238
+ # @return [String] the sanitized filename
239
+ def sanitize_filename(filename)
240
+ filename.gsub(/.*[\/\\]/, '')
241
+ end
242
+
243
+ def build_request_url(path)
244
+ # Add leading and trailing slashes to path
245
+ path = "/#{path}".gsub(/\/+/, '/')
246
+ URI.encode(@config.base_url + path)
247
+ end
248
+
249
+ # Builds the HTTP request body
250
+ #
251
+ # @param [Hash] header_params Header parameters
252
+ # @param [Hash] form_params Query parameters
253
+ # @param [Object] body HTTP body (JSON/XML)
254
+ # @return [String] HTTP body data in the form of string
255
+ def build_request_body(header_params, form_params, body)
256
+ # http form
257
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
258
+ header_params['Content-Type'] == 'multipart/form-data'
259
+ data = {}
260
+ form_params.each do |key, value|
261
+ case value
262
+ when File, Array, nil
263
+ # let typhoeus handle File, Array and nil parameters
264
+ data[key] = value
265
+ else
266
+ data[key] = value.to_s
267
+ end
268
+ end
269
+ elsif body
270
+ data = body.is_a?(String) ? body : body.to_json
271
+ else
272
+ data = nil
273
+ end
274
+ data
275
+ end
276
+
277
+ # Update hearder and query params based on authentication settings.
278
+ #
279
+ # @param [Hash] header_params Header parameters
280
+ # @param [Hash] form_params Query parameters
281
+ # @param [String] auth_names Authentication scheme name
282
+ def update_params_for_auth!(header_params, query_params, auth_names)
283
+ Array(auth_names).each do |auth_name|
284
+ auth_setting = @config.auth_settings[auth_name]
285
+ next unless auth_setting
286
+ case auth_setting[:in]
287
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
288
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
289
+ else fail ArgumentError, 'Authentication token must be in `query` of `header`'
290
+ end
291
+ end
292
+ end
293
+
294
+ # Sets user agent in HTTP header
295
+ #
296
+ # @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
297
+ def user_agent=(user_agent)
298
+ @user_agent = user_agent
299
+ @default_headers['User-Agent'] = @user_agent
300
+ end
301
+
302
+ # Return Accept header based on an array of accepts provided.
303
+ # @param [Array] accepts array for Accept
304
+ # @return [String] the Accept header (e.g. application/json)
305
+ def select_header_accept(accepts)
306
+ return nil if accepts.nil? || accepts.empty?
307
+ # use JSON when present, otherwise use all of the provided
308
+ json_accept = accepts.find { |s| json_mime?(s) }
309
+ return json_accept || accepts.join(',')
310
+ end
311
+
312
+ # Return Content-Type header based on an array of content types provided.
313
+ # @param [Array] content_types array for Content-Type
314
+ # @return [String] the Content-Type header (e.g. application/json)
315
+ def select_header_content_type(content_types)
316
+ # use application/json by default
317
+ return 'application/json' if content_types.nil? || content_types.empty?
318
+ # use JSON when present, otherwise use the first one
319
+ json_content_type = content_types.find { |s| json_mime?(s) }
320
+ return json_content_type || content_types.first
321
+ end
322
+
323
+ # Convert object (array, hash, object, etc) to JSON string.
324
+ # @param [Object] model object to be converted into JSON string
325
+ # @return [String] JSON string representation of the object
326
+ def object_to_http_body(model)
327
+ return model if model.nil? || model.is_a?(String)
328
+ local_body = nil
329
+ if model.is_a?(Array)
330
+ local_body = model.map{|m| object_to_hash(m) }
331
+ else
332
+ local_body = object_to_hash(model)
333
+ end
334
+ local_body.to_json
335
+ end
336
+
337
+ # Convert object(non-array) to hash.
338
+ # @param [Object] obj object to be converted into JSON string
339
+ # @return [String] JSON string representation of the object
340
+ def object_to_hash(obj)
341
+ if obj.respond_to?(:to_hash)
342
+ obj.to_hash
343
+ else
344
+ obj
345
+ end
346
+ end
347
+
348
+ # Build parameter value according to the given collection format.
349
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
350
+ def build_collection_param(param, collection_format)
351
+ case collection_format
352
+ when :csv
353
+ param.join(',')
354
+ when :ssv
355
+ param.join(' ')
356
+ when :tsv
357
+ param.join("\t")
358
+ when :pipes
359
+ param.join('|')
360
+ when :multi
361
+ # return the array directly as typhoeus will handle it as expected
362
+ param
363
+ else
364
+ fail "unknown collection format: #{collection_format.inspect}"
365
+ end
366
+ end
367
+ end
368
+ end
@@ -0,0 +1,40 @@
1
+ =begin
2
+ CaaS - Conductor as a Service
3
+
4
+ Gest\u00C3\u00A3o de pagamento eletr\u00C3\u00B4nicos como servi\u00C3\u00A7o
5
+
6
+ OpenAPI spec version: 0.0.1
7
+ Contact: contato@conductor.com.br
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+
10
+ License: Apache 2.0
11
+ http://www.apache.org/licenses/LICENSE-2.0.html
12
+
13
+ Terms of Service: http://dev.conductor.com.br/terms/
14
+
15
+ =end
16
+
17
+ module Pier
18
+ class ApiError < StandardError
19
+ attr_reader :code, :response_headers, :response_body
20
+
21
+ # Usage examples:
22
+ # ApiError.new
23
+ # ApiError.new("message")
24
+ # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
25
+ # ApiError.new(:code => 404, :message => "Not Found")
26
+ def initialize(arg = nil)
27
+ if arg.is_a? Hash
28
+ arg.each do |k, v|
29
+ if k.to_s == 'message'
30
+ super v
31
+ else
32
+ instance_variable_set "@#{k}", v
33
+ end
34
+ end
35
+ else
36
+ super arg
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,177 @@
1
+ require 'uri'
2
+
3
+ module Pier
4
+ class Configuration
5
+ # Defines url scheme
6
+ attr_accessor :scheme
7
+
8
+ # Defines url host
9
+ attr_accessor :host
10
+
11
+ # Defines url base path
12
+ attr_accessor :base_path
13
+
14
+ # Defines API keys used with API Key authentications.
15
+ #
16
+ # @return [Hash] key: parameter name, value: parameter value (API key)
17
+ #
18
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
19
+ # config.api_key['api_key'] = 'xxx'
20
+ attr_accessor :api_key
21
+
22
+ # Defines API key prefixes used with API Key authentications.
23
+ #
24
+ # @return [Hash] key: parameter name, value: API key prefix
25
+ #
26
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
27
+ # config.api_key_prefix['api_key'] = 'Token'
28
+ attr_accessor :api_key_prefix
29
+
30
+ # Defines the username used with HTTP basic authentication.
31
+ #
32
+ # @return [String]
33
+ attr_accessor :username
34
+
35
+ # Defines the password used with HTTP basic authentication.
36
+ #
37
+ # @return [String]
38
+ attr_accessor :password
39
+
40
+ # Defines the access token (Bearer) used with OAuth2.
41
+ attr_accessor :access_token
42
+
43
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
44
+ # details will be logged with `logger.debug` (see the `logger` attribute).
45
+ # Default to false.
46
+ #
47
+ # @return [true, false]
48
+ attr_accessor :debugging
49
+
50
+ # Defines the logger used for debugging.
51
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
52
+ #
53
+ # @return [#debug]
54
+ attr_accessor :logger
55
+
56
+ # Defines the temporary folder to store downloaded files
57
+ # (for API endpoints that have file response).
58
+ # Default to use `Tempfile`.
59
+ #
60
+ # @return [String]
61
+ attr_accessor :temp_folder_path
62
+
63
+ # The time limit for HTTP request in seconds.
64
+ # Default to 0 (never times out).
65
+ attr_accessor :timeout
66
+
67
+ ### TLS/SSL
68
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
69
+ # Default to true.
70
+ #
71
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
72
+ #
73
+ # @return [true, false]
74
+ attr_accessor :verify_ssl
75
+
76
+ # Set this to customize the certificate file to verify the peer.
77
+ #
78
+ # @return [String] the path to the certificate file
79
+ #
80
+ # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
81
+ # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
82
+ attr_accessor :ssl_ca_cert
83
+
84
+ # Client certificate file (for client certificate)
85
+ attr_accessor :cert_file
86
+
87
+ # Client private key file (for client certificate)
88
+ attr_accessor :key_file
89
+
90
+ attr_accessor :inject_format
91
+
92
+ attr_accessor :force_ending_format
93
+
94
+ def initialize
95
+ @scheme = 'https'
96
+ @host = 'localhost'
97
+ @base_path = '/'
98
+ @api_key = {}
99
+ @api_key_prefix = {}
100
+ @timeout = 0
101
+ @verify_ssl = true
102
+ @cert_file = nil
103
+ @key_file = nil
104
+ @debugging = false
105
+ @inject_format = false
106
+ @force_ending_format = false
107
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
108
+
109
+ yield(self) if block_given?
110
+ end
111
+
112
+ # The default Configuration object.
113
+ def self.default
114
+ @@default ||= Configuration.new
115
+ end
116
+
117
+ def configure
118
+ yield(self) if block_given?
119
+ end
120
+
121
+ def scheme=(scheme)
122
+ # remove :// from scheme
123
+ @scheme = scheme.sub(/:\/\//, '')
124
+ end
125
+
126
+ def host=(host)
127
+ # remove http(s):// and anything after a slash
128
+ @host = host.sub(/https?:\/\//, '').split('/').first
129
+ end
130
+
131
+ def base_path=(base_path)
132
+ # Add leading and trailing slashes to base_path
133
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
134
+ @base_path = "" if @base_path == "/"
135
+ end
136
+
137
+ def base_url
138
+ url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
139
+ URI.encode(url)
140
+ end
141
+
142
+ # Gets API key (with prefix if set).
143
+ # @param [String] param_name the parameter name of API key auth
144
+ def api_key_with_prefix(param_name)
145
+ if @api_key_prefix[param_name]
146
+ "#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
147
+ else
148
+ @api_key[param_name]
149
+ end
150
+ end
151
+
152
+ # Gets Basic Auth token string
153
+ def basic_auth_token
154
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
155
+ end
156
+
157
+ # Returns Auth Settings hash for api client.
158
+ def auth_settings
159
+ {
160
+ 'access_token' =>
161
+ {
162
+ type: 'api_key',
163
+ in: 'header',
164
+ key: 'access_token',
165
+ value: api_key_with_prefix('access_token')
166
+ },
167
+ 'client_id' =>
168
+ {
169
+ type: 'api_key',
170
+ in: 'header',
171
+ key: 'client_id',
172
+ value: api_key_with_prefix('client_id')
173
+ },
174
+ }
175
+ end
176
+ end
177
+ end