google-ads-common 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/COPYING ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2010 Google Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/ChangeLog ADDED
@@ -0,0 +1,14 @@
1
+ 0.2.1:
2
+ - Support for Savon 0.9.1 and later which is now a dependency.
3
+ - Upgraded to httpi/0.9.2, httpclient/2.1.6.
4
+ - use_ruby_names now defaults to true.
5
+
6
+ 0.2.0:
7
+ - Now using httpi instead of net/http.
8
+
9
+ 0.1.0:
10
+ - Full soap4r code generation for client libraries.
11
+ - Experimental savon code generation for client libraries (in development).
12
+ - Full ClientLogin authentication support.
13
+ - Minimal documentation generation support.
14
+ - The very beginnings of a testing framework.
data/README CHANGED
@@ -18,8 +18,9 @@ Install it using the gem install command.
18
18
 
19
19
  The following gem libraries are required:
20
20
  - soap4r v1.5.8 (only for soap4r-based libraries);
21
- - savon v0.8.5 or greater (only for savon-enabled libraries);
22
- - httpclient v2.1.2 or greater.
21
+ - savon v0.9.1 or greater (for savon-enabled libraries);
22
+ - httpi v0.9.2 or greater;
23
+ - httpclient v2.1.6 or greater.
23
24
 
24
25
  = Docs for Developers
25
26
 
@@ -47,7 +48,7 @@ to run unit tests on the library
47
48
 
48
49
  = Copyright/License Info
49
50
 
50
- Copyright 2010, Google Inc. All Rights Reserved.
51
+ Copyright 2011, Google Inc. All Rights Reserved.
51
52
 
52
53
  Licensed under the Apache License, Version 2.0 (the "License");
53
54
  you may not use this file except in compliance with the License.
data/Rakefile CHANGED
@@ -44,7 +44,7 @@ $GEM_DESCRIPTION = "#{$PROJECT_NAME} provides essential utilities shared by " +
44
44
  "all Ads Ruby client libraries."
45
45
  $GEM_AUTHORS = ['Sergio Gomes', 'Danial Klimkin']
46
46
  $GEM_EMAIL = 'api.sgomes@gmail.com'
47
- $GEM_HOMEPAGE = 'http://code.google.com/p/google-api-adwords-ruby/'
47
+ $GEM_HOMEPAGE = 'http://code.google.com/p/google-api-ads-ruby/'
48
48
 
49
49
  # ====================================================================
50
50
  # Default task - call package
@@ -80,11 +80,9 @@ end
80
80
  # Create a task that will package the Rake software into distributable
81
81
  # gem files.
82
82
  PKG_FILES = FileList[
83
- '*.*',
84
83
  'Rakefile',
85
84
  "#{$LIBDIR}/**/*.rb",
86
- "#{$DOCDIR}/**/*.*",
87
- "#{$TESTDIR}/**/*.*"
85
+ "#{$DOCDIR}/**/*.*"
88
86
  ]
89
87
 
90
88
  PKG_FILES.exclude(/\._/)
@@ -104,12 +102,13 @@ else
104
102
  s.files = PKG_FILES.to_a
105
103
  s.require_path = $LIBDIR
106
104
  s.add_dependency('soap4r', '= 1.5.8')
107
- s.add_dependency('httpclient', '>= 2.1.5.2')
108
- s.add_dependency('httpi', '~>0.7.9')
105
+ s.add_dependency('savon', '~> 0.9.1')
106
+ s.add_dependency('httpclient', '>= 2.1.6')
107
+ s.add_dependency('httpi', '~> 0.9.2')
109
108
 
110
109
  # RDoc information
111
110
  s.has_rdoc = true
112
- s.extra_rdoc_files = ['README']
111
+ s.extra_rdoc_files = ['README', 'ChangeLog', 'COPYING']
113
112
  s.rdoc_options << '--main' << 'README'
114
113
 
115
114
  # Metadata
@@ -118,8 +117,9 @@ else
118
117
  s.homepage = $GEM_HOMEPAGE
119
118
  s.rubyforge_project = $GEM_NAME
120
119
  s.requirements << 'soap4r v1.5.8'
121
- s.requirements << 'httpclient v2.1.5.2 or greater'
122
- s.requirements << 'httpi v0.7.9 or greater'
120
+ s.requirements << 'savon v0.9.1 or greater'
121
+ s.requirements << 'httpclient v2.1.6 or greater'
122
+ s.requirements << 'httpi v0.9.2 or greater'
123
123
  end
124
124
 
125
125
  Rake::GemPackageTask.new(spec) do |t|
@@ -26,7 +26,7 @@ module AdsCommon
26
26
  # Contains helper methods for loading and managing the available services.
27
27
  # This module is meant to be imported into API-specific modules.
28
28
  module ApiConfig
29
- ADS_COMMON_VERSION = '0.2.0'
29
+ ADS_COMMON_VERSION = '0.2.1'
30
30
 
31
31
  # Get the available API versions.
32
32
  #
@@ -256,7 +256,7 @@ module AdsCommon
256
256
  path = wsdl_base
257
257
  if (!subdir_config().nil?)
258
258
  subdir_name = subdir(version, service);
259
- path = path + subdir_name if !subdir_name.empty?()
259
+ path = path + subdir_name if subdir_name and !subdir_name.empty?
260
260
  end
261
261
  path = path + version.to_s + '/' + service.to_s + '?wsdl'
262
262
  res[service.to_s] = path
@@ -41,7 +41,7 @@ module AdsCommon
41
41
 
42
42
  def generate_code()
43
43
  code = ERB.new(get_code_template(), 0, '%<>')
44
- code.result(binding)
44
+ return remove_lines_with_blanks_only(code.result(binding))
45
45
  end
46
46
 
47
47
  def get_code_template()
@@ -54,6 +54,10 @@ module AdsCommon
54
54
  @modules_close_string = 'end; ' * modules_count
55
55
  @modules_close_string += 'end'
56
56
  end
57
+
58
+ def remove_lines_with_blanks_only(text)
59
+ return text.gsub(/\n\ +$/, '')
60
+ end
57
61
  end
58
62
  end
59
63
  end
@@ -20,7 +20,7 @@
20
20
  # Generates the wrappers for API services. Only used during the
21
21
  # 'rake generate' step of library setup.
22
22
 
23
- gem 'savon', '~>0.8.5'
23
+ gem 'savon', '~>0.9.1'
24
24
  require 'savon'
25
25
 
26
26
  require 'ads_common/build/savon_service_generator'
@@ -61,7 +61,7 @@ module AdsCommon
61
61
  # Returns:
62
62
  # none
63
63
  def process_wsdl()
64
- client = Savon::Client.new {|wsdl| wsdl.document = @wsdl_url }
64
+ client = Savon::Client.new(@wsdl_url)
65
65
  begin
66
66
  @generator_args[:namespace] = client.wsdl.namespace
67
67
  do_process_wsdl_client(client)
@@ -44,26 +44,37 @@ module AdsCommon
44
44
 
45
45
  # Generate code for given Savon client.
46
46
  def do_process_wsdl(wsdl)
47
+ @soap_exceptions = []
48
+ @soap_types = []
49
+ @soap_methods = []
50
+
47
51
  doc = REXML::Document.new(wsdl.to_xml)
48
- @raw_types = []
49
- @soap_exceptions = extract_exceptions(doc)
52
+ process_types(doc)
53
+ process_methods(doc)
50
54
  sort_exceptions()
51
- @soap_methods = extract_methods(doc)
52
- @soap_types = extract_types(doc)
53
- end
54
-
55
- # Extracts exceptions list with basic properties from ComplexTypes list.
56
- def extract_exceptions(doc)
57
- exceptions = []
58
- ctypes = get_complex_types(doc)
59
- raw_exceptions = exceptions_from_ctypes(ctypes)
60
- raw_exceptions.each do |raw_exception|
61
- exceptions << {:name => raw_exception.attributes['name'],
62
- :doc => get_element_doc(raw_exception),
63
- :base => get_element_base(raw_exception),
64
- :fields => get_element_fields(raw_exception)}
55
+ end
56
+
57
+ # Extracts different types from XML.
58
+ def process_types(doc)
59
+ get_complex_types(doc).each do |ctype|
60
+ ctype_name = get_element_name(ctype)
61
+ if ctype_name.match('.+Exception$')
62
+ @soap_exceptions << extract_exception(ctype)
63
+ elsif ctype_name.match('.+Error$')
64
+ # We don't use it at the moment.
65
+ # TODO: log we ignore it at proper log level.
66
+ else
67
+ @soap_types << extract_type(ctype)
68
+ end
69
+ end
70
+ end
71
+
72
+ # Extracts SOAP actions as methods.
73
+ def process_methods(doc)
74
+ iface = REXML::XPath.first(doc, 'descendant::wsdl:portType')
75
+ REXML::XPath.each(iface, 'descendant::wsdl:operation') do |operation|
76
+ @soap_methods << extract_method(operation, doc)
65
77
  end
66
- return exceptions
67
78
  end
68
79
 
69
80
  # Extracts ComplexTypes from XML into an array.
@@ -75,72 +86,73 @@ module AdsCommon
75
86
  return complex_types
76
87
  end
77
88
 
78
- # Helper function to find Exceptions (by name) from all types.
79
- def exceptions_from_ctypes(ctypes)
80
- exceptions = []
81
- ctypes.each do |ctype|
82
- if ctype.attributes['name'].match('.+Exception$')
83
- exceptions << ctype
84
- end
85
- end
86
- return exceptions
89
+ # Extracts exception parameters from ComplexTypes element.
90
+ def extract_exception(exception_element)
91
+ return {:name => get_element_name(exception_element),
92
+ :doc => get_element_doc(exception_element),
93
+ :base => get_element_base(exception_element),
94
+ :fields => get_element_fields(exception_element)}
87
95
  end
88
96
 
89
- # Extracts methods and parameters from XML.
90
- def extract_methods(doc)
91
- methods = []
92
- iface = REXML::XPath.first(doc, 'descendant::wsdl:portType')
93
- REXML::XPath.each(iface, 'descendant::wsdl:operation') do |operation|
94
- methods << {:name => operation.attributes['name'].to_s.snakecase,
95
- :input => extract_input_parameters(operation, doc),
96
- :output => extract_output_parameters(operation, doc)}
97
- # This could be used to include documentation from wsdl.
98
- # :doc => get_element_doc(operation, 'wsdl')}
97
+ # Extracts method parameters from ComplexTypes element.
98
+ def extract_method(method_element, doc)
99
+ return {:name => get_element_name(method_element).snakecase,
100
+ :input => extract_input_parameters(method_element, doc),
101
+ :output => extract_output_parameters(method_element, doc)}
102
+ # This could be used to include documentation from wsdl.
103
+ # :doc => get_element_doc(operation, 'wsdl')}
104
+ end
105
+
106
+ # Extracts definition of all types. If a non standard undefined type is
107
+ # found it process it recursively.
108
+ def extract_type(type_element)
109
+ type = {:name => get_element_name(type_element), :fields => []}
110
+ if attribute_to_boolean(type_element.attribute('abstract'))
111
+ type[:abstract] = true
99
112
  end
100
- return methods
113
+ base_type = get_element_base(type_element)
114
+ type[:base] = base_type if base_type
115
+ REXML::XPath.each(type_element,
116
+ 'sequence | complexContent/extension/sequence') do |seq_node|
117
+ type[:fields] += get_element_fields(seq_node)
118
+ end
119
+ return type
101
120
  end
102
121
 
103
122
  # Extracts input parameters of given method as an array.
104
123
  def extract_input_parameters(op_node, doc)
105
- result = []
106
- op_name = op_node.attributes['name'].to_s
107
- doc.each_element_with_attribute('name', op_name, 0,
108
- '//schema/element') do |method_node|
109
- seq_node = REXML::XPath.first(method_node, 'complexType/sequence')
110
- result = get_element_fields(seq_node)
111
- process_method_field_types(result)
112
- end
113
- return result
124
+ op_name = get_element_name(op_node)
125
+ return find_sequence_fields(op_name, doc)
114
126
  end
115
127
 
116
128
  # Extracts output parameter name and fields.
117
129
  def extract_output_parameters(op_node, doc)
118
130
  output_element = REXML::XPath.first(op_node, 'descendant::wsdl:output')
119
- output_name = (output_element.nil?) ? nil :
120
- output_element.attribute('name').to_s
121
- output_fields = []
122
- doc.each_element_with_attribute('name', output_name, 0,
123
- '//schema/element') do |response_node|
124
- seq_node = REXML::XPath.first(response_node, 'complexType/sequence')
125
- output_fields = get_element_fields(seq_node)
126
- process_method_field_types(output_fields)
131
+ output_name = get_element_name(output_element)
132
+ output_fields = find_sequence_fields(output_name, doc)
133
+ return {:name => output_name.snakecase, :fields => output_fields}
134
+ end
135
+
136
+ # Finds sequence fields for the element of given name.
137
+ def find_sequence_fields(name, doc)
138
+ result = []
139
+ doc.each_element_with_attribute('name', name, 0,
140
+ '//schema/element') do |element_node|
141
+ REXML::XPath.each(element_node, 'complexType/sequence') do |seq_node|
142
+ result += get_element_fields(seq_node)
143
+ end
127
144
  end
128
- result = {:name => output_name.snakecase, :fields => output_fields}
129
145
  return result
130
146
  end
131
147
 
132
- # Checks all fields are of standard type or included in raw_types.
133
- def process_method_field_types(fields)
134
- fields.each do |field|
135
- field_type = field[:type]
136
- next if STANDARD_TYPES.include?(field_type)
137
- @raw_types << field_type unless @raw_types.include?(field_type)
138
- end
148
+ # Gets element name defined as its attribute.
149
+ def get_element_name(element)
150
+ return element.attribute('name').to_s
139
151
  end
140
152
 
141
153
  # Gets element base defined as an attribute in sibling.
142
- def get_element_base(root)
143
- base_element = REXML::XPath.first(root, 'complexContent/extension')
154
+ def get_element_base(element)
155
+ base_element = REXML::XPath.first(element, 'complexContent/extension')
144
156
  base = (base_element.nil?) ? nil :
145
157
  base_element.attribute('base').to_s.gsub(/^.+:/, '')
146
158
  return base
@@ -157,53 +169,27 @@ module AdsCommon
157
169
  end
158
170
 
159
171
  # Gets subfields defined as elements under given root.
160
- def get_element_fields(root)
172
+ def get_element_fields(element)
161
173
  fields = []
162
- REXML::XPath.each(root, 'descendant::element') do |element|
163
- fields << {:name => element.attribute('name').to_s.snakecase,
164
- :type => element.attribute('type').to_s.gsub(/^.+:/, ''),
165
- :min_occurs => attribute_to_int(element.attribute('minOccurs')),
166
- :max_occurs => attribute_to_int(element.attribute('maxOccurs'))}
174
+ REXML::XPath.each(element, 'descendant::element') do |item|
175
+ fields << {:name => get_element_name(item).snakecase.to_sym,
176
+ :type => item.attribute('type').to_s.gsub(/^.+:/, ''),
177
+ :min_occurs => attribute_to_int(item.attribute('minOccurs')),
178
+ :max_occurs => attribute_to_int(item.attribute('maxOccurs'))}
167
179
  end
168
180
  return fields
169
181
  end
170
182
 
171
- # Extracts definition of all types. If a non standard undefined type is
172
- # found it process it recursively.
173
- # Special case for extensions - types with a base class.
174
- def extract_types(doc)
175
- types = []
176
- @raw_types.each do |raw_type|
177
- doc.each_element_with_attribute('name', raw_type, 0,
178
- '//schema/complexType') do |type_node|
179
- type = {:name => raw_type, :fields => []}
180
- ext_node = REXML::XPath.first(type_node, 'complexContent/extension')
181
- if ext_node
182
- base_type = ext_node.attribute('base').to_s.gsub(/^.+:/, '')
183
- type[:base] = base_type
184
- @raw_types << base_type unless @raw_types.include?(base_type)
185
- seq_node = REXML::XPath.first(ext_node, 'sequence')
186
- fields = get_element_fields(seq_node)
187
- process_method_field_types(fields)
188
- type[:fields] += fields
189
- end
190
- seq_node = REXML::XPath.first(type_node, 'sequence')
191
- if seq_node
192
- fields = get_element_fields(seq_node)
193
- process_method_field_types(fields)
194
- type[:fields] += fields
195
- end
196
- types << type
197
- end
198
- end
199
- return types
200
- end
201
-
202
183
  # Simple converter for int values.
203
184
  def attribute_to_int(attribute)
204
185
  return attribute.value.eql?('unbounded') ? nil : attribute.value.to_i
205
186
  end
206
187
 
188
+ # Simple converter for boolean values.
189
+ def attribute_to_boolean(attribute)
190
+ return (attribute.nil?) ? nil : attribute.value.eql?('true')
191
+ end
192
+
207
193
  # Reorders exceptions so that base ones always come before derived.
208
194
  def sort_exceptions()
209
195
  @ordered_exceptions = []