Class: MinatoRubyApiClient::Configuration
- Inherits:
-
Object
- Object
- MinatoRubyApiClient::Configuration
- Defined in:
- lib/minato_ruby_api_client/configuration.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Defines the access token (Bearer) used with OAuth2.
-
#api_key ⇒ Hash
Defines API keys used with API Key authentications.
-
#api_key_prefix ⇒ Hash
Defines API key prefixes used with API Key authentications.
-
#base_path ⇒ Object
Defines url base path.
-
#client_side_validation ⇒ true, false
Set this to false to skip client side validation in the operation.
-
#debugging ⇒ true, false
Set this to enable/disable debugging.
-
#host ⇒ Object
Defines url host.
-
#logger ⇒ #debug
Defines the logger used for debugging.
-
#params_encoding ⇒ Object
Set this to customize parameters encoding of array parameter with multi collectionFormat.
-
#password ⇒ String
Defines the password used with HTTP basic authentication.
-
#scheme ⇒ Object
Defines url scheme.
-
#ssl_ca_file ⇒ String
TLS/SSL setting Set this to customize the certificate file to verify the peer.
-
#ssl_client_cert ⇒ Object
TLS/SSL setting Client certificate file (for client certificate).
-
#ssl_client_key ⇒ Object
TLS/SSL setting Client private key file (for client certificate).
-
#ssl_verify ⇒ true, false
TLS/SSL setting Set this to false to skip verifying SSL certificate when calling API from https server.
-
#ssl_verify_mode ⇒ Object
TLS/SSL setting Any ‘OpenSSL::SSL::` constant (see ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html).
-
#temp_folder_path ⇒ String
Defines the temporary folder to store downloaded files (for API endpoints that have file response).
-
#timeout ⇒ Object
The time limit for HTTP request in seconds.
-
#user_agent ⇒ Object
Defines user agent.
-
#username ⇒ String
Defines the username used with HTTP basic authentication.
Class Method Summary collapse
-
.default ⇒ Object
The default Configuration object.
Instance Method Summary collapse
-
#api_key_with_prefix(param_name, param_alias = nil) ⇒ Object
Gets API key (with prefix if set).
-
#auth_settings ⇒ Object
Returns Auth Settings hash for api client.
-
#base_url ⇒ Object
Returns base URL.
-
#basic_auth_token ⇒ Object
Gets Basic Auth token string.
- #configure {|_self| ... } ⇒ Object
-
#configure_middleware(connection) ⇒ Object
Set up middleware on the connection.
-
#initialize {|_self| ... } ⇒ Configuration
constructor
A new instance of Configuration.
-
#request(*middleware) ⇒ Object
Adds request middleware to the stack.
-
#response(*middleware) ⇒ Object
Adds response middleware to the stack.
-
#use(*middleware) ⇒ Object
Adds middleware to the stack.
Constructor Details
#initialize {|_self| ... } ⇒ Configuration
Returns a new instance of Configuration.
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_token ⇒ Object
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_key ⇒ Hash
Defines API keys used with API Key authentications.
21 22 23 |
# File 'lib/minato_ruby_api_client/configuration.rb', line 21 def api_key @api_key end |
#api_key_prefix ⇒ Hash
Defines API key prefixes used with API Key authentications.
29 30 31 |
# File 'lib/minato_ruby_api_client/configuration.rb', line 29 def api_key_prefix @api_key_prefix end |
#base_path ⇒ Object
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_validation ⇒ true, false
Set this to false to skip client side validation in the operation. Default to true.
71 72 73 |
# File 'lib/minato_ruby_api_client/configuration.rb', line 71 def client_side_validation @client_side_validation end |
#debugging ⇒ true, 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.
49 50 51 |
# File 'lib/minato_ruby_api_client/configuration.rb', line 49 def debugging @debugging end |
#host ⇒ Object
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.
55 56 57 |
# File 'lib/minato_ruby_api_client/configuration.rb', line 55 def logger @logger end |
#params_encoding ⇒ Object
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
108 109 110 |
# File 'lib/minato_ruby_api_client/configuration.rb', line 108 def params_encoding @params_encoding end |
#password ⇒ String
Defines the password used with HTTP basic authentication.
39 40 41 |
# File 'lib/minato_ruby_api_client/configuration.rb', line 39 def password @password end |
#scheme ⇒ Object
Defines url scheme
4 5 6 |
# File 'lib/minato_ruby_api_client/configuration.rb', line 4 def scheme @scheme end |
#ssl_ca_file ⇒ String
TLS/SSL setting Set this to customize the certificate file to verify the peer.
93 94 95 |
# File 'lib/minato_ruby_api_client/configuration.rb', line 93 def ssl_ca_file @ssl_ca_file end |
#ssl_client_cert ⇒ Object
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_key ⇒ Object
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_verify ⇒ true, false
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.
80 81 82 |
# File 'lib/minato_ruby_api_client/configuration.rb', line 80 def ssl_verify @ssl_verify end |
#ssl_verify_mode ⇒ Object
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_path ⇒ String
Defines the temporary folder to store downloaded files (for API endpoints that have file response). Default to use ‘Tempfile`.
62 63 64 |
# File 'lib/minato_ruby_api_client/configuration.rb', line 62 def temp_folder_path @temp_folder_path end |
#timeout ⇒ Object
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_agent ⇒ Object
Defines user agent
13 14 15 |
# File 'lib/minato_ruby_api_client/configuration.rb', line 13 def user_agent @user_agent end |
#username ⇒ String
Defines the username used with HTTP basic authentication.
34 35 36 |
# File 'lib/minato_ruby_api_client/configuration.rb', line 34 def username @username end |
Class Method Details
.default ⇒ Object
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).
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_settings ⇒ Object
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_url ⇒ Object
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_token ⇒ Object
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
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 |