class BBC::Redux::Key

Redux API Asset Key Object

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

expires_at[R]

@!attribute [r] expires_at @return [DateTime] the access key's expiry time

value[R]

@!attribute [r] value @return [String] the access key's value

Public Class Methods

new(value) click to toggle source

@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

==(other_key) click to toggle source

@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
Also aliased as: eql?
eql?(other_key)
Alias for: ==
expired?() click to toggle source

@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
live?() click to toggle source

@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
to_s() click to toggle source

@return the key's value as a string

# File lib/bbc/redux/key.rb, line 51
def to_s
  value
end
ttl() click to toggle source

@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