Class: WordsRubySdk::Configuration
- Inherits:
-
Object
- Object
- WordsRubySdk::Configuration
- Defined in:
- lib/words_ruby_sdk/configuration.rb
Overview
Class for storing API configuration info
Constant Summary collapse
- V1_API_VERSION =
Defines v1 api version
'/v1'.freeze
- V2_API_VERSION =
Defines v2 api version
'/v2'.freeze
- V3_API_VERSION =
Defines v3 api version
'/v3'.freeze
- V1_1_API_VERSION =
Defines v1.1 api version
'/v1.1'.freeze
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.
-
#api_version ⇒ Object
Defines url api version.
-
#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.
-
#password ⇒ String
Defines the password used with HTTP basic authentication.
-
#refresh_token ⇒ Object
Defines the refresh token (Bearer) used with OAuth2.
-
#scheme ⇒ Object
Defines url scheme.
-
#temp_folder_path ⇒ String
Defines the temporary folder to store downloaded files (for API endpoints that have file response).
-
#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) ⇒ 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
yield self.
-
#initialize {|_self| ... } ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize {|_self| ... } ⇒ Configuration
Returns a new instance of Configuration.
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/words_ruby_sdk/configuration.rb', line 113 def initialize @scheme = 'https' @host = "api.aspose.cloud" @api_version = V1_API_VERSION @api_key = {} @api_key_prefix = {} @client_side_validation = true @debugging = false @logger = 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.
82 83 84 |
# File 'lib/words_ruby_sdk/configuration.rb', line 82 def access_token @access_token end |
#api_key ⇒ Hash
Defines API keys used with API Key authentications.
61 62 63 |
# File 'lib/words_ruby_sdk/configuration.rb', line 61 def api_key @api_key end |
#api_key_prefix ⇒ Hash
Defines API key prefixes used with API Key authentications.
69 70 71 |
# File 'lib/words_ruby_sdk/configuration.rb', line 69 def api_key_prefix @api_key_prefix end |
#api_version ⇒ Object
Defines url api version
53 54 55 |
# File 'lib/words_ruby_sdk/configuration.rb', line 53 def api_version @api_version end |
#client_side_validation ⇒ true, false
Set this to false to skip client side validation in the operation. Default to true.
110 111 112 |
# File 'lib/words_ruby_sdk/configuration.rb', line 110 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.
92 93 94 |
# File 'lib/words_ruby_sdk/configuration.rb', line 92 def debugging @debugging end |
#host ⇒ Object
Defines url host
50 51 52 |
# File 'lib/words_ruby_sdk/configuration.rb', line 50 def host @host end |
#logger ⇒ #debug
Defines the logger used for debugging. Default to ‘Rails.logger` (when in Rails) or logging to STDOUT.
98 99 100 |
# File 'lib/words_ruby_sdk/configuration.rb', line 98 def logger @logger end |
#password ⇒ String
Defines the password used with HTTP basic authentication.
79 80 81 |
# File 'lib/words_ruby_sdk/configuration.rb', line 79 def password @password end |
#refresh_token ⇒ Object
Defines the refresh token (Bearer) used with OAuth2.
85 86 87 |
# File 'lib/words_ruby_sdk/configuration.rb', line 85 def refresh_token @refresh_token end |
#scheme ⇒ Object
Defines url scheme
47 48 49 |
# File 'lib/words_ruby_sdk/configuration.rb', line 47 def scheme @scheme end |
#temp_folder_path ⇒ String
Defines the temporary folder to store downloaded files (for API endpoints that have file response). Default to use ‘Tempfile`.
105 106 107 |
# File 'lib/words_ruby_sdk/configuration.rb', line 105 def temp_folder_path @temp_folder_path end |
#username ⇒ String
Defines the username used with HTTP basic authentication.
74 75 76 |
# File 'lib/words_ruby_sdk/configuration.rb', line 74 def username @username end |
Class Method Details
.default ⇒ Object
The default Configuration object.
127 128 129 |
# File 'lib/words_ruby_sdk/configuration.rb', line 127 def self.default @@default ||= Configuration.new end |
Instance Method Details
#api_key_with_prefix(param_name) ⇒ Object
Gets API key (with prefix if set).
163 164 165 166 167 168 169 |
# File 'lib/words_ruby_sdk/configuration.rb', line 163 def api_key_with_prefix(param_name) if @api_key_prefix[param_name] "#{@api_key_prefix[param_name]} #{@api_key[param_name]}" else @api_key[param_name] end end |
#auth_settings ⇒ Object
Returns Auth Settings hash for api client.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/words_ruby_sdk/configuration.rb', line 177 def auth_settings { 'appsid' => { type: 'api_key', in: 'query', key: 'Appsid', value: api_key_with_prefix('Appsid') }, 'oauth' => { type: 'oauth2', in: 'header', key: 'Authorization', value: "Bearer #{access_token}" }, 'signature' => { type: 'api_key', in: 'query', key: 'Signature', value: api_key_with_prefix('Signature') }, } end |
#base_url ⇒ Object
returns base url
156 157 158 159 |
# File 'lib/words_ruby_sdk/configuration.rb', line 156 def base_url url = "#{scheme}://#{[host, api_version].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') URI.encode(url) end |
#basic_auth_token ⇒ Object
Gets Basic Auth token string
172 173 174 |
# File 'lib/words_ruby_sdk/configuration.rb', line 172 def basic_auth_token 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n") end |
#configure {|_self| ... } ⇒ Object
yield self
132 133 134 |
# File 'lib/words_ruby_sdk/configuration.rb', line 132 def configure yield(self) if block_given? end |