class Omnikassa2::Notification

Constants

EXPIRATION_MARGIN_SECONDS

Attributes

authentication[R]
event_name[R]
expiry[R]
poi_id[R]
signature[R]

Public Class Methods

from_json(json) click to toggle source
# File lib/omnikassa2/models/notification.rb, line 19
def self.from_json(json)
  hash = JSON.parse(json)
  Notification.new(
    authentication: hash['authentication'],
    expiry: Time.parse(hash['expiry']),
    event_name: hash['eventName'],
    poi_id: hash['poiId'],
    signature: hash['signature']
  )
end
new(params) click to toggle source
# File lib/omnikassa2/models/notification.rb, line 11
def initialize(params)
  @authentication = params.fetch(:authentication)
  @expiry = params.fetch(:expiry)
  @event_name = params.fetch(:event_name)
  @poi_id = params.fetch(:poi_id)
  @signature = params.fetch(:signature)
end

Private Class Methods

csv_serializer() click to toggle source
# File lib/omnikassa2/models/notification.rb, line 44
def self.csv_serializer
  CSVSerializer.new([
    { field: :authentication },
    { field: :expiry },
    { field: :event_name },
    { field: :poi_id }
  ])
end

Public Instance Methods

expiring?() click to toggle source
# File lib/omnikassa2/models/notification.rb, line 30
def expiring?
  (Time.now + EXPIRATION_MARGIN_SECONDS) - @expiry > 0
end
to_s() click to toggle source
# File lib/omnikassa2/models/notification.rb, line 38
def to_s
  Notification.csv_serializer.serialize(self)
end
valid_signature?() click to toggle source
# File lib/omnikassa2/models/notification.rb, line 34
def valid_signature?
  SignatureService.validate(to_s, @signature)
end