Sha256: 12642231c36d47a7a16f673576b52bb960b78ba73f33501a0475f041ade95fe8

Contents?: true

Size: 1.25 KB

Versions: 5

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

require_relative '../operation'

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

          private

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

          def operate
            find_in_ledger
              .and_then { success }
          end

          def response
            @response ||= adaptor.get(
              path: ledger_serializer.class.api_resource_path(resource: resource)
            )
          end

          def success
            super(
              resource: ledger_deserializer.deserialize(hash: response.body),
              response: response
            )
          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/find.rb
ledger_sync-1.3.4 lib/ledger_sync/adaptors/netsuite/operation/find.rb
ledger_sync-1.3.3 lib/ledger_sync/adaptors/netsuite/operation/find.rb
ledger_sync-1.3.2 lib/ledger_sync/adaptors/netsuite/operation/find.rb
ledger_sync-1.3.1 lib/ledger_sync/adaptors/netsuite/operation/find.rb