Class: TrainPlugins::Rest::AuthHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/train-rest/auth_handler.rb

Overview

Class to derive authentication handlers from.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection = nil) ⇒ AuthHandler

Returns a new instance of AuthHandler.



8
9
10
# File 'lib/train-rest/auth_handler.rb', line 8

def initialize(connection = nil)
  @connection = connection
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



5
6
7
# File 'lib/train-rest/auth_handler.rb', line 5

def connection
  @connection
end

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/train-rest/auth_handler.rb', line 6

def options
  @options
end

Class Method Details

.descendantsArray

List authentication handlers

Returns:

  • (Array)

    Classes derived from ‘AuthHandler`



24
25
26
# File 'lib/train-rest/auth_handler.rb', line 24

def self.descendants
  ObjectSpace.each_object(Class).select { |klass| klass < self }
end

.nameString

Return name of handler

Returns:

  • (String)


15
16
17
18
19
# File 'lib/train-rest/auth_handler.rb', line 15

def self.name
  class_name = self.to_s.split("::").last

  convert_to_snake_case(class_name)
end

Instance Method Details

#auth_headersHash

Headers added to the rest-client call

Returns:

  • (Hash)


58
59
60
# File 'lib/train-rest/auth_handler.rb', line 58

def auth_headers
  {}
end

#auth_parametersHash

These will get added to the rest-client call.



66
67
68
# File 'lib/train-rest/auth_handler.rb', line 66

def auth_parameters
  { headers: auth_headers }
end

#check_optionsObject

Verify transport options

Raises:

  • (ArgumentError)

    if options are not as needed



39
# File 'lib/train-rest/auth_handler.rb', line 39

def check_options; end

#loginObject

Handle login



42
# File 'lib/train-rest/auth_handler.rb', line 42

def ; end

#logoutObject

Handle logout



53
# File 'lib/train-rest/auth_handler.rb', line 53

def logout; end

#process(payload: "", headers: {}, url: "", method: nil) ⇒ Object

Return headers based on payload signing.

Parameters:

  • data (Hash)

    different types of data for processing



85
86
87
# File 'lib/train-rest/auth_handler.rb', line 85

def process(payload: "", headers: {}, url: "", method: nil)
  {}
end

#process_error(_error) ⇒ Object

Allow processing errors related to authentication.

Parameters:

  • error (RestClient::Exception)

    raw error data



92
# File 'lib/train-rest/auth_handler.rb', line 92

def process_error(_error); end

#renew_sessionObject

Handle session renewal



45
# File 'lib/train-rest/auth_handler.rb', line 45

def renew_session; end

#renewal_needed?Boolean

Return if session renewal needs to happen soon

Returns:

  • (Boolean)


50
# File 'lib/train-rest/auth_handler.rb', line 50

def renewal_needed?; end

#signature_based?Boolean

This Auth Handler will need payload, URI and headers, e.g. for signatures.

Returns:

  • (Boolean)


73
74
75
# File 'lib/train-rest/auth_handler.rb', line 73

def signature_based?
  false
end