class Luma::Authentication
Constants
- AUTH_ENDPOINT
- BASE_ENDPOINT
- VALIDATE_ENDPOINT
Attributes
response[RW]
validation_response[RW]
Public Class Methods
new()
click to toggle source
# File lib/luma/authentication.rb, line 9 def initialize @response = nil @validation_response = nil end
Public Instance Methods
access_header()
click to toggle source
# File lib/luma/authentication.rb, line 67 def access_header return { 'X-Access-Token' => self.access_token, } end
access_token()
click to toggle source
# File lib/luma/authentication.rb, line 51 def access_token return @response['token'] if @response end
authenticate()
click to toggle source
# File lib/luma/authentication.rb, line 14 def authenticate if (self.expires?) request = { body: { email: Luma.configuration.email, password: Luma.configuration.password }, endpoint: AUTH_ENDPOINT } response = self.request(**request, auth: false) if (false == response.ok?) @response = nil raise LumaException.from_response(response, msg: 'Authentication') else @response = response validate end end return self end
expire!()
click to toggle source
# File lib/luma/authentication.rb, line 73 def expire! @response = nil end
expires?()
click to toggle source
# File lib/luma/authentication.rb, line 59 def expires? if (self.expiry) return self.expiry <= (Time.now.to_f * 1000).floor else return true end end
expiry()
click to toggle source
# File lib/luma/authentication.rb, line 55 def expiry return @validation_response['exp'] if @validation_response end
validate()
click to toggle source
# File lib/luma/authentication.rb, line 35 def validate request = { body: { token: access_token }, endpoint: VALIDATE_ENDPOINT } response = self.request(**request, auth: false) if (false == response.ok?) @response = nil raise LumaException.from_response(response, msg: 'Authentication Validation') else @validation_response = response end end