Class: OAuth2c::AccessToken

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token:, token_type:, expires_in:, expires_at: nil, refresh_token: nil, **extra) ⇒ AccessToken

Returns a new instance of AccessToken.



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/oauth2c/access_token.rb', line 28

def initialize(access_token:, token_type:, expires_in:, expires_at: nil, refresh_token: nil, **extra)
  @access_token  = access_token
  @token_type    = token_type
  @expires_in    = Integer(expires_in)
  @refresh_token = refresh_token


  extra.delete(:expires_at)
  @extra = extra

  @expires_at = normalize_time(expires_at) || Time.now + @expires_in
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



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

def access_token
  @access_token
end

#expires_atObject (readonly)

Returns the value of attribute expires_at.



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

def expires_at
  @expires_at
end

#expires_inObject (readonly)

Returns the value of attribute expires_in.



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

def expires_in
  @expires_in
end

#refresh_tokenObject (readonly)

Returns the value of attribute refresh_token.



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

def refresh_token
  @refresh_token
end

#token_typeObject (readonly)

Returns the value of attribute token_type.



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

def token_type
  @token_type
end

Instance Method Details

#==(other) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/oauth2c/access_token.rb', line 56

def ==(other)
  return false unless other.is_a?(self.class)

  access_token == other.access_token &&
  token_type == other.token_type &&
  expires_in == other.expires_in &&
  refresh_token == other.refresh_token &&
  extra == other.extra
end

#attributesObject



41
42
43
44
45
46
47
48
49
50
# File 'lib/oauth2c/access_token.rb', line 41

def attributes
  {
    access_token: @access_token,
    token_type: @token_type,
    expires_in: @expires_in,
    expires_at: @expires_at,
    refresh_token: @refresh_token,
    **@extra,
  }
end

#expired?(leeway = 0) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/oauth2c/access_token.rb', line 52

def expired?(leeway = 0)
  @expires_at - leeway < Time.now
end