Class: Ably::Models::TokenDetails
- Inherits:
-
Object
- Object
- Ably::Models::TokenDetails
- Includes:
- Ably::Modules::ModelCommon
- Defined in:
- lib/submodules/ably-ruby/lib/ably/models/token_details.rb
Overview
TokenDetails is a class providing details of the token string and the token’s associated metadata, constructed from the response from Ably when request in a token via the REST API.
Ruby Time objects are supported in place of Ably ms since epoch time fields. However, if a numeric is provided it must always be expressed in milliseconds as the Ably API always uses milliseconds for time fields.
Constant Summary collapse
- TOKEN_EXPIRY_BUFFER =
Buffer in seconds before a token is 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 ⇒ Time
readonly
Time the token expires.
-
#hash ⇒ Hash
readonly
Access the token details Hash object ruby’fied to use symbolized keys.
-
#issued ⇒ Time
readonly
Time the token was issued.
-
#key_name ⇒ String
readonly
API key name used to create this token.
-
#token ⇒ String
readonly
Token used to authenticate requests.
Instance Method Summary collapse
-
#expired? ⇒ Boolean
Returns true if token is expired or about to expire.
-
#initialize(attributes = {}) ⇒ TokenDetails
constructor
A new instance of TokenDetails.
Methods included from Ably::Modules::ModelCommon
Methods included from Ably::Modules::MessagePack
Constructor Details
#initialize(attributes = {}) ⇒ TokenDetails
Returns a new instance of TokenDetails.
42 43 44 |
# File 'lib/submodules/ably-ruby/lib/ably/models/token_details.rb', line 42 def initialize(attributes) @hash_object = IdiomaticRubyWrapper(attributes.clone.freeze) end |
Instance Attribute Details
#capability ⇒ Hash (readonly)
Returns Capabilities assigned to this token.
78 79 80 |
# File 'lib/submodules/ably-ruby/lib/ably/models/token_details.rb', line 78 def capability JSON.parse(hash.fetch(:capability)) end |
#client_id ⇒ String (readonly)
Returns Optional client ID assigned to this token.
84 85 86 |
# File 'lib/submodules/ably-ruby/lib/ably/models/token_details.rb', line 84 def client_id hash[:client_id] end |
#expires ⇒ Time (readonly)
Returns Time the token expires.
72 73 74 |
# File 'lib/submodules/ably-ruby/lib/ably/models/token_details.rb', line 72 def expires as_time_from_epoch(hash.fetch(:expires), granularity: :ms) end |
#hash ⇒ Hash (readonly)
Returns Access the token details Hash object ruby’fied to use symbolized keys.
97 98 99 |
# File 'lib/submodules/ably-ruby/lib/ably/models/token_details.rb', line 97 def hash @hash_object end |
#issued ⇒ Time (readonly)
Returns Time the token was issued.
66 67 68 |
# File 'lib/submodules/ably-ruby/lib/ably/models/token_details.rb', line 66 def issued as_time_from_epoch(hash.fetch(:issued), granularity: :ms) end |
#key_name ⇒ String (readonly)
Returns API key name used to create this token. An API key is made up of an API key name and secret delimited by a :.
60 61 62 |
# File 'lib/submodules/ably-ruby/lib/ably/models/token_details.rb', line 60 def key_name hash.fetch(:key_name) end |
#token ⇒ String (readonly)
Returns Token used to authenticate requests.
54 55 56 |
# File 'lib/submodules/ably-ruby/lib/ably/models/token_details.rb', line 54 def token hash.fetch(:token) end |
Instance Method Details
#expired? ⇒ Boolean
Returns true if token is expired or about to expire
91 92 93 |
# File 'lib/submodules/ably-ruby/lib/ably/models/token_details.rb', line 91 def expired? expires < Time.now + TOKEN_EXPIRY_BUFFER end |