lib/ably/models/token_request.rb in ably-0.8.15 vs lib/ably/models/token_request.rb in ably-1.0.0
- old
+ new
@@ -40,11 +40,11 @@
end
# @!attribute [r] key_name
# @return [String] 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 +:+
def key_name
- attributes.fetch(:key_name)
+ attributes.fetch(:key_name) { raise Ably::Exceptions::InvalidTokenRequest, 'Key name is missing' }
end
# @!attribute [r] ttl
# @return [Integer] 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
@@ -57,11 +57,20 @@
# @!attribute [r] capability
# @return [Hash] 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.
def capability
- JSON.parse(attributes.fetch(:capability))
+ capability_val = attributes.fetch(:capability) { raise Ably::Exceptions::InvalidTokenRequest, 'Capability is missing' }
+
+ case capability_val
+ when Hash
+ capability_val
+ when Ably::Models::IdiomaticRubyWrapper
+ capability_val.as_json
+ else
+ JSON.parse(attributes.fetch(:capability))
+ end
end
# @!attribute [r] client_id
# @return [String] the client ID to associate with this token. The generated token
# may be used to authenticate as this clientId.
@@ -73,32 +82,33 @@
# @return [Time] 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.
def timestamp
- as_time_from_epoch(attributes.fetch(:timestamp), granularity: :ms)
+ timestamp_val = attributes.fetch(:timestamp) { raise Ably::Exceptions::InvalidTokenRequest, 'Timestamp is missing' }
+ as_time_from_epoch(timestamp_val, granularity: :ms)
end
# @!attribute [r] nonce
# @return [String] 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.
def nonce
- attributes.fetch(:nonce)
+ attributes.fetch(:nonce) { raise Ably::Exceptions::InvalidTokenRequest, 'Nonce is missing' }
end
# @!attribute [r] mac
# @return [String] the Message Authentication Code for this request. See the
# {https://www.ably.io/documentation Ably Authentication documentation} for more details.
def mac
- attributes.fetch(:mac)
+ attributes.fetch(:mac) { raise Ably::Exceptions::InvalidTokenRequest, 'MAC is missing' }
end
# Requests that the token is always persisted
# @api private
#
def persisted
- attributes.fetch(:persisted)
+ attributes[:persisted]
end
# @!attribute [r] attributes
# @return [Hash] the token request Hash object ruby'fied to use symbolized keys
def attributes