class Authentication

Authentication model conatining token generation attributes

Attributes

grant_type[RW]
password[RW]
refresh_token[RW]
token[RW]
username[RW]

Public Class Methods

get_payload(auth_data) click to toggle source

Gets Json represenatation of authentication object

@param [Object] auth_data Authentication object

@return [Json] Json represenatation of authentication object

# File lib/domain/authentication.rb, line 57
def self.get_payload(auth_data)
  auth_data.as_json.to_json
end
get_payload_with_client_info(auth_data) click to toggle source

Gets Json represenatation of authentication object with client details

@param [Object] auth_data Authentication object

@return [Json] Json represenatation of authentication object

# File lib/domain/authentication.rb, line 68
def self.get_payload_with_client_info(auth_data)
  auth_data.as_json.merge!({ 'client_id' => ApplicationConfig.client_id, 'client_secret' => ApplicationConfig.client_secret }).to_json
end
new(grant_type: nil, username: nil, password: nil, token: nil, refresh_token: nil) click to toggle source

Inialise the authentication model

@param [String] grant_type Token grant type @param [String] username @param [String] password @param [String] token Bearer token @param [String] refresh_token Refresh token

# File lib/domain/authentication.rb, line 22
def initialize(grant_type: nil, username: nil, password: nil, token: nil, refresh_token: nil)
  self.grant_type = grant_type
  self.username = username
  self.password = password
  self.token = token
  self.refresh_token = refresh_token
end

Public Instance Methods

as_json(options = {}) click to toggle source

Converts Authentication object to Hash and deletes null value fields

@param [Refrence] options

@return [Hash] Hash of authentication object

# File lib/domain/authentication.rb, line 37
def as_json(options = {})
  hash_data = {
    grant_type: @grant_type,
    username: @username,
    password: @password,
    token: @token,
    refresh_token: @refresh_token
  }

  hash_data.delete_if { |k, v| v.nil? || v.empty? }
  hash_data
end