Class: LedgerSync::Ledgers::TestLedger::WebhookNotification

Inherits:
Object
  • Object
show all
Defined in:
lib/ledger_sync/test/support/test_ledger/webhook_notification.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ WebhookNotification

Returns a new instance of WebhookNotification.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ledger_sync/test/support/test_ledger/webhook_notification.rb', line 16

def initialize(args = {})
  @original_payload = args.fetch(:payload)
  @webhook          = args.fetch(:webhook, nil)
  @payload          = original_payload.is_a?(String) ? JSON.parse(original_payload) : original_payload

  @realm_id = @payload['realmId']
  raise 'Invalid payload: Could not find realmId' if @realm_id.blank?

  events_payload = @payload.dig('dataChangeEvent', 'entities')
  raise 'Invalid payload: Could not find dataChangeEvent -> entities' unless events_payload.is_a?(Array)

  @events = []

  events_payload.each do |event_payload|
    @events << WebhookEvent.new(
      payload: event_payload,
      webhook_notification: self
    )
  end
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



10
11
12
# File 'lib/ledger_sync/test/support/test_ledger/webhook_notification.rb', line 10

def events
  @events
end

#original_payloadObject (readonly)

Returns the value of attribute original_payload.



10
11
12
# File 'lib/ledger_sync/test/support/test_ledger/webhook_notification.rb', line 10

def original_payload
  @original_payload
end

#payloadObject (readonly)

Returns the value of attribute payload.



10
11
12
# File 'lib/ledger_sync/test/support/test_ledger/webhook_notification.rb', line 10

def payload
  @payload
end

#realm_idObject (readonly)

Returns the value of attribute realm_id.



10
11
12
# File 'lib/ledger_sync/test/support/test_ledger/webhook_notification.rb', line 10

def realm_id
  @realm_id
end

#webhookObject (readonly)

Returns the value of attribute webhook.



10
11
12
# File 'lib/ledger_sync/test/support/test_ledger/webhook_notification.rb', line 10

def webhook
  @webhook
end

Instance Method Details

#resourcesObject



37
38
39
# File 'lib/ledger_sync/test/support/test_ledger/webhook_notification.rb', line 37

def resources
  @resources ||= events.map(&:resource).compact
end