Sha256: 2f4abfe7ba88040dab35cd26e4b435cc8b8f5a5496b6e53aff844951bcd5fede

Contents?: true

Size: 1.15 KB

Versions: 15

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require_relative '../operation'

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

        private

        def create_in_ledger
          return LedgerSync::Result.Success(response) if response.success?

          failure(
            Error::OperationError.new(
              operation: self,
              response: response
            )
          )
        end

        def find
          resource.ledger_id = ledger_id

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

        def operate
          create_in_ledger
            .and_then { success }
        end

        def response
          @response ||= client.post(
            body: serializer.serialize(resource: resource),
            path: ledger_resource_path(id: false)
          )
        end

        def success
          find.and_then do |find_result|
            super(
              resource: find_result.resource,
              response: response
            )
          end
        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/create.rb
ledger_sync-netsuite-0.6.2 lib/ledger_sync/netsuite/operation/create.rb
ledger_sync-netsuite-0.6.1 lib/ledger_sync/netsuite/operation/create.rb
ledger_sync-netsuite-0.6.0 lib/ledger_sync/netsuite/operation/create.rb
ledger_sync-netsuite-0.5.0 lib/ledger_sync/netsuite/operation/create.rb
ledger_sync-netsuite-0.4.2 lib/ledger_sync/netsuite/operation/create.rb
ledger_sync-netsuite-0.3.6 lib/ledger_sync/netsuite/operation/create.rb
ledger_sync-netsuite-0.3.5 lib/ledger_sync/netsuite/operation/create.rb
ledger_sync-netsuite-0.3.4 lib/ledger_sync/netsuite/operation/create.rb
ledger_sync-netsuite-0.3.3 lib/ledger_sync/netsuite/operation/create.rb
ledger_sync-netsuite-0.3.2 lib/ledger_sync/netsuite/operation/create.rb
ledger_sync-netsuite-0.3.1 lib/ledger_sync/netsuite/operation/create.rb
ledger_sync-netsuite-0.3.0 lib/ledger_sync/netsuite/operation/create.rb
ledger_sync-netsuite-0.2.0 lib/ledger_sync/netsuite/operation/create.rb
ledger_sync-netsuite-0.1.1 lib/ledger_sync/netsuite/operation/create.rb