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

Returns a new instance of Event.



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

def initialize(name:, payload:, timestamp: nil)
  @internal_name = name
  @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

#format_timestamp(timestamp) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/ravelin/event.rb', line 60

def format_timestamp(timestamp)
  case @internal_name
  when :ato_login
    timestamp * 1000
  when :ato_reclaim
    Time.at(timestamp).utc.to_datetime.to_s
  else
    timestamp
  end
end

#object_classesObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ravelin/event.rb', line 28

def object_classes
  {
    ato_login:                AtoLogin,
    authentication_mechanism: AuthenticationMechanism,
    chargeback:               Chargeback,
    customer:                 Customer,
    ato_reclaim:              AtoReclaim,
    device:                   Device,
    location:                 Location,
    login:                    Login,
    order:                    Order,
    password:                 Password,
    payment_method:           PaymentMethod,
    supplier:                 Supplier,
    voucher_redemption:       VoucherRedemption,
    transaction:              transaction,
    label:                    Label,
    voucher:                  Voucher,
  }
end

#serializable_hashObject



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

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' => format_timestamp(timestamp))
end

#transactionObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/ravelin/event.rb', line 49

def transaction
  case name
  when :pretransaction
    PreTransaction
  when :checkout
    CheckoutTransaction
  else
    Transaction
  end
end