class BBC::Redux::Key
Each asset is served with an associated key that is needed to access it's associated media. Generally these keys have a lifetime of 24 hours
@example Properties of the key object
key = redux_client.asset('5966413090093319525').key key.expired? #=> Boolean key.expires_at #=> DateTime key.live? #=> Boolean key.ttl #=> Integer key.value #=> String
@author Matt Haynes <matt.haynes@bbc.co.uk>
Attributes
@!attribute [r] expires_at
@return [DateTime] the access key's expiry time
@!attribute [r] value @return [String] the access key's value
Public Class Methods
@param value [String] the access keys value
# File lib/bbc/redux/key.rb, line 31 def initialize(value) @value = value @expires_at = Time.at( value.split('-')[1].to_i ).to_datetime end
Public Instance Methods
@return [Boolean] true if other_key is a redux key with the same value
# File lib/bbc/redux/key.rb, line 64 def ==(other_key) self.class == other_key.class && self.value == other_key.value end
@see Key#expired?
@see Key#ttl
@return [Boolean] true if ttl <= 0, false otherwise
# File lib/bbc/redux/key.rb, line 39 def expired? ttl <= 0 end
@see Key#expired?
@see Key#ttl
@return [Boolean] true if ttl > 0, false otherwise
# File lib/bbc/redux/key.rb, line 46 def live? ttl > 0 end
@return the key's value as a string
# File lib/bbc/redux/key.rb, line 51 def to_s value end
@see Key#expired?
@see Key#expires_at
@see Key#live?
@return [Integer] key's Time To Live in seconds
# File lib/bbc/redux/key.rb, line 59 def ttl expires_at.to_time.to_i - Time.now.to_i end