Class: Anthropic::Credentials::AccessToken

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

Overview

An Anthropic API access token with optional expiry.

This is a frozen value object representing an access token and its expiration time. The expires_at is a Unix timestamp in seconds; nil means no expiry information (the token will be treated as never-expires by TokenCache).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token:, expires_at: nil) ⇒ AccessToken

Returns a new instance of AccessToken.

Parameters:

  • token (String)

    the access token string

  • expires_at (Integer, nil) (defaults to: nil)

    Unix timestamp in seconds, or nil for no expiry



21
22
23
24
25
# File 'lib/anthropic/credentials/access_token.rb', line 21

def initialize(token:, expires_at: nil)
  @token = token
  @expires_at = expires_at
  freeze
end

Instance Attribute Details

#expires_atInteger? (readonly)

Returns Unix timestamp in seconds when the token expires, or nil if the token never expires.

Returns:

  • (Integer, nil)

    Unix timestamp in seconds when the token expires, or nil if the token never expires



17
18
19
# File 'lib/anthropic/credentials/access_token.rb', line 17

def expires_at
  @expires_at
end

#tokenString (readonly)

Returns the access token string.

Returns:

  • (String)

    the access token string



13
14
15
# File 'lib/anthropic/credentials/access_token.rb', line 13

def token
  @token
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



32
33
34
35
# File 'lib/anthropic/credentials/access_token.rb', line 32

def ==(other)
  return false unless other.is_a?(AccessToken)
  token == other.token && expires_at == other.expires_at
end

#hashInteger

Returns hash code for the token.

Returns:

  • (Integer)

    hash code for the token



28
29
30
# File 'lib/anthropic/credentials/access_token.rb', line 28

def hash
  [token, expires_at].hash
end