savon 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.travis.yml +2 -1
- data/CHANGELOG.md +35 -1
- data/README.md +6 -5
- data/Rakefile +3 -34
- data/lib/savon/client.rb +1 -1
- data/lib/savon/core_ext/object.rb +1 -1
- data/lib/savon/core_ext/string.rb +2 -15
- data/lib/savon/global.rb +28 -2
- data/lib/savon/soap.rb +0 -3
- data/lib/savon/soap/fault.rb +1 -1
- data/lib/savon/soap/request.rb +6 -0
- data/lib/savon/soap/response.rb +21 -12
- data/lib/savon/soap/xml.rb +7 -29
- data/lib/savon/version.rb +1 -1
- data/lib/savon/wsdl/document.rb +1 -1
- data/lib/savon/wsdl/request.rb +6 -0
- data/lib/savon/wsse.rb +16 -16
- data/savon.gemspec +6 -5
- data/spec/savon/core_ext/string_spec.rb +24 -31
- data/spec/savon/soap/request_spec.rb +14 -6
- data/spec/savon/soap/response_spec.rb +45 -15
- data/spec/savon/soap/xml_spec.rb +5 -58
- data/spec/savon/soap_spec.rb +0 -5
- data/spec/savon/wsdl/request_spec.rb +9 -1
- data/spec/savon/wsse_spec.rb +3 -2
- data/spec/spec_helper.rb +5 -4
- data/spec/support/fixture.rb +3 -5
- metadata +24 -71
- data/lib/savon/core_ext/hash.rb +0 -70
- data/spec/savon/core_ext/hash_spec.rb +0 -121
data/lib/savon/core_ext/hash.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
require "builder"
|
2
|
-
|
3
|
-
require "savon"
|
4
|
-
require "savon/core_ext/object"
|
5
|
-
require "savon/core_ext/string"
|
6
|
-
|
7
|
-
module Savon
|
8
|
-
module CoreExt
|
9
|
-
module Hash
|
10
|
-
|
11
|
-
# Returns a new Hash with +self+ and +other_hash+ merged recursively.
|
12
|
-
# Modifies the receiver in place.
|
13
|
-
def deep_merge!(other_hash)
|
14
|
-
other_hash.each_pair do |k,v|
|
15
|
-
tv = self[k]
|
16
|
-
self[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_merge(v) : v
|
17
|
-
end
|
18
|
-
self
|
19
|
-
end unless defined? deep_merge!
|
20
|
-
|
21
|
-
# Returns the values from the soap:Header element or an empty Hash in case the element could
|
22
|
-
# not be found.
|
23
|
-
def find_soap_header
|
24
|
-
find_soap_element /.+:Header/
|
25
|
-
end
|
26
|
-
|
27
|
-
# Returns the values from the soap:Body element or an empty Hash in case the element could
|
28
|
-
# not be found.
|
29
|
-
def find_soap_body
|
30
|
-
find_soap_element /.+:Body/
|
31
|
-
end
|
32
|
-
|
33
|
-
# Maps keys and values of a Hash created from SOAP response XML to more convenient Ruby Objects.
|
34
|
-
def map_soap_response
|
35
|
-
inject({}) do |hash, (key, value)|
|
36
|
-
value = case value
|
37
|
-
when ::Hash then value["xsi:nil"] ? nil : value.map_soap_response
|
38
|
-
when ::Array then value.map { |val| val.map_soap_response rescue val }
|
39
|
-
when ::String then value.map_soap_response
|
40
|
-
end
|
41
|
-
|
42
|
-
new_key = if Savon.strip_namespaces?
|
43
|
-
key.strip_namespace.snakecase.to_sym
|
44
|
-
else
|
45
|
-
key.snakecase
|
46
|
-
end
|
47
|
-
|
48
|
-
if hash[new_key] # key already exists, value should be added as an Array
|
49
|
-
hash[new_key] = [hash[new_key], value].flatten
|
50
|
-
result = hash
|
51
|
-
else
|
52
|
-
result = hash.merge new_key => value
|
53
|
-
end
|
54
|
-
result
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
def find_soap_element(element)
|
61
|
-
envelope = self[keys.first] || {}
|
62
|
-
element_key = envelope.keys.find { |key| element =~ key } rescue nil
|
63
|
-
element_key ? envelope[element_key].map_soap_response : {}
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
Hash.send :include, Savon::CoreExt::Hash
|
@@ -1,121 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Hash do
|
4
|
-
|
5
|
-
describe "#deep_merge!" do
|
6
|
-
it "should recursively merge two Hashes" do
|
7
|
-
hash = { :one => 1, "two" => { "three" => 3 } }
|
8
|
-
other_hash = { :four => 4, "two" => { "three" => "merge", :five => 5 } }
|
9
|
-
|
10
|
-
hash.merge!(other_hash).should == { :one => 1, :four => 4, "two" => { "three" => "merge", :five => 5 } }
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "#find_soap_header" do
|
15
|
-
it "should return the content from the 'soap:Header' element" do
|
16
|
-
soap_header = { "soap:Envelope" => { "soap:Header" => "content" } }
|
17
|
-
soap_header.find_soap_header.should == "content"
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should return an empty Hash in case the 'soap:Header' element could not be found" do
|
21
|
-
soap_header = { "some_hash" => "content" }
|
22
|
-
soap_header.find_soap_header.should == {}
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "#find_soap_body" do
|
27
|
-
it "should return the content from the 'soap:Body' element" do
|
28
|
-
soap_body = { "soap:Envelope" => { "soap:Body" => "content" } }
|
29
|
-
soap_body.find_soap_body.should == "content"
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should return an empty Hash in case the 'soap:Body' element could not be found" do
|
33
|
-
soap_body = { "some_hash" => "content" }
|
34
|
-
soap_body.find_soap_body.should == {}
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "#map_soap_response" do
|
39
|
-
it "should convert Hash key Strings to snake_case Symbols" do
|
40
|
-
soap_response = { "userResponse" => { "accountStatus" => "active" } }
|
41
|
-
result = { :user_response => { :account_status => "active" } }
|
42
|
-
|
43
|
-
soap_response.map_soap_response.should == result
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should strip namespaces from Hash keys" do
|
47
|
-
soap_response = { "ns:userResponse" => { "ns2:id" => "666" } }
|
48
|
-
result = { :user_response => { :id => "666" } }
|
49
|
-
|
50
|
-
soap_response.map_soap_response.should == result
|
51
|
-
end
|
52
|
-
|
53
|
-
context "with Savon.strip_namespaces set to false" do
|
54
|
-
around do |example|
|
55
|
-
Savon.strip_namespaces = false
|
56
|
-
example.run
|
57
|
-
Savon.strip_namespaces = true
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should not strip namespaces from Hash keys" do
|
61
|
-
soap_response = { "ns:userResponse" => { "ns2:id" => "666" } }
|
62
|
-
result = { "ns:user_response" => { "ns2:id" => "666" } }
|
63
|
-
|
64
|
-
soap_response.map_soap_response.should == result
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should convert Hash keys and values in Arrays" do
|
69
|
-
soap_response = { "response" => [{ "name" => "dude" }, { "name" => "gorilla" }] }
|
70
|
-
result = { :response=> [{ :name => "dude" }, { :name => "gorilla" }] }
|
71
|
-
|
72
|
-
soap_response.map_soap_response.should == result
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should convert xsi:nil values to nil Objects" do
|
76
|
-
soap_response = { "userResponse" => { "xsi:nil" => "true" } }
|
77
|
-
result = { :user_response => nil }
|
78
|
-
|
79
|
-
soap_response.map_soap_response.should == result
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should convert Hash values matching the xs:dateTime format into DateTime Objects" do
|
83
|
-
soap_response = { "response" => { "at" => "2012-03-22T16:22:33+00:00" } }
|
84
|
-
result = { :response => { :at => DateTime.new(2012, 03, 22, 16, 22, 33) } }
|
85
|
-
|
86
|
-
soap_response.map_soap_response.should == result
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should convert Hash values matching 'true' to TrueClass" do
|
90
|
-
soap_response = { "response" => { "active" => "false" } }
|
91
|
-
result = { :response => { :active => false } }
|
92
|
-
|
93
|
-
soap_response.map_soap_response.should == result
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should convert Hash values matching 'false' to FalseClass" do
|
97
|
-
soap_response = { "response" => { "active" => "true" } }
|
98
|
-
result = { :response => { :active => true } }
|
99
|
-
|
100
|
-
soap_response.map_soap_response.should == result
|
101
|
-
end
|
102
|
-
|
103
|
-
it "should convert namespaced entries to array elements" do
|
104
|
-
soap_response = {
|
105
|
-
"history" => {
|
106
|
-
"ns10:case" => { "ns10:name" => "a_name" },
|
107
|
-
"ns11:case" => { "ns11:name" => "another_name" }
|
108
|
-
}
|
109
|
-
}
|
110
|
-
|
111
|
-
result = {
|
112
|
-
:history => {
|
113
|
-
:case => [{ :name => "a_name" }, { :name => "another_name" }]
|
114
|
-
}
|
115
|
-
}
|
116
|
-
|
117
|
-
soap_response.map_soap_response.should == result
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
end
|