Class: SagePay::Server::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/sage_pay/server/response.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Response

Returns a new instance of Response.



61
62
63
64
65
66
67
# File 'lib/sage_pay/server/response.rb', line 61

def initialize(attributes = {})
  attributes.each do |k, v|
    # We're only providing readers, not writers, so we have to directly
    # set the instance variable.
    instance_variable_set("@#{k}", v)
  end
end

Instance Attribute Details

#statusObject (readonly)

Returns the value of attribute status.



29
30
31
# File 'lib/sage_pay/server/response.rb', line 29

def status
  @status
end

#status_detailObject (readonly)

Returns the value of attribute status_detail.



29
30
31
# File 'lib/sage_pay/server/response.rb', line 29

def status_detail
  @status_detail
end

#vps_protocolObject (readonly)

Returns the value of attribute vps_protocol.



29
30
31
# File 'lib/sage_pay/server/response.rb', line 29

def vps_protocol
  @vps_protocol
end

Class Method Details

.attr_accessor_if_ok(*attrs) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sage_pay/server/response.rb', line 31

def self.attr_accessor_if_ok(*attrs)
  attrs.each do |attr|
    define_method(attr) do
      if ok?
        instance_variable_get("@#{attr}")
      else
        raise RuntimeError, "Unable to retrieve #{attr} as the status was #{status} (not OK)."
      end
    end
  end
end

.from_response_body(response_body) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/sage_pay/server/response.rb', line 43

def self.from_response_body(response_body)
  attributes = {}

  response_body.each_line do |line|
    key, value = line.split('=', 2)
    unless key.nil? || value.nil?
      value = value.chomp

      converted_key = key_converter[key]
      converted_value = value_converter[converted_key].nil? ? value : value_converter[converted_key][value]

      attributes[converted_key] = converted_value
    end
  end

  new(attributes)
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/sage_pay/server/response.rb', line 85

def error?
  status == :error
end

#failed?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/sage_pay/server/response.rb', line 73

def failed?
  !ok?
end

#invalid?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/sage_pay/server/response.rb', line 77

def invalid?
  status == :invalid
end

#malformed?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/sage_pay/server/response.rb', line 81

def malformed?
  status == :malformed
end

#ok?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/sage_pay/server/response.rb', line 69

def ok?
  status == :ok
end