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
Initializes 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
Initializes a new instance of Single.
12 13 14 15 16 17 |
# File 'lib/apimatic-core/authentication/multiple/single_auth.rb', line 12 def initialize(auth_participant) @auth_participant = auth_participant @mapped_auth = nil @error_message = nil @is_valid = false end |
Instance Method Details
#apply(http_request) ⇒ Object
Applies the associated auth to the HTTP request.
41 42 43 44 45 |
# File 'lib/apimatic-core/authentication/multiple/single_auth.rb', line 41 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.
31 32 33 34 35 36 37 |
# File 'lib/apimatic-core/authentication/multiple/single_auth.rb', line 31 def valid raise ArgumentError, 'The auth manager entry must not have a nil value.' if @mapped_auth.nil? @is_valid = @mapped_auth.valid @error_message = @mapped_auth. unless @is_valid @is_valid end |
#with_auth_managers(auth_managers) ⇒ Single
Extracts out the auth from the given auth managers.
22 23 24 25 26 27 |
# File 'lib/apimatic-core/authentication/multiple/single_auth.rb', line 22 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 |