Class: DecisionAgent::Auth::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/decision_agent/auth/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_id:, expires_in: 3600) ⇒ Session

Returns a new instance of Session.



10
11
12
13
14
15
# File 'lib/decision_agent/auth/session.rb', line 10

def initialize(user_id:, expires_in: 3600)
  @token = SecureRandom.hex(32)
  @user_id = user_id
  @created_at = Time.now.utc
  @expires_at = @created_at + expires_in
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



8
9
10
# File 'lib/decision_agent/auth/session.rb', line 8

def created_at
  @created_at
end

#expires_atObject (readonly)

Returns the value of attribute expires_at.



8
9
10
# File 'lib/decision_agent/auth/session.rb', line 8

def expires_at
  @expires_at
end

#tokenObject (readonly)

Returns the value of attribute token.



8
9
10
# File 'lib/decision_agent/auth/session.rb', line 8

def token
  @token
end

#user_idObject (readonly)

Returns the value of attribute user_id.



8
9
10
# File 'lib/decision_agent/auth/session.rb', line 8

def user_id
  @user_id
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/decision_agent/auth/session.rb', line 17

def expired?
  Time.now.utc > @expires_at
end

#to_hObject



25
26
27
28
29
30
31
32
# File 'lib/decision_agent/auth/session.rb', line 25

def to_h
  {
    token: @token,
    user_id: @user_id,
    created_at: @created_at.iso8601,
    expires_at: @expires_at.iso8601
  }
end

#valid?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/decision_agent/auth/session.rb', line 21

def valid?
  !expired?
end