Class: Ably::Models::TokenRequest
- Inherits:
-
Object
- Object
- Ably::Models::TokenRequest
- Includes:
- Ably::Modules::ModelCommon
- Defined in:
- lib/ably/models/token_request.rb
Overview
TokenRequest is a class that stores the attributes of a token request
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.
Instance Attribute Summary collapse
-
#attributes ⇒ Hash
readonly
The token request Hash object ruby’fied to use symbolized keys.
-
#capability ⇒ Hash
readonly
Capability of the token.
-
#client_id ⇒ String
readonly
The client ID to associate with this token.
-
#key_name ⇒ String
readonly
API key name of the key against which this request is made.
-
#mac ⇒ String
readonly
The Message Authentication Code for this request.
-
#nonce ⇒ String
readonly
An opaque nonce string of at least 16 characters to ensure uniqueness of this request.
-
#timestamp ⇒ Time
readonly
The timestamp of this request.
-
#ttl ⇒ Integer
readonly
Requested time to live for the token in seconds.
Attributes included from Ably::Modules::ModelCommon
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ TokenRequest
constructor
A new instance of TokenRequest.
-
#persisted ⇒ Object
private
Requests that the token is always persisted.
Methods included from Ably::Modules::ModelCommon
Methods included from Ably::Modules::MessagePack
Constructor Details
#initialize(attributes = {}) ⇒ TokenRequest
Returns a new instance of TokenRequest.
34 35 36 37 38 39 40 |
# File 'lib/ably/models/token_request.rb', line 34 def initialize(attributes = {}) @hash_object = IdiomaticRubyWrapper(attributes.clone) if self.attributes[:timestamp].kind_of?(Time) self.attributes[:timestamp] = (self.attributes[:timestamp].to_f * 1000).round end self.attributes.freeze end |
Instance Attribute Details
#attributes ⇒ Hash (readonly)
Returns the token request Hash object ruby’fied to use symbolized keys.
105 106 107 |
# File 'lib/ably/models/token_request.rb', line 105 def attributes @hash_object end |
#capability ⇒ Hash (readonly)
Returns capability of the token. If the token request is successful, the capability of the returned token will be the intersection of this capability with the capability of the issuing key.
61 62 63 |
# File 'lib/ably/models/token_request.rb', line 61 def capability JSON.parse(attributes.fetch(:capability)) end |
#client_id ⇒ String (readonly)
Returns the client ID to associate with this token. The generated token may be used to authenticate as this clientId.
68 69 70 |
# File 'lib/ably/models/token_request.rb', line 68 def client_id attributes[:client_id] end |
#key_name ⇒ String (readonly)
Returns API key name of the key against which this request is made. An API key is made up of an API key name and secret delimited by a :
.
44 45 46 |
# File 'lib/ably/models/token_request.rb', line 44 def key_name attributes.fetch(:key_name) end |
#mac ⇒ String (readonly)
Returns the Message Authentication Code for this request. See the Ably Authentication documentation for more details.
92 93 94 |
# File 'lib/ably/models/token_request.rb', line 92 def mac attributes.fetch(:mac) end |
#nonce ⇒ String (readonly)
Returns an opaque nonce string of at least 16 characters to ensure uniqueness of this request. Any subsequent request using the same nonce will be rejected.
85 86 87 |
# File 'lib/ably/models/token_request.rb', line 85 def nonce attributes.fetch(:nonce) end |
#timestamp ⇒ Time (readonly)
Returns the timestamp of this request. Timestamps, in conjunction with the nonce, are used to prevent token requests from being replayed. Timestamp when sent to Ably is in milliseconds.
77 78 79 |
# File 'lib/ably/models/token_request.rb', line 77 def as_time_from_epoch(attributes.fetch(:timestamp), granularity: :ms) end |
#ttl ⇒ Integer (readonly)
Returns requested time to live for the token in seconds. If the token request is successful, the TTL of the returned token will be less than or equal to this value depending on application settings and the attributes of the issuing key. TTL when sent to Ably is in milliseconds.
53 54 55 |
# File 'lib/ably/models/token_request.rb', line 53 def ttl attributes.fetch(:ttl) / 1000 end |
Instance Method Details
#persisted ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Requests that the token is always persisted
99 100 101 |
# File 'lib/ably/models/token_request.rb', line 99 def persisted attributes.fetch(:persisted) end |