Class: Ably::Models::Token
- Inherits:
-
Object
- Object
- Ably::Models::Token
- Includes:
- Ably::Modules::ModelCommon
- Defined in:
- lib/ably/models/token.rb
Overview
Authentication token issued by Ably in response to an token request
Constant Summary collapse
- DEFAULTS =
{ capability: { '*' => ['*'] }, ttl: 60 * 60 # 1 hour }
- TOKEN_EXPIRY_BUFFER =
Buffer in seconds given to the use of a token prior to it being considered unusable For example, if buffer is 10s, the token can no longer be used for new requests 9s before it expires
5
Instance Attribute Summary collapse
-
#capability ⇒ Hash
readonly
Capabilities assigned to this token.
-
#client_id ⇒ String
readonly
Optional client ID assigned to this token.
-
#expires_at ⇒ Time
readonly
Time the token expires.
-
#hash ⇒ Hash
readonly
Access the token Hash object ruby’fied to use symbolized keys.
-
#id ⇒ String
readonly
Unique token ID used to authenticate requests.
-
#issued_at ⇒ Time
readonly
Time the token was issued.
-
#key_id ⇒ String
readonly
Key ID used to create this token.
-
#nonce ⇒ String
readonly
Unique nonce used to generate Token and ensure token generation cannot be replayed.
Instance Method Summary collapse
-
#expired? ⇒ Boolean
Returns true if token is expired or about to expire.
-
#initialize(attributes) ⇒ Token
constructor
A new instance of Token.
Methods included from Ably::Modules::ModelCommon
Methods included from Ably::Modules::MessagePack
Constructor Details
#initialize(attributes) ⇒ Token
Returns a new instance of Token.
15 16 17 |
# File 'lib/ably/models/token.rb', line 15 def initialize(attributes) @hash_object = IdiomaticRubyWrapper(attributes.clone.freeze) end |
Instance Attribute Details
#capability ⇒ Hash (readonly)
Returns Capabilities assigned to this token.
45 46 47 |
# File 'lib/ably/models/token.rb', line 45 def capability hash.fetch(:capability) end |
#client_id ⇒ String (readonly)
Returns Optional client ID assigned to this token.
51 52 53 |
# File 'lib/ably/models/token.rb', line 51 def client_id hash[:client_id] end |
#expires_at ⇒ Time (readonly)
Returns Time the token expires.
39 40 41 |
# File 'lib/ably/models/token.rb', line 39 def expires_at as_time_from_epoch(hash.fetch(:expires), granularity: :s) end |
#hash ⇒ Hash (readonly)
Returns Access the token Hash object ruby’fied to use symbolized keys.
70 71 72 |
# File 'lib/ably/models/token.rb', line 70 def hash @hash_object end |
#id ⇒ String (readonly)
Returns Unique token ID used to authenticate requests.
21 22 23 |
# File 'lib/ably/models/token.rb', line 21 def id hash.fetch(:id) end |
#issued_at ⇒ Time (readonly)
Returns Time the token was issued.
33 34 35 |
# File 'lib/ably/models/token.rb', line 33 def issued_at as_time_from_epoch(hash.fetch(:issued_at), granularity: :s) end |
#key_id ⇒ String (readonly)
Returns Key ID used to create this token.
27 28 29 |
# File 'lib/ably/models/token.rb', line 27 def key_id hash.fetch(:key) end |
#nonce ⇒ String (readonly)
Returns unique nonce used to generate Token and ensure token generation cannot be replayed.
57 58 59 |
# File 'lib/ably/models/token.rb', line 57 def nonce hash.fetch(:nonce) end |
Instance Method Details
#expired? ⇒ Boolean
Returns true if token is expired or about to expire
64 65 66 |
# File 'lib/ably/models/token.rb', line 64 def expired? expires_at < Time.now + TOKEN_EXPIRY_BUFFER end |