Sha256: f84818bb7b16a22b24f188d8832cf198b20a895c1145cc30d5b5ee85f488ba50

Contents?: true

Size: 1.65 KB

Versions: 13

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

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

        module InstanceMethods
          def deserialized_resource(response:)
            deserializer.deserialize(
              hash: response.body[quickbooks_online_resource_type.to_s.camelize],
              resource: resource
            )
          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)
          ensure
            client.update_secrets_in_dotenv
          end

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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ledger_sync-quickbooks_online-2.0.0 lib/ledger_sync/quickbooks_online/operation.rb
ledger_sync-quickbooks_online-1.0.1 lib/ledger_sync/quickbooks_online/operation.rb
ledger_sync-quickbooks_online-1.0.0 lib/ledger_sync/quickbooks_online/operation.rb
ledger_sync-quickbooks_online-0.4.0 lib/ledger_sync/quickbooks_online/operation.rb
ledger_sync-quickbooks_online-0.3.1 lib/ledger_sync/quickbooks_online/operation.rb
ledger_sync-quickbooks_online-0.3.0 lib/ledger_sync/quickbooks_online/operation.rb
ledger_sync-quickbooks_online-0.2.6 lib/ledger_sync/quickbooks_online/operation.rb
ledger_sync-quickbooks_online-0.2.5 lib/ledger_sync/quickbooks_online/operation.rb
ledger_sync-quickbooks_online-0.2.4 lib/ledger_sync/quickbooks_online/operation.rb
ledger_sync-quickbooks_online-0.2.2 lib/ledger_sync/quickbooks_online/operation.rb
ledger_sync-quickbooks_online-0.2.1 lib/ledger_sync/quickbooks_online/operation.rb
ledger_sync-quickbooks_online-0.2.0 lib/ledger_sync/quickbooks_online/operation.rb
ledger_sync-quickbooks_online-0.1.1 lib/ledger_sync/quickbooks_online/operation.rb