lib/ably/models/token_details.rb in ably-0.8.8 vs lib/ably/models/token_details.rb in ably-0.8.9

- old
+ new

@@ -14,11 +14,11 @@ end # 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 + # Ruby {http://ruby-doc.org/core/Time.html 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. # class TokenDetails include Ably::Modules::ModelCommon @@ -36,50 +36,52 @@ # def initialize(attributes = {}) @hash_object = IdiomaticRubyWrapper(attributes.clone) %w(issued expires).map(&:to_sym).each do |time_attribute| - hash[time_attribute] = (hash[time_attribute].to_f * 1000).round if hash[time_attribute].kind_of?(Time) + if self.attributes[time_attribute].kind_of?(Time) + self.attributes[time_attribute] = (self.attributes[time_attribute].to_f * 1000).round + end end - hash.freeze + self.attributes.freeze end # @!attribute [r] token # @return [String] Token used to authenticate requests def token - hash[:token] + attributes[:token] end # @!attribute [r] key_name # @return [String] API key name used to create this token. An API key is made up of an API key name and secret delimited by a +:+ def key_name - hash[:key_name] + attributes[:key_name] end # @!attribute [r] issued # @return [Time] Time the token was issued def issued - as_time_from_epoch(hash[:issued], granularity: :ms, allow_nil: :true) + as_time_from_epoch(attributes[:issued], granularity: :ms, allow_nil: :true) end # @!attribute [r] expires # @return [Time] Time the token expires def expires - as_time_from_epoch(hash[:expires], granularity: :ms, allow_nil: :true) + as_time_from_epoch(attributes[:expires], granularity: :ms, allow_nil: :true) end # @!attribute [r] capability # @return [Hash] Capabilities assigned to this token def capability - JSON.parse(hash.fetch(:capability)) if hash.has_key?(:capability) + JSON.parse(attributes.fetch(:capability)) if attributes.has_key?(:capability) end # @!attribute [r] client_id # @return [String] Optional client ID assigned to this token def client_id - hash[:client_id] + attributes[:client_id] end # Returns true if token is expired or about to expire # For tokens that have not got an explicit expires attribute expired? will always return true # @@ -91,15 +93,15 @@ # 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] + attributes.keys == [:token] end - # @!attribute [r] hash + # @!attribute [r] attributes # @return [Hash] Access the token details Hash object ruby'fied to use symbolized keys - def hash + def attributes @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?}>"