Class: LedgerSync::Ledgers::TestLedger::WebhookEvent
- Inherits:
-
Object
- Object
- LedgerSync::Ledgers::TestLedger::WebhookEvent
- Defined in:
- lib/ledger_sync/test/support/test_ledger/webhook_event.rb
Instance Attribute Summary collapse
-
#deleted_id ⇒ Object
readonly
Returns the value of attribute deleted_id.
-
#event_operation ⇒ Object
readonly
Returns the value of attribute event_operation.
-
#last_updated_at ⇒ Object
readonly
Returns the value of attribute last_updated_at.
-
#ledger_id ⇒ Object
readonly
Returns the value of attribute ledger_id.
-
#original_payload ⇒ Object
readonly
Returns the value of attribute original_payload.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#test_ledger_resource_type ⇒ Object
readonly
Returns the value of attribute test_ledger_resource_type.
-
#webhook ⇒ Object
readonly
Returns the value of attribute webhook.
-
#webhook_notification ⇒ Object
readonly
Returns the value of attribute webhook_notification.
Instance Method Summary collapse
- #find(client:) ⇒ Object
- #find_operation(client:) ⇒ Object
- #find_operation_class(client:) ⇒ Object
-
#initialize(payload:, webhook_notification: nil) ⇒ WebhookEvent
constructor
A new instance of WebhookEvent.
- #local_resource_type ⇒ Object
- #resource ⇒ Object
- #resource! ⇒ Object
- #resource_class ⇒ Object
Constructor Details
#initialize(payload:, webhook_notification: nil) ⇒ WebhookEvent
Returns a new instance of WebhookEvent.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ledger_sync/test/support/test_ledger/webhook_event.rb', line 18 def initialize(payload:, webhook_notification: nil) @original_payload = payload @payload = payload.is_a?(String) ? JSON.parse(payload) : payload @deleted_id = @payload['deletedId'] @event_operation = @payload['operation'] raise 'Invalid payload: Could not find operation' if @event_operation.blank? @last_updated_at = @payload['lastUpdated'] raise 'Invalid payload: Could not find lastUpdated' if @last_updated_at.blank? @last_updated_at = Time.parse(@last_updated_at) @ledger_id = @payload['id'] raise 'Invalid payload: Could not find id' if @ledger_id.blank? @test_ledger_resource_type = @payload['name'] raise 'Invalid payload: Could not find name' if @test_ledger_resource_type.blank? @webhook_notification = webhook_notification @webhook = webhook_notification.try(:webhook) end |
Instance Attribute Details
#deleted_id ⇒ Object (readonly)
Returns the value of attribute deleted_id.
8 9 10 |
# File 'lib/ledger_sync/test/support/test_ledger/webhook_event.rb', line 8 def deleted_id @deleted_id end |
#event_operation ⇒ Object (readonly)
Returns the value of attribute event_operation.
8 9 10 |
# File 'lib/ledger_sync/test/support/test_ledger/webhook_event.rb', line 8 def event_operation @event_operation end |
#last_updated_at ⇒ Object (readonly)
Returns the value of attribute last_updated_at.
8 9 10 |
# File 'lib/ledger_sync/test/support/test_ledger/webhook_event.rb', line 8 def last_updated_at @last_updated_at end |
#ledger_id ⇒ Object (readonly)
Returns the value of attribute ledger_id.
8 9 10 |
# File 'lib/ledger_sync/test/support/test_ledger/webhook_event.rb', line 8 def ledger_id @ledger_id end |
#original_payload ⇒ Object (readonly)
Returns the value of attribute original_payload.
8 9 10 |
# File 'lib/ledger_sync/test/support/test_ledger/webhook_event.rb', line 8 def original_payload @original_payload end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
8 9 10 |
# File 'lib/ledger_sync/test/support/test_ledger/webhook_event.rb', line 8 def payload @payload end |
#test_ledger_resource_type ⇒ Object (readonly)
Returns the value of attribute test_ledger_resource_type.
8 9 10 |
# File 'lib/ledger_sync/test/support/test_ledger/webhook_event.rb', line 8 def test_ledger_resource_type @test_ledger_resource_type end |
#webhook ⇒ Object (readonly)
Returns the value of attribute webhook.
8 9 10 |
# File 'lib/ledger_sync/test/support/test_ledger/webhook_event.rb', line 8 def webhook @webhook end |
#webhook_notification ⇒ Object (readonly)
Returns the value of attribute webhook_notification.
8 9 10 |
# File 'lib/ledger_sync/test/support/test_ledger/webhook_event.rb', line 8 def webhook_notification @webhook_notification end |
Instance Method Details
#find(client:) ⇒ Object
42 43 44 |
# File 'lib/ledger_sync/test/support/test_ledger/webhook_event.rb', line 42 def find(client:) find_operation(client: client).perform end |
#find_operation(client:) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/ledger_sync/test/support/test_ledger/webhook_event.rb', line 46 def find_operation(client:) find_operation_class(client: client).new( client: client, resource: resource_class.new(ledger_id: ledger_id) ) end |
#find_operation_class(client:) ⇒ Object
53 54 55 |
# File 'lib/ledger_sync/test/support/test_ledger/webhook_event.rb', line 53 def find_operation_class(client:) client.class.base_operations_module_for(resource_class: resource_class)::Find end |
#local_resource_type ⇒ Object
57 58 59 |
# File 'lib/ledger_sync/test/support/test_ledger/webhook_event.rb', line 57 def local_resource_type @local_resource_type ||= resource_class.resource_type end |
#resource ⇒ Object
61 62 63 64 65 |
# File 'lib/ledger_sync/test/support/test_ledger/webhook_event.rb', line 61 def resource return unless resource_class.present? resource_class.new(ledger_id: ledger_id) end |
#resource! ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/ledger_sync/test/support/test_ledger/webhook_event.rb', line 67 def resource! if resource.nil? raise "Resource class does not exist for QuickBooks Online object: #{test_ledger_resource_type}" end resource end |
#resource_class ⇒ Object
75 76 77 |
# File 'lib/ledger_sync/test/support/test_ledger/webhook_event.rb', line 75 def resource_class @resource_class ||= Client.resource_from_ledger_type(type: test_ledger_resource_type.downcase) end |