Class: LedgerSync::QuickBooksOnline::WebhookNotification
- Inherits:
-
Object
- Object
- LedgerSync::QuickBooksOnline::WebhookNotification
- Defined in:
- lib/ledger_sync/quickbooks_online/webhook_notification.rb
Instance Attribute Summary collapse
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#original_payload ⇒ Object
readonly
Returns the value of attribute original_payload.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#realm_id ⇒ Object
readonly
Returns the value of attribute realm_id.
-
#webhook ⇒ Object
readonly
Returns the value of attribute webhook.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ WebhookNotification
constructor
A new instance of WebhookNotification.
- #resources ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ WebhookNotification
Returns a new instance of WebhookNotification.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ledger_sync/quickbooks_online/webhook_notification.rb', line 15 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
#events ⇒ Object (readonly)
Returns the value of attribute events.
9 10 11 |
# File 'lib/ledger_sync/quickbooks_online/webhook_notification.rb', line 9 def events @events end |
#original_payload ⇒ Object (readonly)
Returns the value of attribute original_payload.
9 10 11 |
# File 'lib/ledger_sync/quickbooks_online/webhook_notification.rb', line 9 def original_payload @original_payload end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
9 10 11 |
# File 'lib/ledger_sync/quickbooks_online/webhook_notification.rb', line 9 def payload @payload end |
#realm_id ⇒ Object (readonly)
Returns the value of attribute realm_id.
9 10 11 |
# File 'lib/ledger_sync/quickbooks_online/webhook_notification.rb', line 9 def realm_id @realm_id end |
#webhook ⇒ Object (readonly)
Returns the value of attribute webhook.
9 10 11 |
# File 'lib/ledger_sync/quickbooks_online/webhook_notification.rb', line 9 def webhook @webhook end |
Instance Method Details
#resources ⇒ Object
36 37 38 |
# File 'lib/ledger_sync/quickbooks_online/webhook_notification.rb', line 36 def resources @resources ||= events.map(&:resource).compact end |