Sha256: d66eb18a436ae6688188a4cab473801f1c982483a1704c7fc39b557cb2ac4186

Contents?: true

Size: 1.7 KB

Versions: 2

Compression:

Stored size: 1.7 KB

Contents

  # frozen_string_literal: true

module LedgerSync
  module Adaptors
    module QuickBooksOnline
      module Operation
        module Mixin
          def self.included(base)
            base.include Adaptors::Operation::Mixin
            base.include InstanceMethods # To ensure these override parent methods
          end

          module InstanceMethods
            def deserialized_resource(response:)
              ledger_serializer.deserialize(
                hash: response.body.dig(
                  quickbooks_online_resource_type.to_s.camelize
                )
              )
            end

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

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

            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

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

            def quickbooks_online_resource_type
              @quickbooks_online_resource_type ||= ledger_serializer.class.quickbooks_online_resource_type
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ledger_sync-1.3.5 lib/ledger_sync/adaptors/quickbooks_online/operation.rb
ledger_sync-1.3.4 lib/ledger_sync/adaptors/quickbooks_online/operation.rb