Class: SpamProtect::Encryption::Payload
- Inherits:
-
Object
- Object
- SpamProtect::Encryption::Payload
- Defined in:
- lib/spam_protect/encryption/payload.rb
Constant Summary collapse
- VALID_METHODS =
%w[timestamp expires_at].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #expires_at ⇒ Object (also: #expires_at?)
-
#initialize(hash) ⇒ Payload
constructor
A new instance of Payload.
- #timestamp ⇒ Object (also: #timestamp?)
- #to_h ⇒ Object
Constructor Details
#initialize(hash) ⇒ Payload
Returns a new instance of Payload.
15 16 17 |
# File 'lib/spam_protect/encryption/payload.rb', line 15 def initialize(hash) @hash = hash end |
Class Method Details
.generate ⇒ Object
8 9 10 11 12 13 |
# File 'lib/spam_protect/encryption/payload.rb', line 8 def self.generate new({ timestamp: CurrentTime.now.to_i, expires_at: CurrentTime.now.to_i + SpamProtect.config.signature_expiry.to_i }) end |
Instance Method Details
#[](key) ⇒ Object
19 20 21 22 23 |
# File 'lib/spam_protect/encryption/payload.rb', line 19 def [](key) if VALID_METHODS.include?(key.to_s) send(key) end end |
#expires_at ⇒ Object Also known as: expires_at?
32 33 34 |
# File 'lib/spam_protect/encryption/payload.rb', line 32 def expires_at @hash[:expires_at] || @hash["expires_at"] end |
#timestamp ⇒ Object Also known as: timestamp?
36 37 38 |
# File 'lib/spam_protect/encryption/payload.rb', line 36 def @hash[:timestamp] || @hash["timestamp"] end |
#to_h ⇒ Object
25 26 27 28 29 30 |
# File 'lib/spam_protect/encryption/payload.rb', line 25 def to_h { "timestamp" => , "expires_at" => expires_at } end |