Class: Maventa::AccessToken

Inherits:
Object
  • Object
show all
Defined in:
lib/maventa/access_token.rb

Constant Summary collapse

EXPIRATION_MARGIN =
60

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token:, expires_in:, token_type:, scope:) ⇒ AccessToken

Returns a new instance of AccessToken.



7
8
9
10
11
12
13
# File 'lib/maventa/access_token.rb', line 7

def initialize(token:, expires_in:, token_type:, scope:)
  @token = token
  @expires_in = expires_in
  @expires_at = Time.now.to_i + expires_in
  @token_type = token_type
  @scope = scope
end

Instance Attribute Details

#expires_atObject

Returns the value of attribute expires_at.



3
4
5
# File 'lib/maventa/access_token.rb', line 3

def expires_at
  @expires_at
end

#expires_inObject

Returns the value of attribute expires_in.



3
4
5
# File 'lib/maventa/access_token.rb', line 3

def expires_in
  @expires_in
end

#scopeObject

Returns the value of attribute scope.



3
4
5
# File 'lib/maventa/access_token.rb', line 3

def scope
  @scope
end

#tokenObject

Returns the value of attribute token.



3
4
5
# File 'lib/maventa/access_token.rb', line 3

def token
  @token
end

#token_typeObject

Returns the value of attribute token_type.



3
4
5
# File 'lib/maventa/access_token.rb', line 3

def token_type
  @token_type
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/maventa/access_token.rb', line 19

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

#expired_or_about_to_expire?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/maventa/access_token.rb', line 27

def expired_or_about_to_expire?
  Time.now.to_i > (@expires_at - EXPIRATION_MARGIN)
end

#scopesObject



15
16
17
# File 'lib/maventa/access_token.rb', line 15

def scopes
  @scope.split " "
end

#valid?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/maventa/access_token.rb', line 23

def valid?
  !expired?
end