lolsoap 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -3,7 +3,9 @@
3
3
  A library for dealing with SOAP requests and responses. We tear our hair
4
4
  out so you don't have to.
5
5
 
6
- https://github.com/loco2/lolsoap
6
+ * Code: https://github.com/loco2/lolsoap
7
+ * Gem: http://rubygems.org/gems/lolsoap
8
+ * Docs: http://rubydoc.info/gems/lolsoap/frames
7
9
 
8
10
  [![Build Status](https://secure.travis-ci.org/loco2/lolsoap.png)](http://travis-ci.org/loco2/lolsoap)
9
11
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -13,7 +13,7 @@ module LolSoap
13
13
  if children.any?
14
14
  children_hash
15
15
  else
16
- node.text.to_s
16
+ content
17
17
  end
18
18
  end
19
19
 
@@ -30,19 +30,36 @@ module LolSoap
30
30
  element = type.element(child.name)
31
31
  output = self.class.new(child, element.type).output
32
32
 
33
- if Array === hash[child.name] || !element.singular?
33
+ if !element.singular?
34
34
  hash[child.name] ||= []
35
- hash[child.name] << output
35
+ end
36
+
37
+ if hash.include?(child.name) && !(Array === hash[child.name])
38
+ hash[child.name] = [hash[child.name]]
39
+ end
40
+
41
+ if Array === hash[child.name]
42
+ hash[child.name] << output unless output.nil?
36
43
  else
37
- if hash.include?(child.name)
38
- hash[child.name] = [hash[child.name]]
39
- hash[child.name] << output
40
- else
41
- hash[child.name] = output
42
- end
44
+ hash[child.name] = output
43
45
  end
44
46
  end
45
47
  hash
46
48
  end
49
+
50
+ # @private
51
+ def content
52
+ node.text.to_s unless nil_value?
53
+ end
54
+
55
+ # @private
56
+ def nil_value?
57
+ parent.search('./*[@xsi:nil=1]', 'xsi' => "http://www.w3.org/2001/XMLSchema-instance").include?(node)
58
+ end
59
+
60
+ # @private
61
+ def parent
62
+ node.ancestors.first
63
+ end
47
64
  end
48
65
  end
@@ -9,7 +9,14 @@ module LolSoap
9
9
 
10
10
  # Create a new instance from a raw XML string
11
11
  def self.parse(request, raw)
12
- new(request, Nokogiri::XML::Document.parse(raw))
12
+ new(
13
+ request,
14
+ Nokogiri::XML::Document.parse(
15
+ raw, nil, nil,
16
+ Nokogiri::XML::ParseOptions::DEFAULT_XML &
17
+ Nokogiri::XML::ParseOptions::STRICT
18
+ )
19
+ )
13
20
  end
14
21
 
15
22
  def initialize(request, doc)
@@ -18,7 +18,7 @@ class LolSoap::WSDL
18
18
  end
19
19
 
20
20
  def inspect
21
- "<LolSoap::WSDL::Element name=#{name.inspect} type=#{@type_name.inspect}>"
21
+ "<#{self.class} name=#{name.inspect} type=#{@type_name.inspect}>"
22
22
  end
23
23
 
24
24
  private
@@ -10,7 +10,7 @@ class LolSoap::WSDL
10
10
  end
11
11
 
12
12
  def inspect
13
- "<LolSoap::WSDL::Operation " \
13
+ "<#{self.class} " \
14
14
  "action=#{action.inspect} " \
15
15
  "input=#{input.inspect}>"
16
16
  end
@@ -26,7 +26,7 @@ class LolSoap::WSDL
26
26
  end
27
27
 
28
28
  def inspect
29
- "<LolSoap::WSDL::Type " \
29
+ "<#{self.class} " \
30
30
  "name=#{(prefix + ':' + name).inspect} " \
31
31
  "elements=#{elements.inspect}>"
32
32
  end
data/lib/lolsoap/wsdl.rb CHANGED
@@ -60,7 +60,7 @@ module LolSoap
60
60
  end
61
61
 
62
62
  def inspect
63
- "<LolSoap::WSDL " \
63
+ "<#{self.class} " \
64
64
  "namespaces=#{namespaces.inspect} " \
65
65
  "operations=#{operations.keys.inspect} " \
66
66
  "types=#{types.keys.inspect}>"
data/lolsoap.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "lolsoap"
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jon Leighton"]
12
- s.date = "2012-01-17"
12
+ s.date = "2012-04-02"
13
13
  s.description = "A library for dealing with SOAP requests and responses. We tear our hair out so you don't have to."
14
14
  s.email = "j@jonathanleighton.com"
15
15
  s.extra_rdoc_files = [
@@ -67,7 +67,7 @@ Gem::Specification.new do |s|
67
67
  s.homepage = "http://github.com/loco2/lolsoap"
68
68
  s.licenses = ["MIT"]
69
69
  s.require_paths = ["lib"]
70
- s.rubygems_version = "1.8.10"
70
+ s.rubygems_version = "1.8.15"
71
71
  s.summary = "A library for dealing with SOAP requests and responses."
72
72
 
73
73
  if s.respond_to? :specification_version then
@@ -123,5 +123,29 @@ module LolSoap
123
123
  builder = HashBuilder.new(node, LolTypes.person)
124
124
  builder.output.must_equal({ 'age' => ['20', '30', '40'] })
125
125
  end
126
+
127
+ it 'converts fields with xsi:nil attribute into nils' do
128
+ xml = Nokogiri::XML <<-XML
129
+ <name>
130
+ <firstName xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="1" />
131
+ </name>
132
+ XML
133
+ node = xml.root
134
+
135
+ builder = HashBuilder.new(node, LolTypes.name)
136
+ builder.output.must_equal({ 'firstName' => nil })
137
+ end
138
+
139
+ it 'converts elements with xsi:nil attribute which can occur multiple times into empty arrays' do
140
+ xml = Nokogiri::XML <<-XML
141
+ <person>
142
+ <friends xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="1" />
143
+ </person>
144
+ XML
145
+ node = xml.root
146
+
147
+ builder = HashBuilder.new(node, LolTypes.person)
148
+ builder.output.must_equal({ 'friends' => [] })
149
+ end
126
150
  end
127
151
  end
@@ -9,6 +9,12 @@ module LolSoap
9
9
 
10
10
  subject { Response.new(request, doc) }
11
11
 
12
+ describe '.parse' do
13
+ it 'raises an error if there is invalid XML' do
14
+ lambda { Response.parse(request, '<a') }.must_raise Nokogiri::XML::SyntaxError
15
+ end
16
+ end
17
+
12
18
  describe '#body' do
13
19
  it 'returns the first node under the envelope body' do
14
20
  subject.body.must_equal doc.at_xpath('/soap:Envelope/soap:Body/m:GetStockPriceResponse')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lolsoap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-17 00:00:00.000000000 Z
12
+ date: 2012-04-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &11712020 !ruby/object:Gem::Requirement
16
+ requirement: &21674480 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.5.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *11712020
24
+ version_requirements: *21674480
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &11711180 !ruby/object:Gem::Requirement
27
+ requirement: &21672260 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.0.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *11711180
35
+ version_requirements: *21672260
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: jeweler
38
- requirement: &11709980 !ruby/object:Gem::Requirement
38
+ requirement: &21669620 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.6.4
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *11709980
46
+ version_requirements: *21669620
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: minitest
49
- requirement: &11721600 !ruby/object:Gem::Requirement
49
+ requirement: &21273520 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *11721600
57
+ version_requirements: *21273520
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: yard
60
- requirement: &11720660 !ruby/object:Gem::Requirement
60
+ requirement: &21271840 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *11720660
68
+ version_requirements: *21271840
69
69
  description: A library for dealing with SOAP requests and responses. We tear our hair
70
70
  out so you don't have to.
71
71
  email: j@jonathanleighton.com
@@ -136,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
136
  version: '0'
137
137
  segments:
138
138
  - 0
139
- hash: 1458853334656196452
139
+ hash: -3972436845554789040
140
140
  required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  none: false
142
142
  requirements:
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  version: '0'
146
146
  requirements: []
147
147
  rubyforge_project:
148
- rubygems_version: 1.8.10
148
+ rubygems_version: 1.8.15
149
149
  signing_key:
150
150
  specification_version: 3
151
151
  summary: A library for dealing with SOAP requests and responses.