class TransactPro::Response

Attributes

body[R]

Public Class Methods

new(body) click to toggle source
# File lib/transact_pro/response.rb, line 4
def initialize(body)
  @body = body
end

Public Instance Methods

status() click to toggle source
# File lib/transact_pro/response.rb, line 30
def status
  status_portion = body.split("~").detect do |portion|
    portion[%r'\A(OK)|(Status)\:']
  end

  if status_portion.to_s[%r'\AOK']
    "OK"
  elsif status_portion.to_s[%r'\AStatus']
    status = status_portion.match(%r'\AStatus:(.*)')[1]
    status == "Success" ? "OK" : "FAIL"
  else
    "ERROR"
  end
end
tid() click to toggle source
# File lib/transact_pro/response.rb, line 45
def tid
  tid_portion = body.split("~").detect do |portion|
    portion[%r'\AOK\:']
  end

  tid_portion.nil? ?
    nil :
    tid_portion.match(%r'\A(.*?)\:(.*)')[2]
end
to_h() click to toggle source
# File lib/transact_pro/response.rb, line 12
def to_h
  @to_h ||= body.split("~").inject({}) do |mem, portion|
    match = portion.match(%r'\A([^\:]+?)\:(.*)')
    mem[match[1]] = match[2]
    mem
  end
end
to_s() click to toggle source
# File lib/transact_pro/response.rb, line 8
def to_s
  body
end