Class: ACube::Endpoint::Auth
Instance Attribute Summary
Attributes inherited from CommonBase
#connection
Instance Method Summary
collapse
Methods inherited from CommonBase
#initialize
Instance Method Details
#login ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/acube/endpoint/auth.rb', line 4
def login
response = connection.post do |req|
req.url "/login"
req.body = {
email: ACube.username,
password: ACube.password
}.to_json
end
if response.success?
token = JSON.parse(response.body)["token"]
Rails.cache.write(ACube.auth_token_cache_key, token, expires_in: 20.hours)
return token
else
raise "Login failed: #{response.body} -- #{response.inspect}"
end
end
|
#logout ⇒ Object
22
23
24
|
# File 'lib/acube/endpoint/auth.rb', line 22
def logout
Rails.cache.delete(ACube.auth_token_cache_key)
end
|
#token! ⇒ Object
26
27
28
29
30
|
# File 'lib/acube/endpoint/auth.rb', line 26
def token!
Rails.cache.fetch(ACube.auth_token_cache_key) do
login
end
end
|