Class: Authentication

Inherits:
Object
  • Object
show all
Defined in:
lib/domain/authentication.rb

Overview

Authentication model conatining token generation attributes

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(grant_type: nil, client_id: nil, client_secret: nil, username: nil, password: nil, token: nil, refresh_token: nil) ⇒ Authentication

Inialise the authentication model

Parameters:

  • grant_type (String) (defaults to: nil)

    Token grant type

  • client_id (String) (defaults to: nil)
  • client_secret (String) (defaults to: nil)
  • username (String) (defaults to: nil)
  • password (String) (defaults to: nil)
  • token (String) (defaults to: nil)

    Bearer token

  • refresh_token (String) (defaults to: nil)

    Refresh token



26
27
28
29
30
31
32
33
34
35
# File 'lib/domain/authentication.rb', line 26

def initialize(grant_type: nil, client_id: nil, client_secret: nil,
               username: nil, password: nil, token: nil, refresh_token: nil)
  self.grant_type = grant_type
  self.client_id = client_id
  self.client_secret = client_secret
  self.username = username
  self.password = password
  self.token = token
  self.refresh_token = refresh_token
end

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



8
9
10
# File 'lib/domain/authentication.rb', line 8

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



9
10
11
# File 'lib/domain/authentication.rb', line 9

def client_secret
  @client_secret
end

#grant_typeObject

Returns the value of attribute grant_type.



7
8
9
# File 'lib/domain/authentication.rb', line 7

def grant_type
  @grant_type
end

#passwordObject

Returns the value of attribute password.



11
12
13
# File 'lib/domain/authentication.rb', line 11

def password
  @password
end

#refresh_tokenObject

Returns the value of attribute refresh_token.



13
14
15
# File 'lib/domain/authentication.rb', line 13

def refresh_token
  @refresh_token
end

#tokenObject

Returns the value of attribute token.



12
13
14
# File 'lib/domain/authentication.rb', line 12

def token
  @token
end

#usernameObject

Returns the value of attribute username.



10
11
12
# File 'lib/domain/authentication.rb', line 10

def username
  @username
end

Class Method Details

.get_payload(auth_data) ⇒ Json

Gets Json represenatation of authentication object

Parameters:

  • auth_data (Object)

    Authentication object

Returns:

  • (Json)

    Json represenatation of authentication object



65
66
67
# File 'lib/domain/authentication.rb', line 65

def self.get_payload(auth_data)
  auth_data.to_json
end

Instance Method Details

#to_json(*data) ⇒ Json

Converts Authentication object to Json object

Parameters:

  • *data (Refrence)

    authentication object refrence

Returns:

  • (Json)

    Json represenatation of authentication object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/domain/authentication.rb', line 44

def to_json(*data)
  hash = {
    grant_type: @grant_type,
    client_id: @client_id,
    client_secret: @client_secret,
    username: @username,
    password: @password,
    token: @token,
    refresh_token: @refresh_token
  }
  hash.delete_if { |k, v| v.nil? || v.empty? }
  hash.to_json(*data)
end