Module: CycloneLariat::Generators::Event

Included in:
Clients::Abstract, Publisher
Defined in:
lib/cyclone_lariat/generators/event.rb

Instance Method Summary collapse

Instance Method Details

#event(type, version: config.version, **options) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/cyclone_lariat/generators/event.rb', line 10

def event(type, version: config.version, **options)
  case version.to_i
  when 1 then event_v1(type, **options)
  when 2 then event_v2(type, **options)
  else raise ArgumentError, "Unknown version #{version}"
  end
end

#event_v1(type, data: {}, request_id: nil, group_id: nil, deduplication_id: nil, uuid: SecureRandom.uuid) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cyclone_lariat/generators/event.rb', line 18

def event_v1(type, data: {}, request_id: nil, group_id: nil, deduplication_id: nil, uuid: SecureRandom.uuid)
  params = {
    uuid: uuid,
    type: type,
    sent_at: Time.now.iso8601(3),
    version: 1,
    publisher: config.publisher,
    data: data,
    request_id: request_id,
    group_id: group_id,
    deduplication_id: deduplication_id
  }

  Messages::V1::Event.wrap(params.compact)
end

#event_v2(type, subject:, object:, data: {}, request_id: nil, group_id: nil, deduplication_id: nil, uuid: SecureRandom.uuid) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cyclone_lariat/generators/event.rb', line 34

def event_v2(type, subject:, object:, data: {}, request_id: nil, group_id: nil, deduplication_id: nil, uuid: SecureRandom.uuid)
  params = {
    uuid: uuid,
    type: type,
    subject: subject,
    object: object,
    sent_at: Time.now.iso8601(3),
    version: 2,
    publisher: config.publisher,
    data: data,
    request_id: request_id,
    group_id: group_id,
    deduplication_id: deduplication_id
  }

  Messages::V2::Event.wrap(params.compact)
end