Sha256: de11b29afc33239b6119f02bba0681af055bf8c605f8e0e9754e324bbfb3f822

Contents?: true

Size: 979 Bytes

Versions: 7

Compression:

Stored size: 979 Bytes

Contents

# frozen_string_literal: true

require_relative '../operation'

module Desertcart
  class Operation
    class Update
      include Desertcart::Operation::Mixin

      private

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

        fail(response.status)
      end

      def operate
        update_in_ledger
          .and_then { success }
      end

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

      def success
        super(
          resource: deserialized_resource,
          response: response
        )
      end

      def fail(status)
        failure(
          LedgerSync::Error::OperationError.new(
            operation: self,
            response: response,
            message: "Status code: #{status}"
          ),
          resource: @resource
        )
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
desertcart-1.1.5 lib/desertcart/operation/update.rb
desertcart-1.1.4 lib/desertcart/operation/update.rb
desertcart-1.1.3 lib/desertcart/operation/update.rb
desertcart-1.1.2 lib/desertcart/operation/update.rb
desertcart-1.1.1 lib/desertcart/operation/update.rb
desertcart-1.1.0 lib/desertcart/operation/update.rb
desertcart-1.0.0 lib/desertcart/operation/update.rb