Class: SpamProtect::Encryption::Payload

Inherits:
Object
  • Object
show all
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

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

.generateObject



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_atObject 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

#timestampObject Also known as: timestamp?



36
37
38
# File 'lib/spam_protect/encryption/payload.rb', line 36

def timestamp
  @hash[:timestamp] || @hash["timestamp"]
end

#to_hObject



25
26
27
28
29
30
# File 'lib/spam_protect/encryption/payload.rb', line 25

def to_h
  {
    "timestamp" => timestamp,
    "expires_at" => expires_at
  }
end