Sha256: 3e6b2bf2ad9f927d6d4f0d28b592dc04760e508ab6d8394880e20fcc9fd79cf3

Contents?: true

Size: 1.55 KB

Versions: 5

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

require_relative '../operation'

module LedgerSync
  module Adaptors
    module NetSuite
      module Operation
        class Update
          include NetSuite::Operation::Mixin

          private

          def update_in_ledger
            case response.status
            when 200..299
              LedgerSync::Result.Success(response)
            else
              failure(
                Error::OperationError.new(
                  operation: self,
                  response: response
                )
              )
            end
          end

          def find
            resource.ledger_id = ledger_id

            self.class.operations_module::Find.new(
              adaptor: adaptor,
              resource: resource
            ).perform
          end

          def ledger_id
            @ledger_id ||= response.headers['Location'].split('/').last
          end

          def operate
            update_in_ledger
              .and_then { success }
          end

          def response
            ledger_hash = ledger_serializer.to_ledger_hash
            ledger_hash.delete('entityId')

            @response ||= adaptor.patch(
              body: ledger_hash,
              path: ledger_serializer.class.api_resource_path(resource: resource)
            )
          end

          def success
            find.and_then do |find_result|
              super(
                resource: find_result.resource,
                response: response
              )
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ledger_sync-1.3.5 lib/ledger_sync/adaptors/netsuite/operation/update.rb
ledger_sync-1.3.4 lib/ledger_sync/adaptors/netsuite/operation/update.rb
ledger_sync-1.3.3 lib/ledger_sync/adaptors/netsuite/operation/update.rb
ledger_sync-1.3.2 lib/ledger_sync/adaptors/netsuite/operation/update.rb
ledger_sync-1.3.1 lib/ledger_sync/adaptors/netsuite/operation/update.rb