Class: HaveAPI::Client::Authentication::Token

Inherits:
Base
  • Object
show all
Defined in:
lib/haveapi/client/authentication/token.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, register, #request_payload, #resource

Constructor Details

This class inherits a constructor from HaveAPI::Client::Authentication::Base

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



4
5
6
# File 'lib/haveapi/client/authentication/token.rb', line 4

def token
  @token
end

#valid_toObject (readonly)

Returns the value of attribute valid_to.



4
5
6
# File 'lib/haveapi/client/authentication/token.rb', line 4

def valid_to
  @valid_to
end

Instance Method Details

#load(hash) ⇒ Object



32
33
34
35
# File 'lib/haveapi/client/authentication/token.rb', line 32

def load(hash)
  @token = hash[:token]
  @valid_to = hash[:valid_to]
end

#request_headersObject



22
23
24
25
26
# File 'lib/haveapi/client/authentication/token.rb', line 22

def request_headers
  return {} unless @configured
  check_validity
  @via == :header ? {@desc[:http_header] => @token} : {}
end

#request_url_paramsObject



16
17
18
19
20
# File 'lib/haveapi/client/authentication/token.rb', line 16

def request_url_params
  return {} unless @configured
  check_validity
  @via == :query_param ? {@desc[:query_parameter] => @token} : {}
end

#saveObject



28
29
30
# File 'lib/haveapi/client/authentication/token.rb', line 28

def save
  {token: @token, valid_to: @valid_to}
end

#setupObject



6
7
8
9
10
11
12
13
14
# File 'lib/haveapi/client/authentication/token.rb', line 6

def setup
  @via = @opts[:via] || :header
  @token = @opts[:token]
  @valid_to = @opts[:valid_to]

  request_token unless @token

  @configured = true
end