Class: CoreLibrary::AuthHelper
- Inherits:
-
Object
- Object
- CoreLibrary::AuthHelper
- Defined in:
- lib/apimatic-core/utilities/auth_helper.rb
Overview
A utility class for authentication flow
Class Method Summary collapse
-
.apply(auth_params, func) ⇒ Object
Applies callable to each entry of the hash.
-
.get_base64_encoded_value(*props, delimiter: ':') ⇒ String
Performs the Base64 encodes the provided parameters after joining the parameters with delimiter.
-
.get_token_expiry(expires_in, current_timestamp) ⇒ Time
Calculates the expiry after adding the expires_in value to the current timestamp.
-
.token_expired?(token_expiry) ⇒ Boolean
Checks if OAuth token has expired.
-
.valid_auth?(auth_params) ⇒ Boolean
Checks whether the provided auth parameters does not contain any nil key/value.
Class Method Details
.apply(auth_params, func) ⇒ Object
Applies callable to each entry of the hash.
45 46 47 |
# File 'lib/apimatic-core/utilities/auth_helper.rb', line 45 def self.apply(auth_params, func) auth_params.each { |key, value| func.call(key, value) } end |
.get_base64_encoded_value(*props, delimiter: ':') ⇒ String
Performs the Base64 encodes the provided parameters after joining the parameters with delimiter.
10 11 12 13 14 15 |
# File 'lib/apimatic-core/utilities/auth_helper.rb', line 10 def self.get_base64_encoded_value(*props, delimiter: ':') return if props.any?(&:nil?) joined = props.join(delimiter) Base64.strict_encode64(joined) end |
.get_token_expiry(expires_in, current_timestamp) ⇒ Time
Calculates the expiry after adding the expires_in value to the current timestamp.
30 31 32 |
# File 'lib/apimatic-core/utilities/auth_helper.rb', line 30 def self.get_token_expiry(expires_in, ) + expires_in end |
.token_expired?(token_expiry) ⇒ Boolean
Checks if OAuth token has expired.
20 21 22 23 24 |
# File 'lib/apimatic-core/utilities/auth_helper.rb', line 20 def self.token_expired?(token_expiry) raise ArgumentError, 'Token expiry can not be nil.' if token_expiry.nil? token_expiry < Time.now.utc.to_i end |
.valid_auth?(auth_params) ⇒ Boolean
Checks whether the provided auth parameters does not contain any nil key/value.
37 38 39 40 |
# File 'lib/apimatic-core/utilities/auth_helper.rb', line 37 def self.valid_auth?(auth_params) !auth_params.nil? and !auth_params.empty? and auth_params.all? { |key, value| !(key.nil? or value.nil?) } end |