Class: CoreLibrary::Single
- Inherits:
-
Authentication
- Object
- Authentication
- CoreLibrary::Single
- Defined in:
- lib/apimatic-core/authentication/multiple/single_auth.rb
Overview
The class to handle the single authentication for a particular request.
Instance Method Summary collapse
-
#apply(http_request) ⇒ Object
Applies the associated auth to the HTTP request.
-
#error_message ⇒ String
Getter for the error message for auth.
-
#initialize(auth_participant) ⇒ Single
constructor
A new instance of Single.
-
#valid ⇒ Boolean
Checks if the associated auth is valid.
-
#with_auth_managers(auth_managers) ⇒ Single
Extracts out the auth from the given auth managers.
Constructor Details
#initialize(auth_participant) ⇒ Single
Returns a new instance of Single.
10 11 12 13 14 15 |
# File 'lib/apimatic-core/authentication/multiple/single_auth.rb', line 10 def initialize(auth_participant) @auth_participant = auth_participant @mapped_auth = nil = nil @is_valid = true end |
Instance Method Details
#apply(http_request) ⇒ Object
Applies the associated auth to the HTTP request.
42 43 44 45 46 |
# File 'lib/apimatic-core/authentication/multiple/single_auth.rb', line 42 def apply(http_request) return unless @is_valid @mapped_auth.apply(http_request) end |
#error_message ⇒ String
Getter for the error message for auth.
6 7 8 |
# File 'lib/apimatic-core/authentication/multiple/single_auth.rb', line 6 def "[#{@error_message}]" end |
#valid ⇒ Boolean
Checks if the associated auth is valid.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/apimatic-core/authentication/multiple/single_auth.rb', line 29 def valid raise ArgumentError, 'The auth manager entry must not have a nil value.' if @mapped_auth.nil? unless @mapped_auth.valid = @mapped_auth. @is_valid = false end @is_valid end |
#with_auth_managers(auth_managers) ⇒ Single
Extracts out the auth from the given auth managers.
20 21 22 23 24 25 |
# File 'lib/apimatic-core/authentication/multiple/single_auth.rb', line 20 def with_auth_managers(auth_managers) raise ArgumentError, 'Auth key is invalid.' unless auth_managers.key?(@auth_participant) @mapped_auth = auth_managers[@auth_participant] self end |