Module: WrAPI::Authentication

Included in:
API
Defined in:
lib/wrapi/authentication.rb

Overview

Deals with authentication flow and stores it within global configuration following attributes should be available:

username
password
access_token
token_type
refresh_token
token_expires

Instance Method Summary collapse

Instance Method Details

#api_auth(path, options = {}) ⇒ String

Authenticates the API request by merging the provided options with the API access token parameters, sending a POST request to the specified path, and processing the response to extract the access token.

Parameters:

  • path (String)

    the API endpoint path to which the authentication request is sent.

  • options (Hash) (defaults to: {})

    additional parameters to be merged with the API access token parameters.

Returns:

  • (String)

    the processed access token extracted from the response body.



19
20
21
22
23
24
# File 'lib/wrapi/authentication.rb', line 19

def api_auth(path, options = {})
  params = api_access_token_params.merge(options)
  response = post(path, params)
  # return access_token

  api_process_token(response.body)
end

#api_refresh(path, token) ⇒ String

Refreshes the API token by making a POST request to the specified path with the given refresh token.

Parameters:

  • path (String)

    the endpoint path to send the refresh request to.

  • token (String)

    the refresh token to be used for obtaining a new access token.

Returns:

  • (String)

    the new access token obtained from the response.



31
32
33
34
35
36
37
# File 'lib/wrapi/authentication.rb', line 31

def api_refresh(path, token)
  params = { refreshToken: token }

  response = post(path, params)
  # return access_token

  api_process_token(response.body)
end