Sha256: 3be8d5142e9887b40fece20dcba286bbc90a6da742f5275515819d5e48c227d9

Contents?: true

Size: 1.43 KB

Versions: 15

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require_relative '../operation'

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

        def request_params
          return super unless expand_sub_resources?

          super.merge({ expandSubResources: expand_sub_resources? })
        end

        def expand_sub_resources?
          self.class.expand_sub_resources?
        end

        def self.expand_sub_resources?
          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

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
ledger_sync-netsuite-0.7.1 lib/ledger_sync/netsuite/operation/find.rb
ledger_sync-netsuite-0.6.2 lib/ledger_sync/netsuite/operation/find.rb
ledger_sync-netsuite-0.6.1 lib/ledger_sync/netsuite/operation/find.rb
ledger_sync-netsuite-0.6.0 lib/ledger_sync/netsuite/operation/find.rb
ledger_sync-netsuite-0.5.0 lib/ledger_sync/netsuite/operation/find.rb
ledger_sync-netsuite-0.4.2 lib/ledger_sync/netsuite/operation/find.rb
ledger_sync-netsuite-0.3.6 lib/ledger_sync/netsuite/operation/find.rb
ledger_sync-netsuite-0.3.5 lib/ledger_sync/netsuite/operation/find.rb
ledger_sync-netsuite-0.3.4 lib/ledger_sync/netsuite/operation/find.rb
ledger_sync-netsuite-0.3.3 lib/ledger_sync/netsuite/operation/find.rb
ledger_sync-netsuite-0.3.2 lib/ledger_sync/netsuite/operation/find.rb
ledger_sync-netsuite-0.3.1 lib/ledger_sync/netsuite/operation/find.rb
ledger_sync-netsuite-0.3.0 lib/ledger_sync/netsuite/operation/find.rb
ledger_sync-netsuite-0.2.0 lib/ledger_sync/netsuite/operation/find.rb
ledger_sync-netsuite-0.1.1 lib/ledger_sync/netsuite/operation/find.rb