Class: HaveAPI::CLI::Authentication::Base

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

Overview

Base class for CLI interface of authentication providers

Direct Known Subclasses

Basic, Token

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(communicator, desc, opts = {}) ⇒ Base

Returns a new instance of Base.



15
16
17
18
19
20
21
22
23
# File 'lib/haveapi/cli/authentication/base.rb', line 15

def initialize(communicator, desc, opts = {})
  @communicator = communicator
  @desc = desc
  opts ||= {}

  opts.each do |k, v|
    instance_variable_set("@#{k}", v)
  end
end

Class Method Details

.register(name) ⇒ Object

Register this class as authentication provider with name. The name must be the same as is used in client auth provider and on server side. All providers have to register.



10
11
12
# File 'lib/haveapi/cli/authentication/base.rb', line 10

def register(name)
  HaveAPI::CLI::Cli.register_auth_method(name, Kernel.const_get(to_s))
end

Instance Method Details

#authenticateObject

This method should call HaveAPI::Client::Communicator#authenticate with arguments specific for this authentication provider.



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

def authenticate

end

#options(opts) ⇒ Object

Implement this method to add CLI options for auth provider. opts is an instance of OptionParser. This method is NOT called if the auth provider has been loaded from the config and wasn’t specified as a command line option and therefore all necessary information must be stored in the config.



30
31
32
# File 'lib/haveapi/cli/authentication/base.rb', line 30

def options(opts)

end

#saveObject



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

def save
  @communicator.auth_save
end

#validateObject

Implement this method to check if all needed information for successful authentication are provided. Ask the user on stdin if something is missing.



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

def validate

end