savon 0.8.2 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
+ ## 0.8.3 (2010-01-11)
2
+
3
+ * Moved implementation of `Savon::SOAP::Response#to_array` to a class method at `Savon::SOAP::XML.to_array`
4
+ ([05a7d3](https://github.com/rubiii/savon/commit/05a7d3)).
5
+
6
+ * Fix for [issue #131](https://github.com/rubiii/savon/issues/131) ([4e57b3](https://github.com/rubiii/savon/commit/4e57b3)).
7
+
1
8
  ## 0.8.2 (2010-01-04)
2
9
 
3
- * Fix for [issue #127](https://github.com/rubiii/savon/issues/127) ([0eb3da](https://github.com/rubiii/savon/commit/0eb3da4))
10
+ * Fix for [issue #127](https://github.com/rubiii/savon/issues/127) ([0eb3da](https://github.com/rubiii/savon/commit/0eb3da4)).
4
11
 
5
12
  * Changed `Savon::WSSE` to be based on a Hash instead of relying on builder ([4cebc3](https://github.com/rubiii/savon/commit/4cebc3)).
6
13
 
data/README.md CHANGED
@@ -3,7 +3,7 @@ Savon
3
3
 
4
4
  Heavy metal Ruby SOAP client
5
5
 
6
- [Guide](http://rubiii.github.com/savon) | [Rubydoc](http://rubydoc.info/gems/savon) | [Wishlist](http://savon.uservoice.com) | [Bugs](http://github.com/rubiii/savon/issues)
6
+ [Guide](http://rubiii.github.com/savon) | [Rubydoc](http://rubydoc.info/gems/savon) | [Google Group](http://groups.google.com/group/savon-soap) | [Wishlist](http://savon.uservoice.com) | [Bugs](http://github.com/rubiii/savon/issues)
7
7
 
8
8
  Installation
9
9
  ------------
@@ -31,12 +31,6 @@ module Savon
31
31
  self[0, prefix.length] == prefix
32
32
  end unless defined? starts_with?
33
33
 
34
- # Returns whether the String ends with a given +suffix+.
35
- def ends_with?(suffix)
36
- suffix = suffix.to_s
37
- self[-suffix.length, suffix.length] == suffix
38
- end unless defined? ends_with?
39
-
40
34
  # Returns the String without namespace.
41
35
  def strip_namespace
42
36
  split(":").last
@@ -45,19 +45,12 @@ module Savon
45
45
 
46
46
  # Returns the SOAP response body as a Hash.
47
47
  def to_hash
48
- @hash ||= Savon::SOAP::XML.to_hash to_xml
48
+ @hash ||= Savon::SOAP::XML.to_hash http.body
49
49
  end
50
50
 
51
- # Traverses the SOAP response Hash for a given +path+ of Hash keys
52
- # and returns the value as an Array. Defaults to return an empty Array
53
- # in case the path does not exist or returns nil.
51
+ # Returns the SOAP response body as an Array.
54
52
  def to_array(*path)
55
- value = path.inject to_hash do |memo, key|
56
- return [] unless memo[key]
57
- memo[key]
58
- end
59
-
60
- value.kind_of?(Array) ? value.compact : [value].compact
53
+ Savon::SOAP::XML.to_array to_hash, *path
61
54
  end
62
55
 
63
56
  # Returns the SOAP response XML.
@@ -20,10 +20,25 @@ module Savon
20
20
  "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance"
21
21
  }
22
22
 
23
+ # Converts the given SOAP response +xml+ into a Hash.
23
24
  def self.to_hash(xml)
24
25
  (Crack::XML.parse(xml) rescue {}).find_soap_body
25
26
  end
26
27
 
28
+ # Expects a SOAP response XML or Hash, traverses it for a given +path+ of Hash keys
29
+ # and returns the value as an Array. Defaults to return an empty Array in case the
30
+ # path does not exist or returns nil.
31
+ def self.to_array(object, *path)
32
+ hash = object.kind_of?(Hash) ? object : to_hash(object)
33
+
34
+ result = path.inject hash do |memo, key|
35
+ return [] unless memo[key]
36
+ memo[key]
37
+ end
38
+
39
+ result.kind_of?(Array) ? result.compact : [result].compact
40
+ end
41
+
27
42
  # Accepts an +endpoint+, an +input+ tag and a SOAP +body+.
28
43
  def initialize(endpoint = nil, input = nil, body = nil)
29
44
  self.endpoint = endpoint if endpoint
data/lib/savon/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Savon
2
2
 
3
- Version = "0.8.2"
3
+ Version = "0.8.3"
4
4
 
5
5
  end
data/lib/savon/wsse.rb CHANGED
@@ -81,12 +81,19 @@ module Savon
81
81
 
82
82
  # Returns a Hash containing wsse:UsernameToken details.
83
83
  def wsse_username_token
84
- wsse_security "UsernameToken",
85
- "wsse:Username" => username,
86
- "wsse:Nonce" => nonce,
87
- "wsu:Created" => timestamp,
88
- "wsse:Password" => password_value,
89
- :attributes! => { "wsse:Password" => { "Type" => password_type } }
84
+ if digest?
85
+ wsse_security "UsernameToken",
86
+ "wsse:Username" => username,
87
+ "wsse:Nonce" => nonce,
88
+ "wsu:Created" => timestamp,
89
+ "wsse:Password" => digest_password,
90
+ :attributes! => { "wsse:Password" => { "Type" => PasswordDigestURI } }
91
+ else
92
+ wsse_security "UsernameToken",
93
+ "wsse:Username" => username,
94
+ "wsse:Password" => password,
95
+ :attributes! => { "wsse:Password" => { "Type" => PasswordTextURI } }
96
+ end
90
97
  end
91
98
 
92
99
  # Returns a Hash containing wsse:Timestamp details.
@@ -107,19 +114,12 @@ module Savon
107
114
  }
108
115
  end
109
116
 
110
- # Returns the WSSE password. Encrypts the password for digest authentication.
111
- def password_value
112
- return password unless digest?
113
-
117
+ # Returns the WSSE password, encrypted for digest authentication.
118
+ def digest_password
114
119
  token = nonce + timestamp + password
115
120
  Base64.encode64(Digest::SHA1.hexdigest(token)).chomp!
116
121
  end
117
122
 
118
- # Returns the URI for the "wsse:Password/@Type" attribute.
119
- def password_type
120
- digest? ? PasswordDigestURI : PasswordTextURI
121
- end
122
-
123
123
  # Returns a WSSE nonce.
124
124
  def nonce
125
125
  @nonce ||= Digest::SHA1.hexdigest random_string + timestamp
data/savon.gemspec CHANGED
@@ -16,12 +16,12 @@ Gem::Specification.new do |s|
16
16
 
17
17
  s.add_dependency "builder", ">= 2.1.2"
18
18
  s.add_dependency "crack", "~> 0.1.8"
19
- s.add_dependency "httpi", ">= 0.7.5"
20
- s.add_dependency "gyoku", ">= 0.1.1"
19
+ s.add_dependency "httpi", ">= 0.7.8"
20
+ s.add_dependency "gyoku", ">= 0.2.0"
21
21
 
22
- s.add_development_dependency "rspec", "~> 2.0.0"
22
+ s.add_development_dependency "rspec", "~> 2.4.0"
23
23
  s.add_development_dependency "autotest"
24
- s.add_development_dependency "mocha", "~> 0.9.7"
24
+ s.add_development_dependency "mocha", "~> 0.9.8"
25
25
  s.add_development_dependency "timecop", "~> 0.3.5"
26
26
 
27
27
  s.files = `git ls-files`.split("\n")
@@ -25,14 +25,6 @@ describe String do
25
25
  end
26
26
  end
27
27
 
28
- describe "ends_with?" do
29
- it "should return whether it ends with a given suffix" do
30
- "authenticate!".ends_with?("!").should be_true
31
- "authenticate".ends_with?("cate").should be_true
32
- "authenticate".ends_with?("?").should be_false
33
- end
34
- end
35
-
36
28
  describe "strip_namespace" do
37
29
  it "strips the namespace from a namespaced String" do
38
30
  "ns:customer".strip_namespace.should == "customer"
@@ -124,25 +124,9 @@ describe Savon::SOAP::Response do
124
124
  end
125
125
 
126
126
  describe "#to_array" do
127
- let(:response) { soap_response }
128
-
129
- context "when the given path exists" do
130
- it "should return an Array containing the path value" do
131
- response.to_array(:authenticate_response, :return).should ==
132
- [Fixture.response_hash(:authentication)[:authenticate_response][:return]]
133
- end
134
- end
135
-
136
- context "when the given path returns nil" do
137
- it "should return an empty Array" do
138
- response.to_array(:authenticate_response, :undefined).should == []
139
- end
140
- end
141
-
142
- context "when the given path does not exist at all" do
143
- it "should return an empty Array" do
144
- response.to_array(:authenticate_response, :some, :wrong, :path).should == []
145
- end
127
+ it "should delegate to Savon::SOAP::XML.to_array" do
128
+ Savon::SOAP::XML.expects(:to_array).with(soap_response.to_hash, :authenticate_response, :return)
129
+ soap_response.to_array :authenticate_response, :return
146
130
  end
147
131
  end
148
132
 
@@ -31,6 +31,29 @@ describe Savon::SOAP::XML do
31
31
  end
32
32
  end
33
33
 
34
+ describe ".to_array" do
35
+ let(:response_hash) { Fixture.response_hash :authentication }
36
+
37
+ context "when the given path exists" do
38
+ it "should return an Array containing the path value" do
39
+ Savon::SOAP::XML.to_array(response_hash, :authenticate_response, :return).should ==
40
+ [response_hash[:authenticate_response][:return]]
41
+ end
42
+ end
43
+
44
+ context "when the given path returns nil" do
45
+ it "should return an empty Array" do
46
+ Savon::SOAP::XML.to_array(response_hash, :authenticate_response, :undefined).should == []
47
+ end
48
+ end
49
+
50
+ context "when the given path does not exist at all" do
51
+ it "should return an empty Array" do
52
+ Savon::SOAP::XML.to_array(response_hash, :authenticate_response, :some, :wrong, :path).should == []
53
+ end
54
+ end
55
+ end
56
+
34
57
  describe ".new" do
35
58
  it "should accept an endpoint, an input tag and a SOAP body" do
36
59
  xml = Savon::SOAP::XML.new Endpoint.soap, :authentication, :id => 1
@@ -118,12 +118,12 @@ describe Savon::WSSE do
118
118
  wsse.to_xml.should include("username", "password")
119
119
  end
120
120
 
121
- it "should contain a wsse:Nonce tag" do
122
- wsse.to_xml.should match(/<wsse:Nonce>\w+<\/wsse:Nonce>/)
121
+ it "should not contain a wsse:Nonce tag" do
122
+ wsse.to_xml.should_not match(/<wsse:Nonce>.*<\/wsse:Nonce>/)
123
123
  end
124
124
 
125
- it "should contain a wsu:Created tag" do
126
- wsse.to_xml.should match(/<wsu:Created>#{Savon::SOAP::DateTimeRegexp}.+<\/wsu:Created>/)
125
+ it "should not contain a wsu:Created tag" do
126
+ wsse.to_xml.should_not match(/<wsu:Created>.*<\/wsu:Created>/)
127
127
  end
128
128
 
129
129
  it "should contain the PasswordText type attribute" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: savon
3
3
  version: !ruby/object:Gem::Version
4
- hash: 59
4
+ hash: 57
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 2
10
- version: 0.8.2
9
+ - 3
10
+ version: 0.8.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel Harrington
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-04 00:00:00 +01:00
18
+ date: 2011-01-11 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -58,12 +58,12 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- hash: 9
61
+ hash: 19
62
62
  segments:
63
63
  - 0
64
64
  - 7
65
- - 5
66
- version: 0.7.5
65
+ - 8
66
+ version: 0.7.8
67
67
  type: :runtime
68
68
  version_requirements: *id003
69
69
  - !ruby/object:Gem::Dependency
@@ -74,12 +74,12 @@ dependencies:
74
74
  requirements:
75
75
  - - ">="
76
76
  - !ruby/object:Gem::Version
77
- hash: 25
77
+ hash: 23
78
78
  segments:
79
79
  - 0
80
- - 1
81
- - 1
82
- version: 0.1.1
80
+ - 2
81
+ - 0
82
+ version: 0.2.0
83
83
  type: :runtime
84
84
  version_requirements: *id004
85
85
  - !ruby/object:Gem::Dependency
@@ -90,12 +90,12 @@ dependencies:
90
90
  requirements:
91
91
  - - ~>
92
92
  - !ruby/object:Gem::Version
93
- hash: 15
93
+ hash: 31
94
94
  segments:
95
95
  - 2
96
+ - 4
96
97
  - 0
97
- - 0
98
- version: 2.0.0
98
+ version: 2.4.0
99
99
  type: :development
100
100
  version_requirements: *id005
101
101
  - !ruby/object:Gem::Dependency
@@ -120,12 +120,12 @@ dependencies:
120
120
  requirements:
121
121
  - - ~>
122
122
  - !ruby/object:Gem::Version
123
- hash: 53
123
+ hash: 43
124
124
  segments:
125
125
  - 0
126
126
  - 9
127
- - 7
128
- version: 0.9.7
127
+ - 8
128
+ version: 0.9.8
129
129
  type: :development
130
130
  version_requirements: *id007
131
131
  - !ruby/object:Gem::Dependency
@@ -161,7 +161,6 @@ files:
161
161
  - LICENSE
162
162
  - README.md
163
163
  - Rakefile
164
- - autotest/discover.rb
165
164
  - lib/savon.rb
166
165
  - lib/savon/client.rb
167
166
  - lib/savon/core_ext/hash.rb
data/autotest/discover.rb DELETED
@@ -1 +0,0 @@
1
- Autotest.add_discovery { "rspec2" }