Class: VoiceNotes::Resources::Auth

Inherits:
Base
  • Object
show all
Defined in:
lib/voice_notes/resources/auth.rb

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from VoiceNotes::Resources::Base

Instance Method Details

#login(email:, password:) ⇒ Hash

Login with email and password

Parameters:

  • email (String)

    User’s email

  • password (String)

    User’s password

Returns:

  • (Hash)

    Response containing access_token and refresh_token



10
11
12
13
14
15
16
# File 'lib/voice_notes/resources/auth.rb', line 10

def (email:, password:)
  post("/api/v1/auth/login", {
         email: email,
         password: password,
         grant_type: "password"
       })
end

#logoutHash?

Logout and invalidate the current session

Returns:

  • (Hash, nil)

    Response from server



30
31
32
# File 'lib/voice_notes/resources/auth.rb', line 30

def logout
  delete("/api/v1/auth/logout")
end

#meHash

Get current authenticated user

Returns:

  • (Hash)

    User data in JSON:API format



36
37
38
# File 'lib/voice_notes/resources/auth.rb', line 36

def me
  get("/api/v1/me")
end

#refresh(refresh_token:) ⇒ Hash

Refresh access token using refresh token

Parameters:

  • refresh_token (String)

    The refresh token

Returns:

  • (Hash)

    Response containing new access_token and refresh_token



21
22
23
24
25
26
# File 'lib/voice_notes/resources/auth.rb', line 21

def refresh(refresh_token:)
  post("/api/v1/auth/login", {
         grant_type: "refresh_token",
         refresh_token: refresh_token
       })
end