Class: BBC::Redux::Key
- Inherits:
-
Object
- Object
- BBC::Redux::Key
- Defined in:
- lib/bbc/redux/key.rb
Overview
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
Instance Attribute Summary collapse
-
#expires_at ⇒ DateTime
readonly
The access key’s expiry time.
-
#value ⇒ String
readonly
The access key’s value.
Instance Method Summary collapse
-
#==(other_key) ⇒ Boolean
(also: #eql?)
True if other_key is a redux key with the same value.
-
#expired? ⇒ Boolean
True if ttl <= 0, false otherwise.
-
#initialize(value) ⇒ Key
constructor
A new instance of Key.
-
#live? ⇒ Boolean
True if ttl > 0, false otherwise.
-
#to_s ⇒ Object
The key’s value as a string.
-
#ttl ⇒ Integer
Key’s Time To Live in seconds.
Constructor Details
#initialize(value) ⇒ Key
Returns a new instance of Key.
31 32 33 34 |
# 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 |
Instance Attribute Details
#expires_at ⇒ DateTime (readonly)
Returns the access key’s expiry time.
24 25 26 |
# File 'lib/bbc/redux/key.rb', line 24 def expires_at @expires_at end |
#value ⇒ String (readonly)
Returns the access key’s value.
28 29 30 |
# File 'lib/bbc/redux/key.rb', line 28 def value @value end |
Instance Method Details
#==(other_key) ⇒ Boolean Also known as: eql?
Returns true if other_key is a redux key with the same value.
64 65 66 |
# File 'lib/bbc/redux/key.rb', line 64 def ==(other_key) self.class == other_key.class && self.value == other_key.value end |
#expired? ⇒ Boolean
Returns true if ttl <= 0, false otherwise.
39 40 41 |
# File 'lib/bbc/redux/key.rb', line 39 def expired? ttl <= 0 end |
#live? ⇒ Boolean
Returns true if ttl > 0, false otherwise.
46 47 48 |
# File 'lib/bbc/redux/key.rb', line 46 def live? ttl > 0 end |
#to_s ⇒ Object
Returns the key’s value as a string.
51 52 53 |
# File 'lib/bbc/redux/key.rb', line 51 def to_s value end |
#ttl ⇒ Integer
Returns key’s Time To Live in seconds.
59 60 61 |
# File 'lib/bbc/redux/key.rb', line 59 def ttl expires_at.to_time.to_i - Time.now.to_i end |