Sha256: fc77afbbd3b9f00b22fbd2327857b70c0ef479251663290cfbd52a33f0a97861

Contents?: true

Size: 1.32 KB

Versions: 8

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

require_relative '../operation'

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

          def request_params
            super.merge({ expandSubResources: true })
          end

          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 ||= client.get(
              path: ledger_resource_path
            )
          end

          def success
            super(
              resource: deserializer.deserialize(hash: response.body, resource: resource),
              response: response
            )
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ledger_sync-1.6.0 lib/ledger_sync/ledgers/netsuite/operation/find.rb
ledger_sync-1.5.2 lib/ledger_sync/ledgers/netsuite/operation/find.rb
ledger_sync-1.5.1 lib/ledger_sync/ledgers/netsuite/operation/find.rb
ledger_sync-1.5.0 lib/ledger_sync/ledgers/netsuite/operation/find.rb
ledger_sync-1.4.4 lib/ledger_sync/ledgers/netsuite/operation/find.rb
ledger_sync-1.4.2 lib/ledger_sync/ledgers/netsuite/operation/find.rb
ledger_sync-1.4.1 lib/ledger_sync/ledgers/netsuite/operation/find.rb
ledger_sync-1.4.0 lib/ledger_sync/ledgers/netsuite/operation/find.rb