Module: LedgerSync::Ledgers::QuickBooksOnline::Operation::Mixin::InstanceMethods

Defined in:
lib/ledger_sync/ledgers/quickbooks_online/operation.rb

Instance Method Summary collapse

Instance Method Details

#deserialized_resource(response:) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/ledger_sync/ledgers/quickbooks_online/operation.rb', line 14

def deserialized_resource(response:)
  deserializer.deserialize(
    hash: response.body.dig(
      quickbooks_online_resource_type.to_s.camelize
    ),
    resource: resource
  )
end

#ledger_resource_pathObject



23
24
25
# File 'lib/ledger_sync/ledgers/quickbooks_online/operation.rb', line 23

def ledger_resource_path
  @ledger_resource_path ||= "#{ledger_resource_type_for_path}/#{resource.ledger_id}"
end

#ledger_resource_type_for_pathObject



27
28
29
# File 'lib/ledger_sync/ledgers/quickbooks_online/operation.rb', line 27

def ledger_resource_type_for_path
  quickbooks_online_resource_type.tr('_', '')
end

#performObject



47
48
49
50
51
# File 'lib/ledger_sync/ledgers/quickbooks_online/operation.rb', line 47

def perform
  super
rescue LedgerSync::Error::OperationError, OAuth2::Error => e
  failure(e)
end

#quickbooks_online_resource_typeObject



53
54
55
# File 'lib/ledger_sync/ledgers/quickbooks_online/operation.rb', line 53

def quickbooks_online_resource_type
  @quickbooks_online_resource_type ||= client.class.ledger_resource_type_for(resource_class: resource.class)
end

#response_to_operation_result(response:) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ledger_sync/ledgers/quickbooks_online/operation.rb', line 31

def response_to_operation_result(response:)
  if response.success?
    success(
      resource: deserialized_resource(response: response),
      response: response
    )
  else
    failure(
      Error::OperationError.new(
        operation: self,
        response: response
      )
    )
  end
end