lib/ably/models/token_details.rb in ably-0.8.5 vs lib/ably/models/token_details.rb in ably-0.8.6

- old
+ new

@@ -1,10 +1,9 @@ module Ably::Models # Convert token details argument to a {TokenDetails} object # - # @param attributes [TokenDetails,Hash] A {TokenDetails} object or Hash of token and meta data attributes - # @option attributes (see TokenDetails#initialize) + # @param attributes (see #initialize) # # @return [TokenDetails] def self.TokenDetails(attributes) case attributes when TokenDetails @@ -25,14 +24,10 @@ # 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 TOKEN_EXPIRY_BUFFER = 15 - def initialize(attributes) - @hash_object = IdiomaticRubyWrapper(attributes.clone.freeze) - end - # @param attributes # @option attributes [String] :token token used to authenticate requests # @option attributes [String] :key_name API key name used to create this token # @option attributes [Time,Integer] :issued Time the token was issued as Time or Integer in milliseconds # @option attributes [Time,Integer] :expires Time the token expires as Time or Integer in milliseconds @@ -74,11 +69,11 @@ end # @!attribute [r] capability # @return [Hash] Capabilities assigned to this token def capability - JSON.parse(hash.fetch(:capability)) if hash.fetch(:capability) + JSON.parse(hash.fetch(:capability)) if hash.has_key?(:capability) end # @!attribute [r] client_id # @return [String] Optional client ID assigned to this token def client_id @@ -92,12 +87,23 @@ def expired? return false if !expires expires < Time.now + TOKEN_EXPIRY_BUFFER end + # True if the TokenDetails was created from an opaque string i.e. no metadata exists for this token + # @return [Boolean] + # @api private + def from_token_string? + hash.keys == [:token] + end + # @!attribute [r] hash # @return [Hash] Access the token details Hash object ruby'fied to use symbolized keys def hash @hash_object + end + + def to_s + "<TokenDetails token=#{token} client_id=#{client_id} key_name=#{key_name} issued=#{issued} expires=#{expires} capability=#{capability} expired?=#{expired?}>" end end end