Class: CoreLibrary::HeaderAuth

Inherits:
Authentication
  • Object
show all
Defined in:
lib/apimatic-core/authentication/header_auth.rb

Overview

This class is responsible for adding authentication in request header parameter.

Instance Method Summary collapse

Constructor Details

#initialize(auth_params) ⇒ HeaderAuth

Initializes a new instance of HeaderAuth.

Parameters:

  • auth_params (Hash)

    Auth params for header auth.



6
7
8
9
# File 'lib/apimatic-core/authentication/header_auth.rb', line 6

def initialize(auth_params)
  @auth_params = auth_params
  @error_message = nil
end

Instance Method Details

#apply(_http_request) ⇒ Object

Applies the authentication scheme on the given HTTP request.

Parameters:

  • _http_request (HttpRequest)

    The HTTP request to apply the authentication on.



19
20
21
# File 'lib/apimatic-core/authentication/header_auth.rb', line 19

def apply(_http_request)
  AuthHelper.apply(@auth_params, _http_request.method(:add_header))
end

#validBoolean

Checks whether this authentication scheme is valid or not.

Returns:

  • (Boolean)

    True if the auth instance is valid to be applied on the request.



13
14
15
# File 'lib/apimatic-core/authentication/header_auth.rb', line 13

def valid
  AuthHelper.valid_auth?(@auth_params)
end