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
#renew ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/haveapi/client/authentication/token.rb', line 43
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
|
32
33
34
35
36
37
|
# File 'lib/haveapi/client/authentication/token.rb', line 32
def
return {} unless @configured
check_validity
@via == :header ? { @desc[:http_header] => @token } : {}
end
|
#request_query_params ⇒ Object
25
26
27
28
29
30
|
# File 'lib/haveapi/client/authentication/token.rb', line 25
def request_query_params
return {} unless @configured
check_validity
@via == :query_param ? { @desc[:query_parameter] => @token } : {}
end
|
#save ⇒ Object
39
40
41
|
# File 'lib/haveapi/client/authentication/token.rb', line 39
def save
{ token: @token, valid_to: @valid_to && @valid_to.to_i }
end
|
#setup ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/haveapi/client/authentication/token.rb', line 8
def setup
@via = @opts[:via] || :header
@token = @opts[:token]
@valid_to =
case @opts[:valid_to]
when Time @opts[:valid_to]
when Integer Time.at(@opts[:valid_to])
end
request_token unless @token
@configured = true
end
|