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, 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
34
35
36
37
|
# File 'lib/haveapi/client/authentication/token.rb', line 34
def load(hash)
@token = hash[:token]
@valid_to = hash[:valid_to]
end
|
#renew ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/haveapi/client/authentication/token.rb', line 39
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.new(ret) unless ret.ok?
@valid_to = ret[:valid_to]
@valid_to = @valid_to && DateTime.iso8601(@valid_to).to_time
end
|
24
25
26
27
28
|
# File 'lib/haveapi/client/authentication/token.rb', line 24
def
return {} unless @configured
check_validity
@via == :header ? {@desc[:http_header] => @token} : {}
end
|
#request_query_params ⇒ Object
18
19
20
21
22
|
# 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
30
31
32
|
# File 'lib/haveapi/client/authentication/token.rb', line 30
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
|