Class: Base::Endpoints::Sessions

Inherits:
Base::Endpoint show all
Defined in:
lib/base/endpoints/sessions.rb

Overview

This endpoint contains a method for authenticating a user.

Instance Attribute Summary

Attributes inherited from Base::Endpoint

#connection, #path

Instance Method Summary collapse

Methods inherited from Base::Endpoint

#io, #parse, #request

Constructor Details

#initialize(access_token:, url:) ⇒ Sessions

Initializes this endpoint.



8
9
10
11
# File 'lib/base/endpoints/sessions.rb', line 8

def initialize(access_token:, url:)
  @path = 'sessions'
  super
end

Instance Method Details

#authenticate(email:, password:) ⇒ Object

Tries to authenticate (log in) the user with email and password.

For security reasons if the email address is not registered or the password is incorrect, “INVALID_CREDENTIALS” error will be returned.



17
18
19
20
21
22
23
24
25
26
# File 'lib/base/endpoints/sessions.rb', line 17

def authenticate(email:, password:)
  request do
    response =
      connection.post('',
                      'password' => password,
                      'email' => email)

    parse(response.body)
  end
end