lolsoap 0.8.3 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a60c39b2f4f03c4308d6f8c9dbcfa2b33c67eba3
4
- data.tar.gz: e46ab60e8fcd3048c379c08544329bffe051f58d
3
+ metadata.gz: f3f35de62b3329ac274dbf69b5fd25052d22d41c
4
+ data.tar.gz: 306b20946e12d19ead01e087aebc890f28578f11
5
5
  SHA512:
6
- metadata.gz: 099b596571f4f0d34bf41768e2819bcea1f5411457c6deb28d28090c6b480b571515bb87e8333cb411e47041fd2eaa7feacf73c12ba6ab43f446feda05b77965
7
- data.tar.gz: 4ecf0b3962d57e6bf8e768e706414716df634633fc7f3ebbc3da1c0ea6df96eb86764ac1dba16c7acd891b2fac71e50d2a001b64d4920732c1882feac75d0b9e
6
+ metadata.gz: 65b2031d1b4ae9caa69bc9dadbe75a13b4d5b4adc48e0543db7959b0bcdf68c462e6e7e25d98242ba7edf27a946f833700a121888184e8bd9b74a3d55008d8b7
7
+ data.tar.gz: a1406021f4af3844a990c1b5085693bef493a02da5c326859cc8c612dfebe889f820f01478da73786e0383a6b5f703dfbe08ea55c9385b20242790477fe5bb6d
data/.gitignore CHANGED
@@ -19,6 +19,8 @@ pkg
19
19
 
20
20
  Gemfile.lock
21
21
 
22
+ Dockerfile
23
+
22
24
  # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
23
25
  #
24
26
  # * Create a file at ~/.gitignore
data/README.md CHANGED
@@ -120,6 +120,10 @@ Development sponsored by [Loco2](http://loco2.com/).
120
120
 
121
121
  ## Changelog ##
122
122
 
123
+ ### 0.9 ###
124
+
125
+ * Support unqualified form for elements in a schema
126
+
123
127
  ### 0.8 ###
124
128
 
125
129
  * Use namespaces when looking up definitions
@@ -68,7 +68,21 @@ module LolSoap
68
68
  sub_node = @node.document.create_element(name.to_s, *args)
69
69
  sub_node.namespace = @node.namespace_scopes.find { |n| n.prefix == prefix }
70
70
 
71
- @node << sub_node
71
+ # Nokogiri doesn't currently allow to add a child element without a
72
+ # namespace to a parent with a namespace: the child inherits the parent's
73
+ # namespace. It's a known issue:
74
+ # https://github.com/sparklemotion/nokogiri/issues/1469 Until it's fixed,
75
+ # we'll use this workaround: store the parent's namespace, set it to nil
76
+ # temporarily, add the child and re-add the original namespace to the
77
+ # parent.
78
+ if sub_node.namespace.nil?
79
+ parent_namespace = @node.namespace
80
+ @node.namespace = nil
81
+ @node << sub_node
82
+ @node.namespace = parent_namespace
83
+ else
84
+ @node << sub_node
85
+ end
72
86
 
73
87
  builder = __class__.new(sub_node, sub_type)
74
88
  yield builder if block_given?
@@ -1,3 +1,3 @@
1
1
  module LolSoap
2
- VERSION = "0.8.3"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -135,7 +135,7 @@ module LolSoap
135
135
  Element.new(
136
136
  self,
137
137
  params[:name],
138
- prefix(params[:namespace]),
138
+ params[:namespace] && prefix(params[:namespace]),
139
139
  type_reference(params[:type]),
140
140
  params[:singular]
141
141
  )
@@ -6,25 +6,55 @@ module LolSoap
6
6
  class WSDLParser
7
7
  class ParseError < StandardError; end
8
8
 
9
+ class Schema < Struct.new(:target_namespace, :element_form_default)
10
+ UNQUALIFIED = 'unqualified'
11
+
12
+ def self.from_node(node)
13
+ new(
14
+ node.attr('targetNamespace').to_s,
15
+ node.attr('elementFormDefault')
16
+ )
17
+ end
18
+
19
+ def default_form
20
+ element_form_default || UNQUALIFIED
21
+ end
22
+ end
23
+
9
24
  class Node
10
- attr_reader :parser, :node, :target_namespace, :name, :namespace
25
+ attr_reader :parser, :node, :schema, :name, :namespace
11
26
 
12
- def initialize(parser, node, target_namespace)
13
- @parser = parser
14
- @node = node
15
- @target_namespace = target_namespace
16
- @namespace, @name = parser.namespace_and_name(node, node.attr('name').to_s, target_namespace)
27
+ def initialize(parser, schema, node)
28
+ @parser = parser
29
+ @node = node
30
+ @schema = schema
17
31
  end
18
32
 
19
33
  def id
20
34
  [namespace, name]
21
35
  end
36
+
37
+ def target_namespace
38
+ schema.target_namespace
39
+ end
22
40
  end
23
41
 
24
42
  class Element < Node
43
+ QUALIFIED = 'qualified'
44
+
45
+ attr_reader :form
46
+
47
+ def initialize(*params)
48
+ super(*params)
49
+
50
+ @form = node.attr('form') || schema.default_form
51
+
52
+ @namespace, @name = parser.namespace_and_name(node, node.attr('name').to_s, default_namespace)
53
+ end
54
+
25
55
  def type
26
56
  if complex_type = node.at_xpath('xs:complexType', parser.ns)
27
- type = Type.new(parser, complex_type, target_namespace)
57
+ type = Type.new(parser, schema, complex_type)
28
58
  {
29
59
  :elements => type.elements,
30
60
  :namespace => type.namespace,
@@ -39,6 +69,14 @@ module LolSoap
39
69
  max_occurs.empty? || max_occurs == '1'
40
70
  end
41
71
 
72
+ def qualified?
73
+ form == QUALIFIED
74
+ end
75
+
76
+ def default_namespace
77
+ target_namespace
78
+ end
79
+
42
80
  private
43
81
 
44
82
  def max_occurs
@@ -72,6 +110,12 @@ module LolSoap
72
110
  end
73
111
 
74
112
  class Type < Node
113
+ def initialize(*params)
114
+ super(*params)
115
+
116
+ @namespace, @name = parser.namespace_and_name(node, node.attr('name').to_s, target_namespace)
117
+ end
118
+
75
119
  def elements
76
120
  parent_elements.merge(own_elements)
77
121
  end
@@ -108,7 +152,8 @@ module LolSoap
108
152
 
109
153
  def element_nodes
110
154
  node.xpath('*/xs:element | */*/xs:element | xs:complexContent/xs:extension/*/xs:element | xs:complexContent/xs:extension/*/*/xs:element', parser.ns).map { |el|
111
- element = Element.new(parser, el, target_namespace)
155
+ element = TypeElement.new(parser, schema, el)
156
+
112
157
  if reference = el.attribute('ref')
113
158
  ReferencedElement.new(element, parser.element(*parser.namespace_and_name(el, reference.to_s)))
114
159
  else
@@ -140,6 +185,12 @@ module LolSoap
140
185
  end
141
186
  end
142
187
 
188
+ class TypeElement < Element
189
+ def default_namespace
190
+ target_namespace if qualified?
191
+ end
192
+ end
193
+
143
194
  class AttributeGroup < Node
144
195
  def attributes
145
196
  own_attributes + referenced_attributes
@@ -254,8 +305,8 @@ module LolSoap
254
305
  def types
255
306
  @types ||= begin
256
307
  types = {}
257
- each_node('xs:complexType[not(@abstract="true")]') do |node, target_ns|
258
- type = Type.new(self, node, target_ns)
308
+ each_node('xs:complexType[not(@abstract="true")]') do |node, schema|
309
+ type = Type.new(self, schema, node)
259
310
  types[type.id] = {
260
311
  :name => type.name,
261
312
  :namespace => type.namespace,
@@ -274,8 +325,8 @@ module LolSoap
274
325
  def elements
275
326
  @elements ||= begin
276
327
  elements = {}
277
- each_node('xs:element') do |node, target_ns|
278
- element = Element.new(self, node, target_ns)
328
+ each_node('xs:element') do |node, schema|
329
+ element = Element.new(self, schema, node)
279
330
  elements[element.id] = {
280
331
  :name => element.name,
281
332
  :namespace => element.namespace,
@@ -378,11 +429,10 @@ module LolSoap
378
429
  end
379
430
 
380
431
  def each_node(xpath)
381
- schemas.each do |schema|
382
- target_namespace = schema.attr('targetNamespace').to_s
383
-
384
- schema.xpath(xpath, ns).each do |node|
385
- yield node, target_namespace
432
+ schemas.each do |schema_node|
433
+ schema = Schema.from_node(schema_node)
434
+ schema_node.xpath(xpath, ns).each do |node|
435
+ yield node, schema
386
436
  end
387
437
  end
388
438
  end
@@ -392,8 +442,8 @@ module LolSoap
392
442
  target = schemas if target.size == 0
393
443
 
394
444
  if node = target.at_xpath("xs:#{selector}[@name='#{name.split(':').last}']", ns)
395
- target_namespace = node.at_xpath('parent::xs:schema/@targetNamespace', ns).to_s
396
- node_class.new(self, node, target_namespace)
445
+ schema = Schema.from_node(node.at_xpath('parent::xs:schema', ns))
446
+ node_class.new(self, schema, node)
397
447
  end
398
448
  end
399
449
  end
@@ -12,7 +12,8 @@
12
12
  <types>
13
13
  <schema targetNamespace="http://example.com/stockquote.xsd"
14
14
  xmlns:xsd3="http://example.com/stockquote.xsd"
15
- xmlns="http://www.w3.org/2001/XMLSchema">
15
+ xmlns="http://www.w3.org/2001/XMLSchema"
16
+ elementFormDefault="qualified">
16
17
  <attributeGroup name="BaseRequestAttributes">
17
18
  <attribute name="signature" type="xs:string"/>
18
19
  </attributeGroup>
@@ -28,7 +28,7 @@ module LolSoap
28
28
  el.wont_equal nil
29
29
  el.text.to_s.must_equal 'LOCO2'
30
30
 
31
- el = doc.at_xpath('//ns0:tradePriceRequest/ns0:specialTickerSymbol/ns1:name', doc.namespaces)
31
+ el = doc.at_xpath('//ns0:tradePriceRequest/ns0:specialTickerSymbol/name', doc.namespaces)
32
32
  el.wont_equal nil
33
33
  el.text.to_s.must_equal 'LOCOLOCOLOCO'
34
34
 
@@ -35,6 +35,7 @@ module LolSoap
35
35
 
36
36
  doc.expect(:create_element, sub_node, args)
37
37
  sub_node.expect(:namespace=, nil, [namespace])
38
+ sub_node.expect(:namespace, namespace)
38
39
  node.children.expect(:<<, nil, [sub_node])
39
40
 
40
41
  yield sub_node
@@ -96,7 +96,7 @@ module LolSoap
96
96
  :elements => {
97
97
  'name' => {
98
98
  :name => 'name',
99
- :namespace => namespace2,
99
+ :namespace => nil,
100
100
  :type => [xs, "string"],
101
101
  :singular => true
102
102
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lolsoap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Leighton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-13 00:00:00.000000000 Z
11
+ date: 2018-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  version: '0'
158
158
  requirements: []
159
159
  rubyforge_project:
160
- rubygems_version: 2.5.1
160
+ rubygems_version: 2.6.13
161
161
  signing_key:
162
162
  specification_version: 4
163
163
  summary: A library for dealing with SOAP requests and responses.