Class: CoreLibrary::AuthGroup

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

Overview

The parent class of multiple authentication groups (i.e. Or & And groups). This parent class is responsible for handling multiple auths on a particular request.

Direct Known Subclasses

And, Or

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth_group) ⇒ AuthGroup

Initializes a new instance of AuthGroup.

Parameters:

  • auth_group (String | AuthGroup)

    AuthGroup instance or string.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/apimatic-core/authentication/multiple/auth_group.rb', line 9

def initialize(auth_group)
  @auth_participants = []
  auth_group.each do |auth_participant|
    if !auth_participant.nil? && auth_participant.is_a?(String)
      @auth_participants.append(Single.new(auth_participant))
    elsif !auth_participant.nil?
      @auth_participants.append(auth_participant)
    end
    @mapped_group = []
    @error_messages = []
    @is_valid_group = nil
  end
end

Instance Attribute Details

#auth_participantsObject

Returns the value of attribute auth_participants.



5
6
7
# File 'lib/apimatic-core/authentication/multiple/auth_group.rb', line 5

def auth_participants
  @auth_participants
end

#error_messagesObject

Returns the value of attribute error_messages.



5
6
7
# File 'lib/apimatic-core/authentication/multiple/auth_group.rb', line 5

def error_messages
  @error_messages
end

#is_valid_groupObject

Returns the value of attribute is_valid_group.



5
6
7
# File 'lib/apimatic-core/authentication/multiple/auth_group.rb', line 5

def is_valid_group
  @is_valid_group
end

#mapped_groupObject

Returns the value of attribute mapped_group.



5
6
7
# File 'lib/apimatic-core/authentication/multiple/auth_group.rb', line 5

def mapped_group
  @mapped_group
end

Instance Method Details

#apply(http_request) ⇒ Object

Applies the associated auth to the HTTP request.

Parameters:

  • http_request (HttpRequest)

    The HTTP request on which the auth is to be applied.



41
42
43
44
45
# File 'lib/apimatic-core/authentication/multiple/auth_group.rb', line 41

def apply(http_request)
  return unless @is_valid_group

  @mapped_group.each { |participant| participant.apply(http_request) }
end

#validBoolean

Checks if the associated auth is valid.

Returns:

  • (Boolean)

    True if the associated auth is valid, false otherwise.

Raises:

  • (NotImplementedError)


35
36
37
# File 'lib/apimatic-core/authentication/multiple/auth_group.rb', line 35

def valid
  raise NotImplementedError, 'This method needs to be implemented in a child class.'
end

#with_auth_managers(auth_managers) ⇒ Single

Extracts out the auth from the given auth managers.

Parameters:

  • auth_managers (Hash)

    The hash of auth managers.

Returns:

  • (Single)

    An updated instance of itself.



26
27
28
29
30
31
# File 'lib/apimatic-core/authentication/multiple/auth_group.rb', line 26

def with_auth_managers(auth_managers)
  @auth_participants.each do |participant|
    @mapped_group.append(participant.with_auth_managers(auth_managers))
  end
  self
end