Class: HaveAPI::Client::Authentication::Token
- Inherits:
-
Base
- Object
- Base
- HaveAPI::Client::Authentication::Token
show all
- Defined in:
- lib/haveapi/client/authentication/token.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #inspect, register, #request_payload, #resource
Instance Attribute Details
#token ⇒ Object
Returns the value of attribute token.
6
7
8
|
# File 'lib/haveapi/client/authentication/token.rb', line 6
def token
@token
end
|
#valid_to ⇒ Object
Returns the value of attribute valid_to.
6
7
8
|
# File 'lib/haveapi/client/authentication/token.rb', line 6
def valid_to
@valid_to
end
|
Instance Method Details
#load(hash) ⇒ Object
36
37
38
39
|
# File 'lib/haveapi/client/authentication/token.rb', line 36
def load(hash)
@token = hash[:token]
@valid_to = hash[:valid_to]
end
|
#renew ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/haveapi/client/authentication/token.rb', line 41
def renew
a = HaveAPI::Client::Action.new(
nil,
@communicator,
:renew,
@desc[:resources][:token][:actions][:renew],
[]
)
ret = HaveAPI::Client::Response.new(a, a.execute({}))
raise HaveAPI::Client::ActionFailed, ret unless ret.ok?
@valid_to = ret[:valid_to]
@valid_to &&= DateTime.iso8601(@valid_to).to_time
end
|
25
26
27
28
29
30
|
# File 'lib/haveapi/client/authentication/token.rb', line 25
def
return {} unless @configured
check_validity
@via == :header ? { @desc[:http_header] => @token } : {}
end
|
#request_query_params ⇒ Object
18
19
20
21
22
23
|
# File 'lib/haveapi/client/authentication/token.rb', line 18
def request_query_params
return {} unless @configured
check_validity
@via == :query_param ? { @desc[:query_parameter] => @token } : {}
end
|
#save ⇒ Object
32
33
34
|
# File 'lib/haveapi/client/authentication/token.rb', line 32
def save
{ token: @token, valid_to: @valid_to }
end
|
#setup ⇒ Object
8
9
10
11
12
13
14
15
16
|
# File 'lib/haveapi/client/authentication/token.rb', line 8
def setup
@via = @opts[:via] || :header
@token = @opts[:token]
@valid_to = @opts[:valid_to]
request_token unless @token
@configured = true
end
|