smacks-savon 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +6 -6
- data/lib/savon/response.rb +14 -14
- data/test/savon/response_test.rb +18 -18
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -23,8 +23,8 @@ Instantiate a new Savon::Service instance passing in the WSDL of your service.
|
|
23
23
|
|
24
24
|
proxy = Savon::Service.new "http://example.com/ExampleService?wsdl"
|
25
25
|
|
26
|
-
Call the SOAP service method
|
27
|
-
|
26
|
+
Call the SOAP service method of your choice on your Savon::Service instance
|
27
|
+
passing in a Hash of options for the service method to receive.
|
28
28
|
|
29
29
|
response = proxy.findExampleById(:id => 123)
|
30
30
|
|
@@ -41,12 +41,12 @@ instance to get a list of available SOAP service methods.
|
|
41
41
|
Check if the SOAP request was successful.
|
42
42
|
|
43
43
|
response.success?
|
44
|
-
response.
|
44
|
+
response.error?
|
45
45
|
|
46
|
-
Access
|
46
|
+
Access error message and code in case a request was not successful.
|
47
47
|
|
48
|
-
response.
|
49
|
-
response.
|
48
|
+
response.error_message
|
49
|
+
response.error_code
|
50
50
|
|
51
51
|
=== Different response formats
|
52
52
|
|
data/lib/savon/response.rb
CHANGED
@@ -7,11 +7,11 @@ module Savon
|
|
7
7
|
# Savon::Response represents the HTTP response.
|
8
8
|
class Response
|
9
9
|
|
10
|
-
# The HTTP or SOAP fault message.
|
11
|
-
attr_reader :
|
10
|
+
# The HTTP error or SOAP fault message.
|
11
|
+
attr_reader :error_message
|
12
12
|
|
13
|
-
# The HTTP or SOAP fault code.
|
14
|
-
attr_reader :
|
13
|
+
# The HTTP error or SOAP fault code.
|
14
|
+
attr_reader :error_code
|
15
15
|
|
16
16
|
# Initializer expects the HTTP response and checks for HTTP or SOAP faults.
|
17
17
|
#
|
@@ -25,12 +25,12 @@ module Savon
|
|
25
25
|
|
26
26
|
# Returns true if the request was successful, false otherwise.
|
27
27
|
def success?
|
28
|
-
@
|
28
|
+
@error_code.nil?
|
29
29
|
end
|
30
30
|
|
31
31
|
# Returns true if there was a HTTP or SOAP fault, false otherwise.
|
32
|
-
def
|
33
|
-
!@
|
32
|
+
def error?
|
33
|
+
!@error_code.nil?
|
34
34
|
end
|
35
35
|
|
36
36
|
# Returns the SOAP response message as a Hash. Call with XPath expession
|
@@ -41,7 +41,7 @@ module Savon
|
|
41
41
|
#
|
42
42
|
# * +root_node+ - Optional. Custom root node to start parsing at.
|
43
43
|
def to_hash(root_node = "//return")
|
44
|
-
return nil if
|
44
|
+
return nil if error?
|
45
45
|
ApricotEatsGorilla[@response.body, root_node]
|
46
46
|
end
|
47
47
|
|
@@ -53,7 +53,7 @@ module Savon
|
|
53
53
|
#
|
54
54
|
# * +root_node+ - Optional. Custom root node to start parsing at.
|
55
55
|
def to_mash(root_node = "//return")
|
56
|
-
return nil if
|
56
|
+
return nil if error?
|
57
57
|
hash = to_hash(root_node)
|
58
58
|
Savon::Mash.new(hash)
|
59
59
|
end
|
@@ -65,14 +65,14 @@ module Savon
|
|
65
65
|
|
66
66
|
private
|
67
67
|
|
68
|
-
# Checks for HTTP and SOAP faults.
|
68
|
+
# Checks for HTTP errors and SOAP faults.
|
69
69
|
def validate
|
70
70
|
if @response.code.to_i >= 300
|
71
|
-
@
|
71
|
+
@error_message, @error_code = @response.message, @response.code
|
72
72
|
else
|
73
|
-
|
74
|
-
@
|
75
|
-
@
|
73
|
+
soap_fault = to_hash("//soap:Fault")
|
74
|
+
@error_message = soap_fault[:faultstring] unless soap_fault.nil?
|
75
|
+
@error_code = soap_fault[:faultcode] unless soap_fault.nil?
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
data/test/savon/response_test.rb
CHANGED
@@ -35,16 +35,16 @@ class SavonResponseTest < Test::Unit::TestCase
|
|
35
35
|
assert_equal true, @response.success?
|
36
36
|
end
|
37
37
|
|
38
|
-
should "return 'false' on
|
39
|
-
assert_equal false, @response.
|
38
|
+
should "return 'false' on error?" do
|
39
|
+
assert_equal false, @response.error?
|
40
40
|
end
|
41
41
|
|
42
|
-
should "return 'nil' for
|
43
|
-
assert_equal nil, @response.
|
42
|
+
should "return 'nil' for error_message" do
|
43
|
+
assert_equal nil, @response.error_message
|
44
44
|
end
|
45
45
|
|
46
|
-
should "return 'nil' for
|
47
|
-
assert_equal nil, @response.
|
46
|
+
should "return 'nil' for error_code" do
|
47
|
+
assert_equal nil, @response.error_code
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -70,16 +70,16 @@ class SavonResponseTest < Test::Unit::TestCase
|
|
70
70
|
assert_equal false, @response.success?
|
71
71
|
end
|
72
72
|
|
73
|
-
should "return 'true' on
|
74
|
-
assert_equal true, @response.
|
73
|
+
should "return 'true' on error?" do
|
74
|
+
assert_equal true, @response.error?
|
75
75
|
end
|
76
76
|
|
77
|
-
should "return the
|
78
|
-
assert_equal soap_fault, @response.
|
77
|
+
should "return the error message on error_message" do
|
78
|
+
assert_equal soap_fault, @response.error_message
|
79
79
|
end
|
80
80
|
|
81
|
-
should "return the
|
82
|
-
assert_equal soap_fault_code, @response.
|
81
|
+
should "return the error code on error_code" do
|
82
|
+
assert_equal soap_fault_code, @response.error_code
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
@@ -105,16 +105,16 @@ class SavonResponseTest < Test::Unit::TestCase
|
|
105
105
|
assert_equal false, @response.success?
|
106
106
|
end
|
107
107
|
|
108
|
-
should "return 'true' on
|
109
|
-
assert_equal true, @response.
|
108
|
+
should "return 'true' on error?" do
|
109
|
+
assert_equal true, @response.error?
|
110
110
|
end
|
111
111
|
|
112
|
-
should "return the
|
113
|
-
assert_equal "NotFound", @response.
|
112
|
+
should "return the error message on error_message" do
|
113
|
+
assert_equal "NotFound", @response.error_message
|
114
114
|
end
|
115
115
|
|
116
|
-
should "return the
|
117
|
-
assert_equal "404", @response.
|
116
|
+
should "return the error code on error_code" do
|
117
|
+
assert_equal "404", @response.error_code
|
118
118
|
end
|
119
119
|
|
120
120
|
end
|