Class: ACube::Endpoint::Auth

Inherits:
CommonBase show all
Defined in:
lib/acube/endpoint/auth.rb

Instance Attribute Summary

Attributes inherited from CommonBase

#connection

Instance Method Summary collapse

Methods inherited from CommonBase

#initialize

Constructor Details

This class inherits a constructor from ACube::Endpoint::CommonBase

Instance Method Details

#loginObject



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 
  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

#logoutObject



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
    
  end
end