Class: Soap::Webservice::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/soap/webservice/response.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



16
17
18
19
20
21
22
# File 'lib/soap/webservice/response.rb', line 16

def initialize(response)
  @response = response
  @errors = []

  validate_errors!
  validate_body_attrs!
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



14
15
16
# File 'lib/soap/webservice/response.rb', line 14

def errors
  @errors
end

#responseObject (readonly)

Returns the value of attribute response.



13
14
15
# File 'lib/soap/webservice/response.rb', line 13

def response
  @response
end

Class Method Details

.body_attributesObject



10
# File 'lib/soap/webservice/response.rb', line 10

def body_attributes; {} end

.header_attributesObject



8
# File 'lib/soap/webservice/response.rb', line 8

def header_attributes; {} end

Instance Method Details

#bodyObject



52
53
54
# File 'lib/soap/webservice/response.rb', line 52

def body
  response.body
end

#decoded_bodyObject



56
57
58
# File 'lib/soap/webservice/response.rb', line 56

def decoded_body
  response.body
end

#headerObject



48
49
50
# File 'lib/soap/webservice/response.rb', line 48

def header
  response.header
end

#to_xmlObject



60
61
62
# File 'lib/soap/webservice/response.rb', line 60

def to_xml
  response.to_xml
end

#validate_body_attrs!Object

rubocop:enable all



37
38
39
40
41
42
43
44
45
46
# File 'lib/soap/webservice/response.rb', line 37

def validate_body_attrs!
  return if required_body.empty?
  if !required_body.empty? && attributes.empty?
    raise "Required attributes are missing #{required_body}"
  end

  if !(required_body - attributes.keys).empty?
    raise "Attribute #{required_body - attributes.keys} must be present"
  end
end

#validate_errors!Object

rubocop:disable all



25
26
27
28
29
30
31
32
33
34
# File 'lib/soap/webservice/response.rb', line 25

def validate_errors!
  case response.http.code
  when 200
    errors << Soap::Webservice::FaultError.new(response)
  when 500
    errors << Soap::Webservice::Error.new(response)
  else
    errors << Soap::Webservice::GenericError.new(response)
  end
end