Class: HaveAPI::Authentication::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/haveapi/authentication/base.rb

Overview

Base class for authentication providers.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, v) ⇒ Base

Returns a new instance of Base.



24
25
26
27
28
29
# File 'lib/haveapi/authentication/base.rb', line 24

def initialize(server, v)
  @name = self.class.auth_method
  @server = server
  @version = v
  setup
end

Instance Attribute Details

#nameSymbol (readonly)

Returns:

  • (Symbol)


22
23
24
# File 'lib/haveapi/authentication/base.rb', line 22

def name
  @name
end

Class Method Details

.auth_method(v = nil) ⇒ Symbol

Get or set auth method name

Parameters:

  • v (Symbol, nil) (defaults to: nil)

Returns:

  • (Symbol)


8
9
10
11
12
13
14
# File 'lib/haveapi/authentication/base.rb', line 8

def self.auth_method(v = nil)
  if v
    @auth_method = v
  else
    @auth_method || name.split('::').last.underscore.to_sym
  end
end

.inherited(subclass) ⇒ Object



16
17
18
19
# File 'lib/haveapi/authentication/base.rb', line 16

def self.inherited(subclass)
  super
  subclass.send(:instance_variable_set, '@auth_method', @auth_method)
end

Instance Method Details

#authenticate(request) ⇒ Object

Reimplement this method in your authentication provider. ‘request` is passed directly from Sinatra.



43
# File 'lib/haveapi/authentication/base.rb', line 43

def authenticate(request); end

#describeObject

Reimplement to describe provider.



46
47
48
# File 'lib/haveapi/authentication/base.rb', line 46

def describe
  {}
end

#register_routes(sinatra, prefix) ⇒ Object

Register custom path handlers in sinatra

Parameters:

  • sinatra (Sinatra::Base)
  • prefix (String)


34
# File 'lib/haveapi/authentication/base.rb', line 34

def register_routes(sinatra, prefix); end

#resource_moduleModule?

Returns:

  • (Module, nil)


37
38
39
# File 'lib/haveapi/authentication/base.rb', line 37

def resource_module
  nil
end