class Paypal::Masspay::ResponseParser

Constants

SUCCESSFUL_ACKS
SUCCESS_ACK
SUCCESS_WITH_WARN_ACK

Public Class Methods

new(response_body) click to toggle source
# File lib/paypal/masspay/response_parser.rb, line 10
def initialize(response_body)
  @response_body = response_body
  @errors = []
end

Public Instance Methods

errors() click to toggle source
# File lib/paypal/masspay/response_parser.rb, line 19
def errors
  @errors.tap do |errors|
    parsed_response.select { |k, v| k.match(/^L_ERRORCODE\d+$/) }.keys.count.times do |i|
      errors << Paypal::Masspay::Error.new(
        :code          => error_code_for(i),
        :short_message => short_message_for(i),
        :long_message  => long_message_for(i),
        :severity      => severity_for(i))
    end
  end
end
successful?() click to toggle source
# File lib/paypal/masspay/response_parser.rb, line 15
def successful?
  SUCCESSFUL_ACKS.include?(ack)
end

Private Instance Methods

ack() click to toggle source
# File lib/paypal/masspay/response_parser.rb, line 42
def ack
  parsed_response["ACK"]
end
error_code_for(index) click to toggle source
# File lib/paypal/masspay/response_parser.rb, line 46
def error_code_for(index)
  parsed_response["L_ERRORCODE#{index}"].to_i
end
long_message_for(index) click to toggle source
# File lib/paypal/masspay/response_parser.rb, line 54
def long_message_for(index)
  parsed_response["L_LONGMESSAGE#{index}"]
end
parsed_response() click to toggle source
# File lib/paypal/masspay/response_parser.rb, line 33
def parsed_response
  if @parsed_response.nil?
    @parsed_response = CGI::parse(@response_body)
    @parsed_response.each { |key, value| @parsed_response[key] = value.first }
  end

  @parsed_response
end
severity_for(index) click to toggle source
# File lib/paypal/masspay/response_parser.rb, line 58
def severity_for(index)
  parsed_response["L_SEVERITYCODE#{index}"]
end
short_message_for(index) click to toggle source
# File lib/paypal/masspay/response_parser.rb, line 50
def short_message_for(index)
  parsed_response["L_SHORTMESSAGE#{index}"]
end