Class: Ravelin::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/ravelin/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, payload:, timestamp: nil) ⇒ Event



5
6
7
8
9
10
11
# File 'lib/ravelin/event.rb', line 5

def initialize(name:, payload:, timestamp: nil)
  @name = convert_event_name(name)
  @payload = convert_to_ravelin_objects(payload)
  @timestamp = timestamp.nil? ? Time.now.to_i : convert_to_epoch(timestamp)

  validate_top_level_payload_params
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/ravelin/event.rb', line 3

def name
  @name
end

#payloadObject

Returns the value of attribute payload.



3
4
5
# File 'lib/ravelin/event.rb', line 3

def payload
  @payload
end

#timestampObject

Returns the value of attribute timestamp.



3
4
5
# File 'lib/ravelin/event.rb', line 3

def timestamp
  @timestamp
end

Instance Method Details

#object_classesObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ravelin/event.rb', line 27

def object_classes
  {
    chargeback:     Chargeback,
    customer:       Customer,
    device:         Device,
    location:       Location,
    order:          Order,
    payment_method: PaymentMethod,
    voucher_redemption: VoucherRedemption,
    transaction:    name == :pretransaction ? PreTransaction : Transaction,
    label:          Label,
    voucher:        Voucher,
  }
end

#serializable_hashObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ravelin/event.rb', line 13

def serializable_hash
  payload_hash = hash_map(payload) do |k, v|
    k = Ravelin.camelize(k)

    if v.is_a?(Ravelin::RavelinObject)
      [k, v.serializable_hash]
    else
      [k, v]
    end
  end

  payload_hash.merge('timestamp' => timestamp)
end