Class: HaveAPI::Client::Authentication::Base

Inherits:
Object
  • Object
show all
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.

Direct Known Subclasses

Basic, NoAuth, Token

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(communicator, description, opts) ⇒ Base

Returns a new instance of Base.



30
31
32
33
34
35
36
# File 'lib/haveapi/client/authentication/base.rb', line 30

def initialize(communicator, description, opts)
  @communicator = communicator
  @desc = description
  @opts = opts

  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.



25
26
27
# File 'lib/haveapi/client/authentication/base.rb', line 25

def register(name)
  HaveAPI::Client::Communicator.register_auth_method(name, Kernel.const_get(to_s))
end

Instance Method Details

#load(hash) ⇒ Object

Load auth provider attributes from previous #save call.



74
75
76
# File 'lib/haveapi/client/authentication/base.rb', line 74

def load(hash)
  @opts = hash
end

#request_headersObject

Called for each request. Returns a hash of HTTP headers.



60
61
62
# File 'lib/haveapi/client/authentication/base.rb', line 60

def request_headers
  {}
end

#request_payloadObject

Called for each request. Returns a hash of parameters send in request body.



55
56
57
# File 'lib/haveapi/client/authentication/base.rb', line 55

def request_payload
  {}
end

#request_url_paramsObject

Called for each request. Returns a hash of query parameters.



49
50
51
# File 'lib/haveapi/client/authentication/base.rb', line 49

def request_url_params
  {}
end

#resourceObject

Return RestClient::Resource instance. This is mainly for HTTP basic auth.



44
45
46
# File 'lib/haveapi/client/authentication/base.rb', line 44

def resource

end

#saveObject

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.



69
70
71
# File 'lib/haveapi/client/authentication/base.rb', line 69

def save
  @opts
end

#setupObject

Called right after initialize. Use this method to initialize provider.



39
40
41
# File 'lib/haveapi/client/authentication/base.rb', line 39

def setup

end