Class: ResoWebApi::Authentication::Access

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

Overview

Session class for TokenAuth. This stores the access token, the token type (usually `Bearer`), and the expiration date of the token.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Access

Returns a new instance of Access


8
9
10
11
12
# File 'lib/reso_web_api/authentication/access.rb', line 8

def initialize(options = {})
  @token      = options['access_token']
  @expires    = Time.now + options['expires_in']
  @token_type = options['token_type']
end

Instance Attribute Details

#expiresObject

Returns the value of attribute expires


6
7
8
# File 'lib/reso_web_api/authentication/access.rb', line 6

def expires
  @expires
end

#tokenObject

Returns the value of attribute token


6
7
8
# File 'lib/reso_web_api/authentication/access.rb', line 6

def token
  @token
end

#token_typeObject

Returns the value of attribute token_type


6
7
8
# File 'lib/reso_web_api/authentication/access.rb', line 6

def token_type
  @token_type
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)

14
15
16
# File 'lib/reso_web_api/authentication/access.rb', line 14

def expired?
  Time.now > expires
end

#valid?Boolean

Returns:

  • (Boolean)

18
19
20
# File 'lib/reso_web_api/authentication/access.rb', line 18

def valid?
  !!token && !expired?
end