Class: HaveAPI::CLI::Authentication::Base
- Inherits:
-
Object
- Object
- HaveAPI::CLI::Authentication::Base
- Defined in:
- lib/haveapi/cli/authentication/base.rb
Overview
Base class for CLI interface of authentication providers
Class Method Summary collapse
-
.register(name) ⇒ Object
Register this class as authentication provider with
name
.
Instance Method Summary collapse
-
#authenticate ⇒ Object
This method should call HaveAPI::Client::Communicator#authenticate with arguments specific for this authentication provider.
-
#initialize(communicator, desc, opts = {}) ⇒ Base
constructor
A new instance of Base.
-
#options(opts) ⇒ Object
Implement this method to add CLI options for auth provider.
- #save ⇒ Object
-
#validate ⇒ Object
Implement this method to check if all needed information for successful authentication are provided.
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
#authenticate ⇒ Object
This method should call HaveAPI::Client::Communicator#authenticate with arguments specific for this authentication provider.
39 |
# File 'lib/haveapi/cli/authentication/base.rb', line 39 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 |
# File 'lib/haveapi/cli/authentication/base.rb', line 30 def (opts); end |
#save ⇒ Object
41 42 43 |
# File 'lib/haveapi/cli/authentication/base.rb', line 41 def save @communicator.auth_save end |
#validate ⇒ Object
Implement this method to check if all needed information for successful authentication are provided. Ask the user on stdin if something is missing.
35 |
# File 'lib/haveapi/cli/authentication/base.rb', line 35 def validate; end |