Class: LedgerSync::QuickBooksOnline::WebhookEvent
- Inherits:
-
Object
- Object
- LedgerSync::QuickBooksOnline::WebhookEvent
- Defined in:
- lib/ledger_sync/quickbooks_online/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.
-
#quickbooks_online_resource_type ⇒ Object
readonly
Returns the value of attribute quickbooks_online_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.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ledger_sync/quickbooks_online/webhook_event.rb', line 17 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? @quickbooks_online_resource_type = @payload['name'] raise 'Invalid payload: Could not find name' if @quickbooks_online_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.
7 8 9 |
# File 'lib/ledger_sync/quickbooks_online/webhook_event.rb', line 7 def deleted_id @deleted_id end |
#event_operation ⇒ Object (readonly)
Returns the value of attribute event_operation.
7 8 9 |
# File 'lib/ledger_sync/quickbooks_online/webhook_event.rb', line 7 def event_operation @event_operation end |
#last_updated_at ⇒ Object (readonly)
Returns the value of attribute last_updated_at.
7 8 9 |
# File 'lib/ledger_sync/quickbooks_online/webhook_event.rb', line 7 def last_updated_at @last_updated_at end |
#ledger_id ⇒ Object (readonly)
Returns the value of attribute ledger_id.
7 8 9 |
# File 'lib/ledger_sync/quickbooks_online/webhook_event.rb', line 7 def ledger_id @ledger_id end |
#original_payload ⇒ Object (readonly)
Returns the value of attribute original_payload.
7 8 9 |
# File 'lib/ledger_sync/quickbooks_online/webhook_event.rb', line 7 def original_payload @original_payload end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
7 8 9 |
# File 'lib/ledger_sync/quickbooks_online/webhook_event.rb', line 7 def payload @payload end |
#quickbooks_online_resource_type ⇒ Object (readonly)
Returns the value of attribute quickbooks_online_resource_type.
7 8 9 |
# File 'lib/ledger_sync/quickbooks_online/webhook_event.rb', line 7 def quickbooks_online_resource_type @quickbooks_online_resource_type end |
#webhook ⇒ Object (readonly)
Returns the value of attribute webhook.
7 8 9 |
# File 'lib/ledger_sync/quickbooks_online/webhook_event.rb', line 7 def webhook @webhook end |
#webhook_notification ⇒ Object (readonly)
Returns the value of attribute webhook_notification.
7 8 9 |
# File 'lib/ledger_sync/quickbooks_online/webhook_event.rb', line 7 def webhook_notification @webhook_notification end |
Instance Method Details
#find(client:) ⇒ Object
41 42 43 |
# File 'lib/ledger_sync/quickbooks_online/webhook_event.rb', line 41 def find(client:) find_operation(client: client).perform end |
#find_operation(client:) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/ledger_sync/quickbooks_online/webhook_event.rb', line 45 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
52 53 54 |
# File 'lib/ledger_sync/quickbooks_online/webhook_event.rb', line 52 def find_operation_class(client:) client.class.base_operations_module_for(resource_class: resource_class)::Find end |
#local_resource_type ⇒ Object
56 57 58 |
# File 'lib/ledger_sync/quickbooks_online/webhook_event.rb', line 56 def local_resource_type @local_resource_type ||= resource_class.resource_type end |
#resource ⇒ Object
60 61 62 63 64 |
# File 'lib/ledger_sync/quickbooks_online/webhook_event.rb', line 60 def resource return unless resource_class.present? resource_class.new(ledger_id: ledger_id) end |
#resource! ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/ledger_sync/quickbooks_online/webhook_event.rb', line 66 def resource! if resource.nil? raise "Resource class does not exist for QuickBooks Online object: #{quickbooks_online_resource_type}" end resource end |
#resource_class ⇒ Object
74 75 76 |
# File 'lib/ledger_sync/quickbooks_online/webhook_event.rb', line 74 def resource_class @resource_class ||= Client.resource_from_ledger_type(type: quickbooks_online_resource_type.downcase) end |