Class: MinatoRubyApiClient::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/minato_ruby_api_client/configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Configuration

Returns a new instance of Configuration.

Yields:

  • (_self)

Yield Parameters:



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/minato_ruby_api_client/configuration.rb', line 110

def initialize
  @scheme = 'https'
  @host = ''
  @base_path = ''
  @user_agent = ''
  @subscription_key = ''
  @api_key = {}
  @api_key_prefix = {}
  @client_side_validation = true
  @ssl_verify = true
  @ssl_verify_mode = nil
  @ssl_ca_file = nil
  @ssl_client_cert = nil
  @ssl_client_key = nil
  @middlewares = []
  @request_middlewares = []
  @response_middlewares = []
  @timeout = 60
  @debugging = false
  @logger = Object.const_defined?(:Rails) ? Rails.logger : Logger.new(STDOUT)

  yield(self) if block_given?
end

Instance Attribute Details

#access_tokenObject

Defines the access token (Bearer) used with OAuth2.



42
43
44
# File 'lib/minato_ruby_api_client/configuration.rb', line 42

def access_token
  @access_token
end

#api_keyHash

Defines API keys used with API Key authentications.

Examples:

parameter name is “api_key”, API key is “xxx” (e.g. “api_key=xxx” in query string)

config.api_key['api_key'] = 'xxx'

Returns:

  • (Hash)

    key: parameter name, value: parameter value (API key)



21
22
23
# File 'lib/minato_ruby_api_client/configuration.rb', line 21

def api_key
  @api_key
end

#api_key_prefixHash

Defines API key prefixes used with API Key authentications.

Examples:

parameter name is “Authorization”, API key prefix is “Token” (e.g. “Authorization: Token xxx” in headers)

config.api_key_prefix['api_key'] = 'Token'

Returns:

  • (Hash)

    key: parameter name, value: API key prefix



29
30
31
# File 'lib/minato_ruby_api_client/configuration.rb', line 29

def api_key_prefix
  @api_key_prefix
end

#base_pathObject

Defines url base path



10
11
12
# File 'lib/minato_ruby_api_client/configuration.rb', line 10

def base_path
  @base_path
end

#client_side_validationtrue, false

Set this to false to skip client side validation in the operation. Default to true.

Returns:

  • (true, false)


71
72
73
# File 'lib/minato_ruby_api_client/configuration.rb', line 71

def client_side_validation
  @client_side_validation
end

#debuggingtrue, false

Set this to enable/disable debugging. When enabled (set to true), HTTP request/response details will be logged with ‘logger.debug` (see the `logger` attribute). Default to false.

Returns:

  • (true, false)


49
50
51
# File 'lib/minato_ruby_api_client/configuration.rb', line 49

def debugging
  @debugging
end

#hostObject

Defines url host



7
8
9
# File 'lib/minato_ruby_api_client/configuration.rb', line 7

def host
  @host
end

#logger#debug

Defines the logger used for debugging. Default to ‘Rails.logger` (when in Rails) or logging to STDOUT.

Returns:

  • (#debug)


55
56
57
# File 'lib/minato_ruby_api_client/configuration.rb', line 55

def logger
  @logger
end

#params_encodingObject

Set this to customize parameters encoding of array parameter with multi collectionFormat. Default to nil.

github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96

See Also:

  • params_encoding option of Ethon. Related source code:


108
109
110
# File 'lib/minato_ruby_api_client/configuration.rb', line 108

def params_encoding
  @params_encoding
end

#passwordString

Defines the password used with HTTP basic authentication.

Returns:

  • (String)


39
40
41
# File 'lib/minato_ruby_api_client/configuration.rb', line 39

def password
  @password
end

#schemeObject

Defines url scheme



4
5
6
# File 'lib/minato_ruby_api_client/configuration.rb', line 4

def scheme
  @scheme
end

#ssl_ca_fileString

TLS/SSL setting Set this to customize the certificate file to verify the peer.

Returns:

  • (String)

    the path to the certificate file



93
94
95
# File 'lib/minato_ruby_api_client/configuration.rb', line 93

def ssl_ca_file
  @ssl_ca_file
end

#ssl_client_certObject

TLS/SSL setting Client certificate file (for client certificate)



97
98
99
# File 'lib/minato_ruby_api_client/configuration.rb', line 97

def ssl_client_cert
  @ssl_client_cert
end

#ssl_client_keyObject

TLS/SSL setting Client private key file (for client certificate)



101
102
103
# File 'lib/minato_ruby_api_client/configuration.rb', line 101

def ssl_client_key
  @ssl_client_key
end

#ssl_verifytrue, false

Note:

Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.

TLS/SSL setting Set this to false to skip verifying SSL certificate when calling API from https server. Default to true.

Returns:

  • (true, false)


80
81
82
# File 'lib/minato_ruby_api_client/configuration.rb', line 80

def ssl_verify
  @ssl_verify
end

#ssl_verify_modeObject

Note:

Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.

TLS/SSL setting Any ‘OpenSSL::SSL::` constant (see ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html)



87
88
89
# File 'lib/minato_ruby_api_client/configuration.rb', line 87

def ssl_verify_mode
  @ssl_verify_mode
end

#temp_folder_pathString

Defines the temporary folder to store downloaded files (for API endpoints that have file response). Default to use ‘Tempfile`.

Returns:

  • (String)


62
63
64
# File 'lib/minato_ruby_api_client/configuration.rb', line 62

def temp_folder_path
  @temp_folder_path
end

#timeoutObject

The time limit for HTTP request in seconds. Default to 0 (never times out).



66
67
68
# File 'lib/minato_ruby_api_client/configuration.rb', line 66

def timeout
  @timeout
end

#user_agentObject

Defines user agent



13
14
15
# File 'lib/minato_ruby_api_client/configuration.rb', line 13

def user_agent
  @user_agent
end

#usernameString

Defines the username used with HTTP basic authentication.

Returns:

  • (String)


34
35
36
# File 'lib/minato_ruby_api_client/configuration.rb', line 34

def username
  @username
end

Class Method Details

.defaultObject

The default Configuration object.



135
136
137
# File 'lib/minato_ruby_api_client/configuration.rb', line 135

def self.default
  @@default ||= Configuration.new
end

Instance Method Details

#api_key_with_prefix(param_name, param_alias = nil) ⇒ Object

Gets API key (with prefix if set).

Parameters:

  • param_name (String)

    the parameter name of API key auth



171
172
173
174
175
176
177
178
179
# File 'lib/minato_ruby_api_client/configuration.rb', line 171

def api_key_with_prefix(param_name, param_alias = nil)
  key = @api_key[param_name]
  key = @api_key.fetch(param_alias, key) unless param_alias.nil?
  if @api_key_prefix[param_name]
    "#{@api_key_prefix[param_name]} #{key}"
  else
    key
  end
end

#auth_settingsObject

Returns Auth Settings hash for api client.



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/minato_ruby_api_client/configuration.rb', line 187

def auth_settings
  auth_settings = {
    'bearer_auth' =>
      {
        type: 'bearer',
        in: 'header',
        key: 'Authorization',
        value: "Bearer #{access_token}"
      },
    'basic_auth' =>
      {
        type: 'basic',
        in: 'header',
        key: 'Authorization',
        value: basic_auth_token
      },
  }

  api_key.each do |k, v|
    auth_settings['apikey'] = {
      type: 'apikey',
      in: 'header',
      key: k,
      value: api_key_with_prefix(k)
    }
  end

  auth_settings
end

#base_urlObject

Returns base URL



160
161
162
# File 'lib/minato_ruby_api_client/configuration.rb', line 160

def base_url
  "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
end

#basic_auth_tokenObject

Gets Basic Auth token string



182
183
184
# File 'lib/minato_ruby_api_client/configuration.rb', line 182

def basic_auth_token
  'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
end

#configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



139
140
141
# File 'lib/minato_ruby_api_client/configuration.rb', line 139

def configure
  yield(self) if block_given?
end

#configure_middleware(connection) ⇒ Object

Set up middleware on the connection



233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/minato_ruby_api_client/configuration.rb', line 233

def configure_middleware(connection)
  @middlewares.each do |middleware|
    connection.use(*middleware)
  end

  @request_middlewares.each do |middleware|
    connection.request(*middleware)
  end

  @response_middlewares.each do |middleware|
    connection.response(*middleware)
  end
end

#request(*middleware) ⇒ Object

Adds request middleware to the stack



223
224
225
# File 'lib/minato_ruby_api_client/configuration.rb', line 223

def request(*middleware)
  @request_middlewares << middleware
end

#response(*middleware) ⇒ Object

Adds response middleware to the stack



228
229
230
# File 'lib/minato_ruby_api_client/configuration.rb', line 228

def response(*middleware)
  @response_middlewares << middleware
end

#use(*middleware) ⇒ Object

Adds middleware to the stack



218
219
220
# File 'lib/minato_ruby_api_client/configuration.rb', line 218

def use(*middleware)
  @middlewares << middleware
end