class SpookAndPay::Result

A small convenience class which wraps any results coming back from a provider. This is never instanced directly, but instead instances are created by the Provider classes.

Attributes

credit_card[R]

Readers for the various portions of a result's payload. Depending on the type of request any of these may be nil.

errors[R]

Readers for the various portions of a result's payload. Depending on the type of request any of these may be nil.

raw[R]

Readers for the various portions of a result's payload. Depending on the type of request any of these may be nil.

transaction[R]

Readers for the various portions of a result's payload. Depending on the type of request any of these may be nil.

Public Class Methods

new(successful, raw, opts = {}) click to toggle source

@param [true, false] successful @param Class raw @param Hash opts

# File lib/spook_and_pay/result.rb, line 13
def initialize(successful, raw, opts = {})
  @successful   = successful
  @raw          = raw
  @transaction  = opts[:transaction] if opts.has_key?(:transaction)
  @credit_card  = opts[:credit_card] if opts.has_key?(:credit_card)
  @errors       = opts[:errors] || []
end

Public Instance Methods

credit_card?() click to toggle source

Checks to see if a credit card is present.

@return [true, false]

# File lib/spook_and_pay/result.rb, line 31
def credit_card?
  !credit_card.nil?
end
errors?() click to toggle source

Checks to see if any errors are present.

@return [true, false]

# File lib/spook_and_pay/result.rb, line 38
def errors?
  !errors.empty?
end
errors_for(target) click to toggle source

Collects errors for a specific target, keyed by field.

@param Symbol target @return Hash @return Hash<Symbol, Array<SpookAndPay::SubmissionError>>

# File lib/spook_and_pay/result.rb, line 47
def errors_for(target)
  errors.select{|e| e.target == target}.reduce({}) do |h, e|
    h[e.field] ||= []
    h[e.field] << e
    h
  end
end
errors_for_field(target, field) click to toggle source

Returns the errors for a specific target and field.

@param Symbol target @param Symbol field @return Array<SpookAndPay::SubmissionError>

# File lib/spook_and_pay/result.rb, line 60
def errors_for_field(target, field)
  errors.select {|e| e.target == target and e.field == field}
end
failure?() click to toggle source

A nice helper for checking for failure.

@return [true, false]

# File lib/spook_and_pay/result.rb, line 74
def failure?
  !@successful
end
successful?() click to toggle source

A nice alias for checking for success.

@return [true, false]

# File lib/spook_and_pay/result.rb, line 67
def successful?
  @successful
end
transaction?() click to toggle source

Checks to see if a transaction is present.

@return [true, false]

# File lib/spook_and_pay/result.rb, line 24
def transaction?
  !transaction.nil?
end