Module: Webhooks::Outgoing::EventSupport

Extended by:
ActiveSupport::Concern
Includes:
HasUuid
Included in:
Event
Defined in:
app/models/concerns/webhooks/outgoing/event_support.rb

Instance Method Summary collapse

Instance Method Details

#deliverObject



43
44
45
46
47
48
49
# File 'app/models/concerns/webhooks/outgoing/event_support.rb', line 43

def deliver
  endpoints.each do |endpoint|
    unless endpoint.deliveries.where(event: self).any?
      endpoint.deliveries.create(event: self, endpoint_url: endpoint.url).deliver_async
    end
  end
end

#endpointsObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/concerns/webhooks/outgoing/event_support.rb', line 30

def endpoints
  endpoints = send(BulletTrain::OutgoingWebhooks.parent_association).webhooks_outgoing_endpoints.where(api_version: api_version).listening_for_event_type_id(event_type_id)

  case subject_type
  when "Scaffolding::AbsolutelyAbstract::CreativeConcept"
    endpoints.where(scaffolding_absolutely_abstract_creative_concept_id: [subject.id, nil])
  when "Scaffolding::CompletelyConcrete::TangibleThing"
    endpoints.where(scaffolding_absolutely_abstract_creative_concept_id: [subject.absolutely_abstract_creative_concept_id, nil])
  else
    endpoints
  end
end

#event_type_nameObject



26
27
28
# File 'app/models/concerns/webhooks/outgoing/event_support.rb', line 26

def event_type_name
  payload.dig("event_type")
end

#generate_payloadObject



16
17
18
19
20
21
22
23
24
# File 'app/models/concerns/webhooks/outgoing/event_support.rb', line 16

def generate_payload
  {
    event_id: uuid,
    event_type: event_type_id,
    subject_id: subject_id,
    subject_type: subject_type,
    data: data
  }
end

#label_stringObject



51
52
53
# File 'app/models/concerns/webhooks/outgoing/event_support.rb', line 51

def label_string
  short_uuid
end