Class: HaveAPI::Client::Authentication::Base
- Inherits:
-
Object
- Object
- HaveAPI::Client::Authentication::Base
- Defined in:
- lib/haveapi/client/authentication/base.rb
Overview
Base class for all authentication providers.
Authentication providers may reimplement only methods they need. You do not have to reimplement all methods.
Class Method Summary collapse
-
.register(name) ⇒ Object
Register this class as authentication provider with
name.
Instance Method Summary collapse
-
#initialize(communicator, description, opts, &block) ⇒ Base
constructor
A new instance of Base.
- #inspect ⇒ Object
-
#load(hash) ⇒ Object
Load auth provider attributes from previous #save call.
-
#request_headers ⇒ Object
Called for each request.
-
#request_payload ⇒ Object
Called for each request.
-
#request_query_params ⇒ Object
Called for each request.
-
#resource ⇒ Object
Return RestClient::Resource instance.
-
#save ⇒ Object
Returns a hash of auth provider attributes to be saved e.g.
-
#setup ⇒ Object
Called right after initialize.
Constructor Details
#initialize(communicator, description, opts, &block) ⇒ Base
Returns a new instance of Base.
33 34 35 36 37 38 39 40 |
# File 'lib/haveapi/client/authentication/base.rb', line 33 def initialize(communicator, description, opts, &block) @communicator = communicator @desc = description @opts = opts @block = block setup 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 CLI auth provider (if any) and on server side. All providers have to register.
28 29 30 |
# File 'lib/haveapi/client/authentication/base.rb', line 28 def register(name) HaveAPI::Client::Communicator.register_auth_method(name, Kernel.const_get(to_s)) end |
Instance Method Details
#inspect ⇒ Object
42 43 44 |
# File 'lib/haveapi/client/authentication/base.rb', line 42 def inspect "#<#{self.class.name} @opts=#{@opts.inspect}>" end |
#load(hash) ⇒ Object
Load auth provider attributes from previous #save call.
78 79 80 |
# File 'lib/haveapi/client/authentication/base.rb', line 78 def load(hash) @opts = hash end |
#request_headers ⇒ Object
Called for each request. Returns a hash of HTTP headers.
64 65 66 |
# File 'lib/haveapi/client/authentication/base.rb', line 64 def request_headers {} end |
#request_payload ⇒ Object
Called for each request. Returns a hash of parameters send in request body.
59 60 61 |
# File 'lib/haveapi/client/authentication/base.rb', line 59 def request_payload {} end |
#request_query_params ⇒ Object
Called for each request. Returns a hash of query parameters.
53 54 55 |
# File 'lib/haveapi/client/authentication/base.rb', line 53 def request_query_params {} end |
#resource ⇒ Object
Return RestClient::Resource instance. This is mainly for HTTP basic auth.
50 |
# File 'lib/haveapi/client/authentication/base.rb', line 50 def resource; end |
#save ⇒ Object
Returns a hash of auth provider attributes to be saved e.g. in a file to be used later, without the user providing credentials again. You may wish to save a username or password (not recommended), tokens or whatever authentication provider needs to authenticate user without his input.
73 74 75 |
# File 'lib/haveapi/client/authentication/base.rb', line 73 def save @opts end |
#setup ⇒ Object
Called right after initialize. Use this method to initialize provider.
47 |
# File 'lib/haveapi/client/authentication/base.rb', line 47 def setup; end |