lolsoap 0.7.0 → 0.8.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: 581a7842c694777a4af6b960f266eaebbf9e9431
4
- data.tar.gz: 095e4cd38b1e59af2ff5514a560725f02d21b867
3
+ metadata.gz: 0b9bc4b76b05a3d31cba1d44dfbdcbe1ec345374
4
+ data.tar.gz: 3bc623601587f2e60ca3443767c02e73b69f2f60
5
5
  SHA512:
6
- metadata.gz: d26800dfb89edd5bb9378a280d6be073d57ff8e273d1865b7b5cfde5ab5d83c9d3f757bb71df2213987c57c741947985d76127ea1e629b3c5e4cff963bcbd4e1
7
- data.tar.gz: 44a08cfc2ecc91f15bcc54a442d37b912fe831d8a1bb013503efc52d392d2e04f2b0a5d4afeb684c28cbced4734048358544bef0b03195b566ee96966c95017e
6
+ metadata.gz: ccf49a609716134ab68a817fc59ee1e872767d812b5e35ae148d244c8a9a882afe96499ddacaf7c49c6f17c79c5c3d82f910da77f448cb6ada62f22b9d0083b5
7
+ data.tar.gz: c8b787f474363da4d866cfb6f1ba8419dc8275fed43f23667835f97112aa5d7495c666172a4f9127c8d789b4cd86eb274d3feeff94a4004fc87aab80695ffe3e
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
4
- - 2.1.5
5
- - 2.2.1
3
+ - 2.1.8
4
+ - 2.2.4
5
+ - 2.3.0
data/README.md CHANGED
@@ -114,6 +114,11 @@ Development sponsored by [Loco2](http://loco2.com/).
114
114
 
115
115
  ## Changelog ##
116
116
 
117
+ ### 0.8 ###
118
+
119
+ * Use namespaces when looking up definitions
120
+ * Added support for referenced attribute groups
121
+
117
122
  ### 0.7 ###
118
123
 
119
124
  * Added support for element references in type definitions
@@ -1,3 +1,3 @@
1
1
  module LolSoap
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -82,8 +82,8 @@ module LolSoap
82
82
 
83
83
  def base_type
84
84
  @base_type ||= begin
85
- if extension = node.at_xpath('*/xs:extension/@base', parser.ns)
86
- parser.type(extension.to_s)
85
+ if extension = node.at_xpath('*/xs:extension', parser.ns)
86
+ parser.type(*parser.namespace_and_name(extension, extension.attribute('base').to_s))
87
87
  end
88
88
  end
89
89
  end
@@ -110,7 +110,7 @@ module LolSoap
110
110
  node.xpath('*/xs:element | */*/xs:element | xs:complexContent/xs:extension/*/xs:element | xs:complexContent/xs:extension/*/*/xs:element', parser.ns).map { |el|
111
111
  element = Element.new(parser, el, target_namespace)
112
112
  if reference = el.attribute('ref')
113
- ReferencedElement.new(element, parser.element(reference.to_s))
113
+ ReferencedElement.new(element, parser.element(*parser.namespace_and_name(el, reference.to_s)))
114
114
  else
115
115
  element
116
116
  end
@@ -122,14 +122,40 @@ module LolSoap
122
122
  end
123
123
 
124
124
  def own_attributes
125
+ defined_attributes + referenced_attributes
126
+ end
127
+
128
+ def defined_attributes
125
129
  node.xpath('xs:attribute/@name | */xs:extension/xs:attribute/@name', parser.ns).map(&:text)
126
130
  end
127
131
 
132
+ def referenced_attributes
133
+ node.xpath('xs:attributeGroup[@ref] | */xs:extension/xs:attributeGroup[@ref]', parser.ns).map { |group|
134
+ parser.attribute_group(*parser.namespace_and_name(group, group.attribute('ref').to_s))
135
+ }.flat_map(&:attributes)
136
+ end
137
+
128
138
  def parent_attributes
129
139
  base_type ? base_type.attributes : []
130
140
  end
131
141
  end
132
142
 
143
+ class AttributeGroup < Node
144
+ def attributes
145
+ own_attributes + referenced_attributes
146
+ end
147
+
148
+ def own_attributes
149
+ node.xpath('xs:attribute/@name', parser.ns).map(&:text)
150
+ end
151
+
152
+ def referenced_attributes
153
+ node.xpath('xs:attributeGroup[@ref]', parser.ns).map { |group|
154
+ parser.attribute_group(*parser.namespace_and_name(group, group.attribute('ref').to_s))
155
+ }.flat_map(&:attributes)
156
+ end
157
+ end
158
+
133
159
  class Operation
134
160
  attr_reader :parser, :node
135
161
 
@@ -241,8 +267,8 @@ module LolSoap
241
267
  end
242
268
  end
243
269
 
244
- def type(name)
245
- find_node name, Type, 'complexType'
270
+ def type(namespace, name)
271
+ find_node namespace, name, Type, 'complexType'
246
272
  end
247
273
 
248
274
  def elements
@@ -260,8 +286,12 @@ module LolSoap
260
286
  end
261
287
  end
262
288
 
263
- def element(name)
264
- find_node name, Element, 'element'
289
+ def element(namespace, name)
290
+ find_node namespace, name, Element, 'element'
291
+ end
292
+
293
+ def attribute_group(namespace, name)
294
+ find_node namespace, name, AttributeGroup, 'attributeGroup'
265
295
  end
266
296
 
267
297
  def messages
@@ -338,7 +368,11 @@ module LolSoap
338
368
  def namespace_and_name(node, prefixed_name, default_namespace = nil)
339
369
  if prefixed_name.include? ':'
340
370
  prefix, name = prefixed_name.split(':')
341
- namespace = node.namespaces.fetch("xmlns:#{prefix}")
371
+ if prefix == 'tns' && schema = node.at_xpath('ancestor::xs:schema', ns)
372
+ namespace = schema.attribute('targetNamespace').to_s
373
+ else
374
+ namespace = node.namespaces.fetch("xmlns:#{prefix}")
375
+ end
342
376
  else
343
377
  name = prefixed_name
344
378
  namespace = default_namespace
@@ -357,9 +391,11 @@ module LolSoap
357
391
  end
358
392
  end
359
393
 
360
- def find_node(name, node_class, selector)
361
- name = name.split(":").last
362
- if node = doc.at_xpath("//xs:#{selector}[@name='#{name}']", ns)
394
+ def find_node(namespace, name, node_class, selector)
395
+ target = schemas.xpath("../xs:schema[@targetNamespace='#{namespace}']", ns)
396
+ target = schemas if target.size == 0
397
+
398
+ if node = target.at_xpath("xs:#{selector}[@name='#{name.split(':').last}']", ns)
363
399
  target_namespace = node.at_xpath('parent::xs:schema/@targetNamespace', ns).to_s
364
400
  node_class.new(self, node, target_namespace)
365
401
  end
@@ -13,6 +13,9 @@
13
13
  <schema targetNamespace="http://example.com/stockquote.xsd"
14
14
  xmlns:xsd3="http://example.com/stockquote.xsd"
15
15
  xmlns="http://www.w3.org/2001/XMLSchema">
16
+ <attributeGroup name="BaseRequestAttributes">
17
+ <attribute name="signature" type="xs:string"/>
18
+ </attributeGroup>
16
19
  <complexType name="Price">
17
20
  <simpleContent>
18
21
  <extension base="xs:string">
@@ -80,7 +83,7 @@
80
83
  <sequence>
81
84
  <element name="accountId" type="xs:string" maxOccurs="1"/>
82
85
  </sequence>
83
- <attribute name="signature" type="xs:string"/>
86
+ <attributeGroup ref="tns:BaseRequestAttributes" />
84
87
  </complexType>
85
88
  </schema>
86
89
 
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.7.0
4
+ version: 0.8.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: 2015-11-12 00:00:00.000000000 Z
11
+ date: 2016-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.4.5
160
+ rubygems_version: 2.5.1
161
161
  signing_key:
162
162
  specification_version: 4
163
163
  summary: A library for dealing with SOAP requests and responses.