Class: AvalaraSdk::Configuration
- Inherits:
-
Object
- Object
- AvalaraSdk::Configuration
- Defined in:
- lib/avalara_sdk/configuration.rb
Constant Summary collapse
- PRODUCTION_OPENID_CONFIG_URL =
'https://identity.avalara.com/.well-known/openid-configuration'
- SANDBOX_OPENID_CONFIG_URL =
'https://ai-sbx.avlr.sh/.well-known/openid-configuration'
- QA_OPENID_CONFIG_URL =
'https://ai-awsfqa.avlr.sh/.well-known/openid-configuration'
- FALLBACK_TOKEN_URL =
'https://identity.avalara.com/connect/token'
- FALLBACK_DEVICE_AUTHORIZATION_URL =
'https://identity.avalara.com/connect/token'
Instance Attribute Summary collapse
-
#api_key ⇒ Hash
Defines API keys used with API Key authentications.
-
#api_key_prefix ⇒ Hash
Defines API key prefixes used with API Key authentications.
-
#app_name ⇒ String
Defines the application name.
-
#app_version ⇒ String
Defines the application version.
-
#base_path ⇒ Object
Defines url base path.
-
#bearer_token ⇒ Object
The OAuth2 Avalara Identity Bearer Token that will be used for API access.
-
#client_id ⇒ Object
Defines the ClientId used for the OAuth2 Client Credentials flow.
-
#client_secret ⇒ Object
The ClientSecret used for the OAuth2 Client Credentials flow.
-
#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.
-
#device_authorization_url ⇒ Object
Defines Device Authorization URL for OAuth 2.0 flows.
-
#environment ⇒ Object
Defines environment.
-
#force_ending_format ⇒ Object
Returns the value of attribute force_ending_format.
-
#inject_format ⇒ Object
Returns the value of attribute inject_format.
-
#logger ⇒ #debug
Defines the logger used for debugging.
-
#machine_name ⇒ String
Defines the machine name.
-
#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.
-
#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).
-
#test_base_path ⇒ Object
Defines Test base Path.
-
#test_device_authorization_url ⇒ Object
Defines override device Authorization URL for OAuth 2.0 flows when using the test environment.
-
#test_token_url ⇒ Object
Defines override token URL for OAuth 2.0 flows when using the test environment.
-
#timeout ⇒ Object
The time limit for HTTP request in seconds.
-
#token_url ⇒ Object
Defines Token URL for OAuth 2.0 flows.
-
#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 for specified operation based on server settings.
-
#basic_auth_token ⇒ Object
Gets Basic Auth token string.
- #configure {|_self| ... } ⇒ Object
-
#configure_middleware(connection) ⇒ Object
Set up middleware on the connection.
- #get_token_url(openid_connect_url) ⇒ Object
-
#initialize {|_self| ... } ⇒ Configuration
constructor
A new instance of Configuration.
- #openid_connect_url ⇒ Object
- #populate_token_url ⇒ Object
-
#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.
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/avalara_sdk/configuration.rb', line 159 def initialize @base_path = '' @environment='' @app_name='' @app_version='' @machine_name='' @client_id='' @client_secret='' @bearer_token='' @token_url='' @device_authorization_url='' @test_base_path='' @test_token_url='' @test_device_authorization_url='' @username='' @password='' @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 @inject_format = false @force_ending_format = false @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT) yield(self) if block_given? end |
Instance Attribute Details
#api_key ⇒ Hash
Defines API keys used with API Key authentications.
33 34 35 |
# File 'lib/avalara_sdk/configuration.rb', line 33 def api_key @api_key end |
#api_key_prefix ⇒ Hash
Defines API key prefixes used with API Key authentications.
41 42 43 |
# File 'lib/avalara_sdk/configuration.rb', line 41 def api_key_prefix @api_key_prefix end |
#app_name ⇒ String
Defines the application name
147 148 149 |
# File 'lib/avalara_sdk/configuration.rb', line 147 def app_name @app_name end |
#app_version ⇒ String
Defines the application version
152 153 154 |
# File 'lib/avalara_sdk/configuration.rb', line 152 def app_version @app_version end |
#base_path ⇒ Object
Defines url base path
25 26 27 |
# File 'lib/avalara_sdk/configuration.rb', line 25 def base_path @base_path end |
#bearer_token ⇒ Object
The OAuth2 Avalara Identity Bearer Token that will be used for API access.
72 73 74 |
# File 'lib/avalara_sdk/configuration.rb', line 72 def bearer_token @bearer_token end |
#client_id ⇒ Object
Defines the ClientId used for the OAuth2 Client Credentials flow.
66 67 68 |
# File 'lib/avalara_sdk/configuration.rb', line 66 def client_id @client_id end |
#client_secret ⇒ Object
The ClientSecret used for the OAuth2 Client Credentials flow.
69 70 71 |
# File 'lib/avalara_sdk/configuration.rb', line 69 def client_secret @client_secret end |
#client_side_validation ⇒ true, false
Set this to false to skip client side validation in the operation. Default to true.
101 102 103 |
# File 'lib/avalara_sdk/configuration.rb', line 101 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.
79 80 81 |
# File 'lib/avalara_sdk/configuration.rb', line 79 def debugging @debugging end |
#device_authorization_url ⇒ Object
Defines Device Authorization URL for OAuth 2.0 flows.
57 58 59 |
# File 'lib/avalara_sdk/configuration.rb', line 57 def @device_authorization_url end |
#environment ⇒ Object
Defines environment
19 20 21 |
# File 'lib/avalara_sdk/configuration.rb', line 19 def environment @environment end |
#force_ending_format ⇒ Object
Returns the value of attribute force_ending_format.
142 143 144 |
# File 'lib/avalara_sdk/configuration.rb', line 142 def force_ending_format @force_ending_format end |
#inject_format ⇒ Object
Returns the value of attribute inject_format.
140 141 142 |
# File 'lib/avalara_sdk/configuration.rb', line 140 def inject_format @inject_format end |
#logger ⇒ #debug
Defines the logger used for debugging. Default to ‘Rails.logger` (when in Rails) or logging to STDOUT.
85 86 87 |
# File 'lib/avalara_sdk/configuration.rb', line 85 def logger @logger end |
#machine_name ⇒ String
Defines the machine name
157 158 159 |
# File 'lib/avalara_sdk/configuration.rb', line 157 def machine_name @machine_name 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
138 139 140 |
# File 'lib/avalara_sdk/configuration.rb', line 138 def params_encoding @params_encoding end |
#password ⇒ String
Defines the password used with HTTP basic authentication.
51 52 53 |
# File 'lib/avalara_sdk/configuration.rb', line 51 def password @password end |
#ssl_ca_file ⇒ String
TLS/SSL setting Set this to customize the certificate file to verify the peer.
123 124 125 |
# File 'lib/avalara_sdk/configuration.rb', line 123 def ssl_ca_file @ssl_ca_file end |
#ssl_client_cert ⇒ Object
TLS/SSL setting Client certificate file (for client certificate)
127 128 129 |
# File 'lib/avalara_sdk/configuration.rb', line 127 def ssl_client_cert @ssl_client_cert end |
#ssl_client_key ⇒ Object
TLS/SSL setting Client private key file (for client certificate)
131 132 133 |
# File 'lib/avalara_sdk/configuration.rb', line 131 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.
110 111 112 |
# File 'lib/avalara_sdk/configuration.rb', line 110 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)
117 118 119 |
# File 'lib/avalara_sdk/configuration.rb', line 117 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`.
92 93 94 |
# File 'lib/avalara_sdk/configuration.rb', line 92 def temp_folder_path @temp_folder_path end |
#test_base_path ⇒ Object
Defines Test base Path
22 23 24 |
# File 'lib/avalara_sdk/configuration.rb', line 22 def test_base_path @test_base_path end |
#test_device_authorization_url ⇒ Object
Defines override device Authorization URL for OAuth 2.0 flows when using the test environment.
63 64 65 |
# File 'lib/avalara_sdk/configuration.rb', line 63 def @test_device_authorization_url end |
#test_token_url ⇒ Object
Defines override token URL for OAuth 2.0 flows when using the test environment.
60 61 62 |
# File 'lib/avalara_sdk/configuration.rb', line 60 def test_token_url @test_token_url end |
#timeout ⇒ Object
The time limit for HTTP request in seconds. Default to 0 (never times out).
96 97 98 |
# File 'lib/avalara_sdk/configuration.rb', line 96 def timeout @timeout end |
#token_url ⇒ Object
Defines Token URL for OAuth 2.0 flows.
54 55 56 |
# File 'lib/avalara_sdk/configuration.rb', line 54 def token_url @token_url end |
#username ⇒ String
Defines the username used with HTTP basic authentication.
46 47 48 |
# File 'lib/avalara_sdk/configuration.rb', line 46 def username @username end |
Class Method Details
.default ⇒ Object
The default Configuration object.
196 197 198 |
# File 'lib/avalara_sdk/configuration.rb', line 196 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).
230 231 232 233 234 235 236 237 238 |
# File 'lib/avalara_sdk/configuration.rb', line 230 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.
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/avalara_sdk/configuration.rb', line 246 def auth_settings { 'BasicAuth' => { type: 'basic', in: 'header', key: 'Authorization', value: basic_auth_token }, 'Bearer' => { type: 'api_key', in: 'header', key: 'Authorization', value: api_key_with_prefix('Bearer') }, } end |
#base_url ⇒ Object
Returns base URL for specified operation based on server settings
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/avalara_sdk/configuration.rb', line 210 def base_url case environment.downcase when 'sandbox' return 'https://api.sbx.avalara.com' when 'production' return 'https://api.avalara.com' when 'qa' return 'https://superapi.qa.avalara.io' when 'test' if test_base_path.empty? fail ArgumentError, "Test_Base_Path must be configured to run in test environment mode." end return test_base_path else fail ArgumentError, "Invalid environment value" end end |
#basic_auth_token ⇒ Object
Gets Basic Auth token string
241 242 243 |
# File 'lib/avalara_sdk/configuration.rb', line 241 def basic_auth_token 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n") end |
#configure {|_self| ... } ⇒ Object
200 201 202 |
# File 'lib/avalara_sdk/configuration.rb', line 200 def configure yield(self) if block_given? end |
#configure_middleware(connection) ⇒ Object
Set up middleware on the connection
281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/avalara_sdk/configuration.rb', line 281 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 |
#get_token_url(openid_connect_url) ⇒ Object
323 324 325 326 327 328 |
# File 'lib/avalara_sdk/configuration.rb', line 323 def get_token_url(openid_connect_url) response = Faraday.get(openid_connect_url) do |req| req.headers['Accept'] = 'application/json' end JSON.parse(response.body) end |
#openid_connect_url ⇒ Object
312 313 314 315 316 317 318 319 320 321 |
# File 'lib/avalara_sdk/configuration.rb', line 312 def openid_connect_url case @environment.downcase when 'sandbox' SANDBOX_OPENID_CONFIG_URL when 'production' PRODUCTION_OPENID_CONFIG_URL when 'qa' QA_OPENID_CONFIG_URL end end |
#populate_token_url ⇒ Object
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/avalara_sdk/configuration.rb', line 295 def populate_token_url if @environment.downcase == 'test' @token_url = @test_token_url @device_authorization_url = @test_device_authorization_url elsif @token_url.nil? || @token_url.length == 0 begin token_response = get_token_url openid_connect_url @token_url = token_response['token_endpoint'] @device_authorization_url = token_response['device_authorization_endpoint'] rescue Exception => e puts "Exception when calling OpenIdConnect to fetch the token endpoint. Error: #{e.}" @token_url = FALLBACK_TOKEN_URL @device_authorization_url = FALLBACK_DEVICE_AUTHORIZATION_URL end end end |
#request(*middleware) ⇒ Object
Adds request middleware to the stack
271 272 273 |
# File 'lib/avalara_sdk/configuration.rb', line 271 def request(*middleware) @request_middlewares << middleware end |
#response(*middleware) ⇒ Object
Adds response middleware to the stack
276 277 278 |
# File 'lib/avalara_sdk/configuration.rb', line 276 def response(*middleware) @response_middlewares << middleware end |
#use(*middleware) ⇒ Object
Adds middleware to the stack
266 267 268 |
# File 'lib/avalara_sdk/configuration.rb', line 266 def use(*middleware) @middlewares << middleware end |