Class: Luma::Authentication
- Inherits:
-
Connection
- Object
- Connection
- Luma::Authentication
- Defined in:
- lib/luma/authentication.rb
Constant Summary collapse
- BASE_ENDPOINT =
'/api'.freeze
- AUTH_ENDPOINT =
"#{BASE_ENDPOINT}/users/login".freeze
- VALIDATE_ENDPOINT =
"#{BASE_ENDPOINT}/tokens/validate".freeze
Constants inherited from Connection
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#password ⇒ Object
Returns the value of attribute password.
-
#response ⇒ Object
Returns the value of attribute response.
-
#validation_response ⇒ Object
Returns the value of attribute validation_response.
Instance Method Summary collapse
- #access_header ⇒ Object
- #access_token ⇒ Object
- #authenticate ⇒ Object
-
#initialize(email: nil, password: nil) ⇒ Authentication
constructor
A new instance of Authentication.
- #validate ⇒ Object
Methods inherited from Connection
#add_headers_and_body, #request
Constructor Details
#initialize(email: nil, password: nil) ⇒ Authentication
Returns a new instance of Authentication.
9 10 11 12 13 14 |
# File 'lib/luma/authentication.rb', line 9 def initialize(email: nil, password: nil) @email = email @password = password @response = nil @validation_response = nil end |
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
3 4 5 |
# File 'lib/luma/authentication.rb', line 3 def email @email end |
#password ⇒ Object
Returns the value of attribute password.
3 4 5 |
# File 'lib/luma/authentication.rb', line 3 def password @password end |
#response ⇒ Object
Returns the value of attribute response.
3 4 5 |
# File 'lib/luma/authentication.rb', line 3 def response @response end |
#validation_response ⇒ Object
Returns the value of attribute validation_response.
3 4 5 |
# File 'lib/luma/authentication.rb', line 3 def validation_response @validation_response end |
Instance Method Details
#access_header ⇒ Object
54 55 56 57 58 |
# File 'lib/luma/authentication.rb', line 54 def access_header return { 'X-Access-Token' => self.access_token, } end |
#access_token ⇒ Object
50 51 52 |
# File 'lib/luma/authentication.rb', line 50 def access_token return @response['token'] if @response end |
#authenticate ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/luma/authentication.rb', line 16 def authenticate request = { body: { email: email, password: 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 end return self end |
#validate ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/luma/authentication.rb', line 34 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 |