Sha256: bb1cc29fdb3f7ee0d69d460e9e9470e9a703e9239b7936c054f87f1f35ea2b40

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

module ShipCompliant
  # == ShipCompliant::BaseResult
  #
  # This class provides methods to are relevant to every
  # API request. All requests made through the
  # ShipCompliant API client include these methods.
  module BaseResult

    # Returns boolean whether order was successfully voided.
    #
    #   puts "SUCCESS" if result.success?
    def success?
      response[:response_status] == "Success"
    end

    # Returns true if order failed to be voided.
    #
    #   puts "FAILED" if result.failure?
    def failure?
      !success?
    end

    # An array of +ErrorResult+ items or an empty array if the response was
    # successful.
    #
    #   result.errors.each do |error|
    #     puts "#{error.message} [#error.key]"
    #   end
    def errors
      return [] if success?
      @errors ||= Array.wrap(response[:errors]).map do |error|
        ErrorResult.new(error[:error])
      end
    end

    # The number of errors in the response.
    def errors_count
      errors.length
    end
    alias_method :error_count, :errors_count

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ship_compliant-0.2.1 lib/ship_compliant/base_result.rb
ship_compliant-0.2.0 lib/ship_compliant/base_result.rb
ship_compliant-0.1.2 lib/ship_compliant/base_result.rb
ship_compliant-0.1.1 lib/ship_compliant/base_result.rb
ship_compliant-0.1.0 lib/ship_compliant/base_result.rb