aws-sdk 1.4.1 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +0 -1
- data/lib/aws/api_config/AutoScaling-2011-01-01.yml +772 -544
- data/lib/aws/api_config/CloudFormation-2010-05-15.yml +284 -185
- data/lib/aws/api_config/DynamoDB-2011-12-05.yml +458 -738
- data/lib/aws/api_config/EC2-2011-12-15.yml +3502 -2653
- data/lib/aws/api_config/ELB-2011-08-15.yml +484 -352
- data/lib/aws/api_config/IAM-2010-05-08.yml +899 -711
- data/lib/aws/api_config/SNS-2010-03-31.yml +235 -167
- data/lib/aws/api_config/SQS-2011-10-01.yml +290 -251
- data/lib/aws/api_config/STS-2011-06-15.yml +35 -41
- data/lib/aws/api_config/SimpleDB-2009-04-15.yml +290 -263
- data/lib/aws/api_config/SimpleEmailService-2010-12-01.yml +144 -130
- data/lib/aws/api_config/SimpleWorkflow-2012-01-25.yml +697 -1139
- data/lib/aws/auto_scaling/activity_collection.rb +1 -1
- data/lib/aws/auto_scaling/client.rb +724 -9
- data/lib/aws/auto_scaling/errors.rb +1 -5
- data/lib/aws/auto_scaling/group.rb +1 -1
- data/lib/aws/auto_scaling/group_collection.rb +1 -1
- data/lib/aws/auto_scaling/instance_collection.rb +1 -1
- data/lib/aws/auto_scaling/launch_configuration.rb +1 -1
- data/lib/aws/auto_scaling/launch_configuration_collection.rb +1 -1
- data/lib/aws/auto_scaling/notification_configuration_collection.rb +1 -1
- data/lib/aws/auto_scaling/request.rb +1 -2
- data/lib/aws/auto_scaling/scaling_policy_collection.rb +1 -1
- data/lib/aws/auto_scaling/scheduled_action_collection.rb +3 -3
- data/lib/aws/auto_scaling/tag_collection.rb +1 -1
- data/lib/aws/cloud_formation.rb +1 -18
- data/lib/aws/cloud_formation/client.rb +314 -8
- data/lib/aws/cloud_formation/errors.rb +1 -5
- data/lib/aws/cloud_formation/request.rb +1 -2
- data/lib/aws/cloud_formation/stack.rb +4 -3
- data/lib/aws/cloud_formation/stack_collection.rb +2 -2
- data/lib/aws/cloud_formation/stack_resource_collection.rb +1 -1
- data/lib/aws/cloud_formation/stack_resource_summary_collection.rb +2 -2
- data/lib/aws/cloud_formation/stack_summary_collection.rb +1 -1
- data/lib/aws/core.rb +29 -14
- data/lib/aws/core/async_handle.rb +11 -12
- data/lib/aws/core/client.rb +112 -102
- data/lib/aws/core/client/query_json.rb +110 -0
- data/lib/aws/core/client/query_xml.rb +122 -0
- data/lib/aws/core/data.rb +242 -0
- data/lib/aws/core/http/request.rb +7 -4
- data/lib/aws/core/lazy_error_classes.rb +60 -38
- data/lib/aws/core/option_grammar.rb +1 -0
- data/lib/aws/core/policy.rb +2 -1
- data/lib/aws/core/resource.rb +38 -33
- data/lib/aws/core/response.rb +109 -44
- data/lib/aws/core/signature/version_2.rb +42 -0
- data/lib/aws/core/signature/version_3.rb +73 -0
- data/lib/aws/core/signature/version_3_http.rb +72 -0
- data/lib/aws/core/signature/version_4.rb +138 -0
- data/lib/aws/core/uri_escape.rb +6 -9
- data/lib/aws/core/xml/frame.rb +242 -0
- data/lib/aws/core/xml/frame_stack.rb +85 -0
- data/lib/aws/core/xml/grammar.rb +299 -0
- data/lib/aws/core/xml/parser.rb +70 -0
- data/lib/aws/core/xml/root_frame.rb +65 -0
- data/lib/aws/core/{configured_xml_grammars.rb → xml/sax_handlers/libxml.rb} +22 -20
- data/lib/aws/core/xml/sax_handlers/nokogiri.rb +55 -0
- data/lib/aws/core/{authorize_with_session_token.rb → xml/sax_handlers/ox.rb} +19 -7
- data/lib/aws/core/{configured_option_grammars.rb → xml/sax_handlers/rexml.rb} +22 -23
- data/lib/aws/core/xml/stub.rb +123 -0
- data/lib/aws/dynamo_db/batch_get.rb +1 -1
- data/lib/aws/dynamo_db/client.rb +796 -14
- data/lib/aws/dynamo_db/errors.rb +1 -38
- data/lib/aws/dynamo_db/item_collection.rb +29 -28
- data/lib/aws/dynamo_db/request.rb +3 -53
- data/lib/aws/dynamo_db/table.rb +6 -2
- data/lib/aws/ec2/attachment.rb +1 -1
- data/lib/aws/ec2/client.rb +3954 -9
- data/lib/aws/ec2/dhcp_options.rb +3 -3
- data/lib/aws/ec2/errors.rb +10 -4
- data/lib/aws/ec2/instance.rb +7 -6
- data/lib/aws/ec2/instance_collection.rb +2 -2
- data/lib/aws/ec2/key_pair_collection.rb +3 -3
- data/lib/aws/ec2/network_acl.rb +4 -2
- data/lib/aws/ec2/network_acl/entry.rb +10 -10
- data/lib/aws/ec2/network_interface.rb +2 -3
- data/lib/aws/ec2/network_interface/attachment.rb +8 -8
- data/lib/aws/ec2/permission_collection.rb +3 -3
- data/lib/aws/ec2/request.rb +1 -3
- data/lib/aws/ec2/resource_tag_collection.rb +4 -8
- data/lib/aws/ec2/route_table.rb +3 -2
- data/lib/aws/ec2/route_table/route.rb +7 -7
- data/lib/aws/ec2/security_group.rb +2 -2
- data/lib/aws/ec2/security_group/egress_ip_permission_collection.rb +16 -5
- data/lib/aws/ec2/security_group/ingress_ip_permission_collection.rb +4 -3
- data/lib/aws/ec2/security_group/ip_permission.rb +1 -2
- data/lib/aws/ec2/snapshot_collection.rb +6 -3
- data/lib/aws/ec2/subnet.rb +1 -1
- data/lib/aws/ec2/volume.rb +1 -3
- data/lib/aws/ec2/volume_collection.rb +2 -0
- data/lib/aws/elb/availability_zone_collection.rb +2 -2
- data/lib/aws/elb/backend_server_policy_collection.rb +1 -1
- data/lib/aws/elb/client.rb +513 -9
- data/lib/aws/elb/errors.rb +2 -6
- data/lib/aws/elb/instance_collection.rb +2 -2
- data/lib/aws/elb/request.rb +1 -1
- data/lib/aws/errors.rb +61 -74
- data/lib/aws/iam.rb +2 -3
- data/lib/aws/iam/client.rb +1178 -10
- data/lib/aws/iam/collection.rb +2 -1
- data/lib/aws/iam/errors.rb +1 -6
- data/lib/aws/iam/group.rb +8 -9
- data/lib/aws/iam/request.rb +1 -1
- data/lib/aws/iam/server_certificate_collection.rb +8 -5
- data/lib/aws/iam/signing_certificate.rb +1 -1
- data/lib/aws/iam/user.rb +2 -2
- data/lib/aws/iam/user_policy.rb +3 -2
- data/lib/aws/rails.rb +1 -2
- data/lib/aws/record.rb +3 -3
- data/lib/aws/record/abstract_base.rb +0 -3
- data/lib/aws/record/attributes.rb +7 -7
- data/lib/aws/record/model.rb +19 -19
- data/lib/aws/record/model/finder_methods.rb +7 -7
- data/lib/aws/s3/bucket.rb +7 -2
- data/lib/aws/s3/client.rb +391 -398
- data/lib/aws/s3/client/xml.rb +44 -71
- data/lib/aws/s3/data_options.rb +3 -2
- data/lib/aws/s3/errors.rb +8 -11
- data/lib/aws/s3/multipart_upload_collection.rb +1 -3
- data/lib/aws/s3/object_collection.rb +2 -1
- data/lib/aws/s3/object_metadata.rb +2 -2
- data/lib/aws/s3/paginated_collection.rb +2 -2
- data/lib/aws/s3/prefix_and_delimiter_collection.rb +1 -1
- data/lib/aws/s3/presigned_post.rb +18 -17
- data/lib/aws/s3/request.rb +4 -3
- data/lib/aws/s3/s3_object.rb +8 -10
- data/lib/aws/simple_db/attribute.rb +2 -2
- data/lib/aws/simple_db/attribute_collection.rb +14 -4
- data/lib/aws/simple_db/client.rb +313 -14
- data/lib/aws/simple_db/domain.rb +1 -1
- data/lib/aws/simple_db/domain_collection.rb +4 -4
- data/lib/aws/simple_db/domain_metadata.rb +1 -1
- data/lib/aws/simple_db/errors.rb +14 -2
- data/lib/aws/simple_db/expect_condition_option.rb +1 -1
- data/lib/aws/simple_db/item.rb +1 -1
- data/lib/aws/simple_db/item_collection.rb +9 -9
- data/lib/aws/simple_db/item_data.rb +9 -6
- data/lib/aws/simple_db/request.rb +1 -1
- data/lib/aws/simple_email_service.rb +8 -7
- data/lib/aws/simple_email_service/client.rb +174 -9
- data/lib/aws/simple_email_service/email_address_collection.rb +0 -1
- data/lib/aws/simple_email_service/errors.rb +1 -5
- data/lib/aws/simple_email_service/quotas.rb +8 -6
- data/lib/aws/simple_email_service/request.rb +7 -1
- data/lib/aws/simple_workflow/client.rb +1383 -6
- data/lib/aws/simple_workflow/decision_task.rb +1 -3
- data/lib/aws/simple_workflow/errors.rb +1 -38
- data/lib/aws/simple_workflow/history_event_collection.rb +2 -2
- data/lib/aws/simple_workflow/request.rb +5 -49
- data/lib/aws/simple_workflow/type.rb +1 -1
- data/lib/aws/simple_workflow/type_collection.rb +4 -3
- data/lib/aws/simple_workflow/workflow_execution_collection.rb +2 -2
- data/lib/aws/sns/client.rb +345 -9
- data/lib/aws/sns/errors.rb +1 -5
- data/lib/aws/sns/request.rb +1 -2
- data/lib/aws/sns/subscription_collection.rb +2 -2
- data/lib/aws/sns/topic.rb +15 -14
- data/lib/aws/sns/topic_collection.rb +1 -1
- data/lib/aws/sqs/client.rb +334 -9
- data/lib/aws/sqs/errors.rb +1 -6
- data/lib/aws/sqs/queue.rb +20 -21
- data/lib/aws/sqs/queue_collection.rb +3 -3
- data/lib/aws/sqs/request.rb +2 -2
- data/lib/aws/sts.rb +8 -10
- data/lib/aws/sts/client.rb +67 -10
- data/lib/aws/sts/errors.rb +1 -5
- data/lib/aws/sts/request.rb +1 -1
- data/lib/user.rb +49 -0
- metadata +21 -28
- data/lib/aws/auto_scaling/client/xml.rb +0 -32
- data/lib/aws/cloud_formation/client/xml.rb +0 -32
- data/lib/aws/core/api_config.rb +0 -44
- data/lib/aws/core/authorize_v2.rb +0 -39
- data/lib/aws/core/authorize_v3.rb +0 -38
- data/lib/aws/core/authorize_v4.rb +0 -149
- data/lib/aws/core/configured_client_methods.rb +0 -76
- data/lib/aws/core/configured_grammars.rb +0 -63
- data/lib/aws/core/configured_json_client_methods.rb +0 -74
- data/lib/aws/core/ignore_result_element.rb +0 -34
- data/lib/aws/core/json_client.rb +0 -41
- data/lib/aws/core/xml_grammar.rb +0 -957
- data/lib/aws/ec2/client/xml.rb +0 -175
- data/lib/aws/elb/client/xml.rb +0 -33
- data/lib/aws/elb/listener_spec.rb +0 -14
- data/lib/aws/iam/client/xml.rb +0 -34
- data/lib/aws/simple_db/client/options.rb +0 -32
- data/lib/aws/simple_db/client/xml.rb +0 -63
- data/lib/aws/simple_email_service/client/xml.rb +0 -34
- data/lib/aws/sns/client/xml.rb +0 -34
- data/lib/aws/sqs/client/xml.rb +0 -33
- data/lib/aws/sts/client/xml.rb +0 -34
@@ -0,0 +1,85 @@
|
|
1
|
+
# Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
5
|
+
# the License is located at
|
6
|
+
#
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
8
|
+
#
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
12
|
+
# language governing permissions and limitations under the License.
|
13
|
+
|
14
|
+
module AWS
|
15
|
+
module Core
|
16
|
+
module XML
|
17
|
+
|
18
|
+
# @private
|
19
|
+
module FrameStack
|
20
|
+
|
21
|
+
# @param [Hash] rules A hash of parser rules. These
|
22
|
+
# rules are typically generated by an {XML::Grammar}.
|
23
|
+
def initialize rules
|
24
|
+
@frame = RootFrame.new(rules)
|
25
|
+
end
|
26
|
+
|
27
|
+
def sax_parse xml
|
28
|
+
raise NotImplementedError
|
29
|
+
end
|
30
|
+
protected :sax_parse
|
31
|
+
|
32
|
+
# Parses the xml string and returns a hash with the resutls.
|
33
|
+
# @param [String] xml
|
34
|
+
# @return [Hash]
|
35
|
+
def parse xml
|
36
|
+
sax_parse(xml)
|
37
|
+
@frame.value
|
38
|
+
end
|
39
|
+
|
40
|
+
# Increase the frame stack level by one.
|
41
|
+
# @param [String] element_name The name of the xml opening tag.
|
42
|
+
# @param [Hash] attributes A hash of xml element attributes.
|
43
|
+
# @return [nil]
|
44
|
+
def start_element element_name, attributes = {}
|
45
|
+
@frame = @frame.build_child_frame(element_name)
|
46
|
+
self.attributes(attributes)
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
|
50
|
+
# Increase the frame stack level by one by treating
|
51
|
+
# xml element attributes as nested elements.
|
52
|
+
# @param [Hash] attributes A hash of attributes names to values.
|
53
|
+
# @return [nil]
|
54
|
+
def attributes attributes
|
55
|
+
attributes.each_pair do |attr_name, attr_value|
|
56
|
+
attr_frame = @frame.build_child_frame(attr_name)
|
57
|
+
attr_frame.add_text(attr_value)
|
58
|
+
@frame.consume_child_frame(attr_frame)
|
59
|
+
end
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
|
63
|
+
# Pops the top frame off the stack. When closing frames
|
64
|
+
# their final value is computed.
|
65
|
+
# @overload end_element
|
66
|
+
# @return [nil]
|
67
|
+
def end_element *ignored
|
68
|
+
parent = @frame.parent_frame
|
69
|
+
child = @frame
|
70
|
+
parent.consume_child_frame(child)
|
71
|
+
@frame = @frame.parent_frame
|
72
|
+
nil
|
73
|
+
end
|
74
|
+
|
75
|
+
# Adds text to the current frame. Frames that only contain
|
76
|
+
# text and no child elements are leaf nodes and have
|
77
|
+
# raw string values.
|
78
|
+
def text text
|
79
|
+
@frame.add_text(text) if @frame
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,299 @@
|
|
1
|
+
# Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
5
|
+
# the License is located at
|
6
|
+
#
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
8
|
+
#
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
12
|
+
# language governing permissions and limitations under the License.
|
13
|
+
|
14
|
+
module AWS
|
15
|
+
module Core
|
16
|
+
module XML
|
17
|
+
|
18
|
+
# A class that simplifies building XML {Parser} rules. This is also
|
19
|
+
# a compatability layer between the old and new formats of the api
|
20
|
+
# config.
|
21
|
+
class Grammar
|
22
|
+
|
23
|
+
def initialize rules = {}, options = {}
|
24
|
+
@rules = rules
|
25
|
+
@context = @rules
|
26
|
+
@element_name = 'xml'
|
27
|
+
@inflect_rename = options.key?(:inflect_rename) ?
|
28
|
+
options[:inflect_rename] : true
|
29
|
+
end
|
30
|
+
|
31
|
+
# Parses the XML with the rules provided by the current grammar.
|
32
|
+
# This method is meant to provide backwards compatability with
|
33
|
+
# the old XmlGrammar class that handled rules and parsing.
|
34
|
+
# @param [String] xml
|
35
|
+
# @return [Data] Returns a hash-like parsed response.
|
36
|
+
def parse xml
|
37
|
+
Data.new(Parser.parse(xml, rules))
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Hash] Returns a hash of rules defined by this grammar.
|
41
|
+
attr_reader :rules
|
42
|
+
|
43
|
+
# Returns a new grammar (leaving the current one un-modified) with
|
44
|
+
# the given customizations applied. Customizations can be given in
|
45
|
+
# a hash-form or in a block form.
|
46
|
+
#
|
47
|
+
# @example Block-form customizations
|
48
|
+
#
|
49
|
+
# grammar.customize do
|
50
|
+
# element "EnumElement" do
|
51
|
+
# symbol_value
|
52
|
+
# list
|
53
|
+
# end
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
# @example Hash-form customizations
|
57
|
+
#
|
58
|
+
# grammar.customize "EnumElement" => [:symbol_value, :list]
|
59
|
+
#
|
60
|
+
# @return [Grammar] Returns a grammar with the given customizations
|
61
|
+
# applied.
|
62
|
+
#
|
63
|
+
def customize customizations = nil, &block
|
64
|
+
opts = { :inflect_rename => @inflect_rename }
|
65
|
+
self.class.customize(customizations, @rules, opts, &block)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Applies customizations to the current grammar, not returning
|
69
|
+
# a new grammar.
|
70
|
+
def customize! customizations = nil, &block
|
71
|
+
apply_customizations(customizations) if customizations
|
72
|
+
instance_eval(&block) if block_given?
|
73
|
+
self
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.customize customizations = nil, rules = {}, opts = {}, &block
|
77
|
+
grammar = self.new(deep_copy(rules), opts)
|
78
|
+
grammar.send(:apply_customizations, customizations) if customizations
|
79
|
+
grammar.instance_eval(&block) if block_given?
|
80
|
+
grammar
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.parse xml
|
84
|
+
self.new.parse(xml)
|
85
|
+
end
|
86
|
+
|
87
|
+
protected
|
88
|
+
|
89
|
+
# Performs a deep copy of the rules hash so that it can be
|
90
|
+
# customized without chaning the parent grammar.
|
91
|
+
def self.deep_copy rules
|
92
|
+
rules.inject({}) do |copy,(key,value)|
|
93
|
+
copy[key] = value.is_a?(Hash) ? deep_copy(value) : value
|
94
|
+
copy
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def apply_customizations customizations
|
99
|
+
customizations.each do |item|
|
100
|
+
(type, identifier, args) = parse_customization_item(item)
|
101
|
+
case type
|
102
|
+
when :method
|
103
|
+
validate_config_method(identifier)
|
104
|
+
validate_args(identifier, args)
|
105
|
+
send(identifier, *args)
|
106
|
+
when :element
|
107
|
+
element(identifier) do
|
108
|
+
apply_customizations(args)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def parse_customization_item item
|
115
|
+
case item
|
116
|
+
when Symbol
|
117
|
+
[:method, item, []]
|
118
|
+
when Hash
|
119
|
+
(method, arg) = item.to_a.first
|
120
|
+
if method.kind_of?(Symbol)
|
121
|
+
[:method, method, [arg].flatten]
|
122
|
+
else
|
123
|
+
[:element, method, arg]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def validate_config_method(method)
|
129
|
+
allow_methods = %w(
|
130
|
+
rename attribute_name boolean integer long float list force
|
131
|
+
ignore collect_values symbol_value timestamp map_entry map
|
132
|
+
blob string
|
133
|
+
)
|
134
|
+
unless allow_methods.include?(method.to_s)
|
135
|
+
raise "#{method} cannot be used in configuration"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def validate_args(identifier, args)
|
140
|
+
arity = method(identifier).arity
|
141
|
+
if args.length > 0
|
142
|
+
raise "#{identifier} does not accept an argument" if
|
143
|
+
arity == 0
|
144
|
+
else
|
145
|
+
raise "#{identifier} requires an argument" unless
|
146
|
+
arity == 0 || arity == -1
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def inflect value
|
151
|
+
Inflection.ruby_name(value.to_s).to_sym
|
152
|
+
end
|
153
|
+
|
154
|
+
##
|
155
|
+
## customization methods
|
156
|
+
##
|
157
|
+
|
158
|
+
def element element_name, &block
|
159
|
+
|
160
|
+
parent_context = @context
|
161
|
+
parent_element_name = @element_name
|
162
|
+
|
163
|
+
@context = context_for_child(element_name)
|
164
|
+
|
165
|
+
@element_name = element_name
|
166
|
+
|
167
|
+
begin
|
168
|
+
if block_given?
|
169
|
+
block.arity == 1 ? yield(parent_element_name) : yield
|
170
|
+
end
|
171
|
+
ensure
|
172
|
+
@context = parent_context
|
173
|
+
@element_name = parent_element_name
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
def ignore
|
179
|
+
@context[:ignore] = true
|
180
|
+
end
|
181
|
+
|
182
|
+
def rename new_name
|
183
|
+
if @inflect_rename
|
184
|
+
@context[:rename] = inflect(new_name)
|
185
|
+
else
|
186
|
+
@context[:rename] = new_name
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def force
|
191
|
+
@context[:force] = true
|
192
|
+
end
|
193
|
+
|
194
|
+
def collect_values
|
195
|
+
@context[:list] = true
|
196
|
+
end
|
197
|
+
|
198
|
+
def index index_name, options = {}
|
199
|
+
@context[:index] = options.merge(:name => index_name)
|
200
|
+
end
|
201
|
+
|
202
|
+
def default_value name, value
|
203
|
+
@context[:defaults] ||= {}
|
204
|
+
@context[:defaults][name] = value
|
205
|
+
end
|
206
|
+
|
207
|
+
def list child_element_name = nil, &block
|
208
|
+
if child_element_name
|
209
|
+
ignore
|
210
|
+
element(child_element_name) do |parent_element_name|
|
211
|
+
rename(parent_element_name)
|
212
|
+
collect_values
|
213
|
+
yield if block_given?
|
214
|
+
end
|
215
|
+
else
|
216
|
+
collect_values
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
def map_entry key_element_name, value_element_name
|
221
|
+
@context[:map] = [key_element_name, value_element_name]
|
222
|
+
end
|
223
|
+
|
224
|
+
def map map_element_name, key_element_name, value_element_name
|
225
|
+
ignore
|
226
|
+
element(map_element_name) do |parent_element_name|
|
227
|
+
rename(parent_element_name)
|
228
|
+
map_entry(key_element_name, value_element_name)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
def wrapper method_name, options = {}, &block
|
233
|
+
options[:for].each do |child|
|
234
|
+
context_for_child(child)[:wrap] = method_name
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
def construct_value &block
|
239
|
+
raise 'remove the need for this'
|
240
|
+
end
|
241
|
+
|
242
|
+
def boolean_value
|
243
|
+
@context[:type] = :boolean
|
244
|
+
end
|
245
|
+
alias_method :boolean, :boolean_value
|
246
|
+
|
247
|
+
def blob_value
|
248
|
+
@context[:type] = :blob
|
249
|
+
end
|
250
|
+
alias_method :blob, :blob_value
|
251
|
+
|
252
|
+
def datetime_value
|
253
|
+
@context[:type] = :datetime
|
254
|
+
end
|
255
|
+
alias_method :datetime, :datetime_value
|
256
|
+
|
257
|
+
def time_value
|
258
|
+
@context[:type] = :time
|
259
|
+
end
|
260
|
+
alias_method :timestamp, :time_value
|
261
|
+
alias_method :time, :time_value
|
262
|
+
|
263
|
+
def string_value
|
264
|
+
@context[:type] = :string
|
265
|
+
end
|
266
|
+
alias_method :string, :string_value
|
267
|
+
|
268
|
+
def integer_value
|
269
|
+
@context[:type] = :integer
|
270
|
+
end
|
271
|
+
alias_method :integer, :integer_value
|
272
|
+
alias_method :long, :integer_value
|
273
|
+
|
274
|
+
def float_value
|
275
|
+
@context[:type] = :float
|
276
|
+
end
|
277
|
+
alias_method :float, :float_value
|
278
|
+
|
279
|
+
def symbol_value
|
280
|
+
@context[:type] = :symbol
|
281
|
+
end
|
282
|
+
alias_method :symbol, :symbol_value
|
283
|
+
|
284
|
+
def eql? other
|
285
|
+
other.is_a?(Grammar) and self.rules == other.rules
|
286
|
+
end
|
287
|
+
alias_method :==, :eql?
|
288
|
+
|
289
|
+
protected
|
290
|
+
def context_for_child child_element_name
|
291
|
+
@context[:children] ||= {}
|
292
|
+
@context[:children][child_element_name] ||= {}
|
293
|
+
@context[:children][child_element_name]
|
294
|
+
end
|
295
|
+
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
5
|
+
# the License is located at
|
6
|
+
#
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
8
|
+
#
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
12
|
+
# language governing permissions and limitations under the License.
|
13
|
+
|
14
|
+
module AWS
|
15
|
+
module Core
|
16
|
+
module XML
|
17
|
+
class Parser
|
18
|
+
|
19
|
+
# @param [Hash] rules A has of xml parsing rules. Generally
|
20
|
+
# rules will come from an xml grammar.
|
21
|
+
def initialize rules = {}
|
22
|
+
@rules = rules
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [Hash] Returns the rules for this xml parser that define
|
26
|
+
# how it should transform the XMl into Ruby.
|
27
|
+
attr_reader :rules
|
28
|
+
|
29
|
+
# @param [String] xml An XML document string to parse.
|
30
|
+
# @return [Hash] Returns a hash of parsed xml data.
|
31
|
+
def parse xml
|
32
|
+
xml = '<xml/>' if xml.nil? or xml.empty?
|
33
|
+
sax_handler.parse(xml)
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [Hash] Returns a hash of mostly empty placeholder data.
|
37
|
+
def simulate
|
38
|
+
XML::Stub.simulate(rules)
|
39
|
+
end
|
40
|
+
|
41
|
+
# @param [String] xml An XML document string to parse.
|
42
|
+
# @param [Hash] rules A has of xml parsing rules. Generally
|
43
|
+
# rules will come from an xml grammar.
|
44
|
+
# @return [Hash] Returns a hash of parsed xml data.
|
45
|
+
def self.parse xml, rules = {}
|
46
|
+
self.new(rules).parse(xml)
|
47
|
+
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
|
51
|
+
# There are three handlers, nokogiri is the fastest, followed
|
52
|
+
# by libxml-ruby. Lastly (by a long shot) is REXML. REXML
|
53
|
+
# is the only library that does not rely on a native
|
54
|
+
# extension.
|
55
|
+
#
|
56
|
+
# Currently you can not choose your xml sax handler, and the only
|
57
|
+
# we express a gem dependency on is nokogiri.
|
58
|
+
#
|
59
|
+
def sax_handler
|
60
|
+
begin
|
61
|
+
SaxHandlers::Nokogiri.new(rules)
|
62
|
+
rescue NameError, LoadError
|
63
|
+
SaxHandlers::REXML.new(rules)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|