aws-sdk 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/ca-bundle.crt +2 -348
- data/lib/aws.rb +24 -49
- data/lib/aws/{common.rb → core.rb} +120 -9
- data/lib/aws/{api_config.rb → core/api_config.rb} +19 -20
- data/lib/aws/core/api_config_transform.rb +36 -0
- data/lib/aws/core/async_handle.rb +91 -0
- data/lib/aws/core/authorize_v2.rb +39 -0
- data/lib/aws/{authorize_v3.rb → core/authorize_v3.rb} +16 -15
- data/lib/aws/{api_config_transform.rb → core/authorize_with_session_token.rb} +9 -12
- data/lib/aws/core/autoloader.rb +64 -0
- data/lib/aws/core/cacheable.rb +78 -0
- data/lib/aws/core/client.rb +471 -0
- data/lib/aws/core/client_logging.rb +125 -0
- data/lib/aws/core/collections.rb +229 -0
- data/lib/aws/core/configuration.rb +358 -0
- data/lib/aws/core/configured_client_methods.rb +76 -0
- data/lib/aws/core/configured_grammars.rb +63 -0
- data/lib/aws/{configured_option_grammars.rb → core/configured_option_grammars.rb} +18 -20
- data/lib/aws/{configured_xml_grammars.rb → core/configured_xml_grammars.rb} +19 -21
- data/lib/aws/core/default_signer.rb +67 -0
- data/lib/aws/core/http/curb_handler.rb +129 -0
- data/lib/aws/core/http/handler.rb +77 -0
- data/lib/aws/core/http/httparty_handler.rb +113 -0
- data/lib/aws/core/http/net_http_handler.rb +124 -0
- data/lib/aws/core/http/request.rb +207 -0
- data/lib/aws/core/http/response.rb +73 -0
- data/lib/aws/{ignore_result_element.rb → core/ignore_result_element.rb} +14 -18
- data/lib/aws/core/indifferent_hash.rb +88 -0
- data/lib/aws/core/inflection.rb +47 -0
- data/lib/aws/core/lazy_error_classes.rb +62 -0
- data/lib/aws/{uri_escape.rb → core/meta_utils.rb} +24 -23
- data/lib/aws/core/model.rb +57 -0
- data/lib/aws/{authorize_with_session_token.rb → core/naming.rb} +9 -8
- data/lib/aws/core/option_grammar.rb +562 -0
- data/lib/aws/core/policy.rb +914 -0
- data/lib/aws/core/resource.rb +380 -0
- data/lib/aws/core/resource_cache.rb +40 -0
- data/lib/aws/core/response.rb +125 -0
- data/lib/aws/core/response_cache.rb +50 -0
- data/lib/aws/core/service_interface.rb +60 -0
- data/lib/aws/core/uri_escape.rb +46 -0
- data/lib/aws/core/xml_grammar.rb +926 -0
- data/lib/aws/ec2.rb +47 -16
- data/lib/aws/ec2/attachment.rb +0 -2
- data/lib/aws/ec2/attachment_collection.rb +1 -6
- data/lib/aws/ec2/availability_zone.rb +0 -2
- data/lib/aws/ec2/availability_zone_collection.rb +0 -3
- data/lib/aws/ec2/client.rb +6 -9
- data/lib/aws/ec2/client/xml.rb +3 -6
- data/lib/aws/ec2/collection.rb +1 -4
- data/lib/aws/ec2/config.rb +18 -0
- data/lib/aws/ec2/elastic_ip.rb +0 -2
- data/lib/aws/ec2/elastic_ip_collection.rb +0 -4
- data/lib/aws/ec2/errors.rb +1 -4
- data/lib/aws/ec2/has_permissions.rb +0 -2
- data/lib/aws/ec2/image.rb +0 -5
- data/lib/aws/ec2/image_collection.rb +0 -6
- data/lib/aws/ec2/instance.rb +23 -9
- data/lib/aws/ec2/instance_collection.rb +85 -22
- data/lib/aws/ec2/key_pair.rb +0 -2
- data/lib/aws/ec2/key_pair_collection.rb +1 -4
- data/lib/aws/ec2/permission_collection.rb +2 -5
- data/lib/aws/ec2/region.rb +0 -2
- data/lib/aws/ec2/region_collection.rb +0 -4
- data/lib/aws/ec2/request.rb +4 -9
- data/lib/aws/ec2/reserved_instances.rb +0 -3
- data/lib/aws/ec2/reserved_instances_collection.rb +0 -4
- data/lib/aws/ec2/reserved_instances_offering.rb +0 -3
- data/lib/aws/ec2/reserved_instances_offering_collection.rb +0 -4
- data/lib/aws/ec2/resource.rb +3 -5
- data/lib/aws/ec2/resource_tag_collection.rb +1 -6
- data/lib/aws/ec2/security_group.rb +204 -72
- data/lib/aws/ec2/security_group/egress_ip_permission_collection.rb +53 -0
- data/lib/aws/ec2/security_group/ip_permission.rb +92 -10
- data/lib/aws/ec2/security_group/ip_permission_collection.rb +14 -15
- data/lib/aws/ec2/security_group_collection.rb +11 -8
- data/lib/aws/ec2/snapshot.rb +0 -4
- data/lib/aws/ec2/snapshot_collection.rb +0 -4
- data/lib/aws/ec2/tag.rb +0 -3
- data/lib/aws/ec2/tag_collection.rb +1 -8
- data/lib/aws/ec2/tagged_item.rb +1 -3
- data/lib/aws/ec2/volume.rb +0 -6
- data/lib/aws/ec2/volume_collection.rb +0 -4
- data/lib/aws/errors.rb +0 -3
- data/lib/aws/iam.rb +33 -12
- data/lib/aws/iam/access_key.rb +0 -3
- data/lib/aws/iam/access_key_collection.rb +0 -3
- data/lib/aws/iam/account_alias_collection.rb +0 -2
- data/lib/aws/iam/client.rb +6 -8
- data/lib/aws/iam/client/xml.rb +4 -8
- data/lib/aws/iam/collection.rb +2 -5
- data/lib/aws/iam/config.rb +18 -0
- data/lib/aws/iam/errors.rb +2 -4
- data/lib/aws/iam/group.rb +0 -5
- data/lib/aws/iam/group_collection.rb +0 -3
- data/lib/aws/iam/group_policy_collection.rb +0 -2
- data/lib/aws/iam/group_user_collection.rb +1 -4
- data/lib/aws/iam/login_profile.rb +0 -2
- data/lib/aws/iam/mfa_device.rb +1 -3
- data/lib/aws/iam/mfa_device_collection.rb +0 -3
- data/lib/aws/iam/policy.rb +2 -4
- data/lib/aws/iam/policy_collection.rb +0 -3
- data/lib/aws/iam/request.rb +3 -7
- data/lib/aws/iam/resource.rb +1 -4
- data/lib/aws/iam/server_certificate.rb +0 -2
- data/lib/aws/iam/server_certificate_collection.rb +0 -3
- data/lib/aws/iam/signing_certificate.rb +0 -2
- data/lib/aws/iam/signing_certificate_collection.rb +0 -3
- data/lib/aws/iam/user.rb +0 -7
- data/lib/aws/iam/user_collection.rb +0 -3
- data/lib/aws/iam/user_group_collection.rb +0 -3
- data/lib/aws/iam/user_policy.rb +0 -2
- data/lib/aws/iam/user_policy_collection.rb +0 -3
- data/lib/aws/rails.rb +5 -4
- data/lib/aws/record.rb +4 -1
- data/lib/aws/record/base.rb +3 -2
- data/lib/aws/record/errors.rb +1 -3
- data/lib/aws/s3.rb +31 -6
- data/lib/aws/s3/access_control_list.rb +0 -2
- data/lib/aws/s3/acl_object.rb +10 -12
- data/lib/aws/s3/bucket.rb +1 -9
- data/lib/aws/s3/bucket_collection.rb +2 -5
- data/lib/aws/s3/bucket_version_collection.rb +1 -5
- data/lib/aws/s3/client.rb +34 -37
- data/lib/aws/s3/client/xml.rb +11 -14
- data/lib/aws/{resource_cache.rb → s3/config.rb} +6 -20
- data/lib/aws/s3/errors.rb +6 -7
- data/lib/aws/s3/multipart_upload.rb +1 -4
- data/lib/aws/s3/multipart_upload_collection.rb +1 -6
- data/lib/aws/s3/object_collection.rb +1 -5
- data/lib/aws/s3/object_metadata.rb +1 -3
- data/lib/aws/s3/object_upload_collection.rb +1 -7
- data/lib/aws/s3/object_version.rb +1 -4
- data/lib/aws/s3/object_version_collection.rb +1 -4
- data/lib/aws/s3/policy.rb +3 -5
- data/lib/aws/s3/prefix_and_delimiter_collection.rb +0 -2
- data/lib/aws/s3/prefixed_collection.rb +0 -2
- data/lib/aws/s3/presigned_post.rb +1 -3
- data/lib/aws/s3/request.rb +2 -5
- data/lib/aws/s3/s3_object.rb +1 -8
- data/lib/aws/s3/tree.rb +8 -6
- data/lib/aws/s3/tree/branch_node.rb +0 -3
- data/lib/aws/s3/tree/child_collection.rb +1 -5
- data/lib/aws/s3/tree/leaf_node.rb +0 -5
- data/lib/aws/s3/tree/parent.rb +1 -4
- data/lib/aws/s3/uploaded_part.rb +1 -3
- data/lib/aws/s3/uploaded_part_collection.rb +1 -5
- data/lib/aws/simple_db.rb +21 -6
- data/lib/aws/simple_db/attribute.rb +1 -6
- data/lib/aws/simple_db/attribute_collection.rb +1 -7
- data/lib/aws/simple_db/client.rb +7 -9
- data/lib/aws/simple_db/client/options.rb +2 -4
- data/lib/aws/simple_db/client/xml.rb +5 -10
- data/lib/aws/{naming.rb → simple_db/config.rb} +3 -14
- data/lib/aws/simple_db/delete_attributes.rb +0 -2
- data/lib/aws/simple_db/domain.rb +1 -6
- data/lib/aws/simple_db/domain_collection.rb +1 -4
- data/lib/aws/simple_db/domain_metadata.rb +1 -3
- data/lib/aws/simple_db/errors.rb +1 -4
- data/lib/aws/simple_db/item.rb +1 -7
- data/lib/aws/simple_db/item_collection.rb +22 -23
- data/lib/aws/simple_db/put_attributes.rb +0 -2
- data/lib/aws/simple_db/request.rb +3 -7
- data/lib/aws/simple_email_service.rb +11 -6
- data/lib/aws/simple_email_service/client.rb +7 -9
- data/lib/aws/simple_email_service/client/options.rb +3 -6
- data/lib/aws/simple_email_service/client/xml.rb +4 -8
- data/lib/aws/simple_email_service/config.rb +19 -0
- data/lib/aws/simple_email_service/email_address_collection.rb +1 -3
- data/lib/aws/simple_email_service/errors.rb +1 -4
- data/lib/aws/simple_email_service/quotas.rb +1 -3
- data/lib/aws/simple_email_service/request.rb +3 -7
- data/lib/aws/sns.rb +15 -8
- data/lib/aws/sns/client.rb +7 -8
- data/lib/aws/sns/client/options.rb +3 -6
- data/lib/aws/sns/client/xml.rb +4 -8
- data/lib/aws/sns/config.rb +18 -0
- data/lib/aws/sns/errors.rb +1 -4
- data/lib/aws/sns/policy.rb +3 -5
- data/lib/aws/sns/request.rb +4 -9
- data/lib/aws/sns/subscription.rb +1 -5
- data/lib/aws/sns/subscription_collection.rb +1 -5
- data/lib/aws/sns/topic.rb +1 -6
- data/lib/aws/sns/topic_collection.rb +1 -4
- data/lib/aws/sns/topic_subscription_collection.rb +1 -4
- data/lib/aws/sqs.rb +14 -5
- data/lib/aws/sqs/client.rb +6 -9
- data/lib/aws/sqs/client/xml.rb +4 -7
- data/lib/aws/sqs/config.rb +18 -0
- data/lib/aws/sqs/errors.rb +1 -4
- data/lib/aws/sqs/policy.rb +3 -5
- data/lib/aws/sqs/queue.rb +2 -7
- data/lib/aws/sqs/queue_collection.rb +4 -5
- data/lib/aws/sqs/received_message.rb +1 -3
- data/lib/aws/sqs/received_sns_message.rb +2 -2
- data/lib/aws/sqs/request.rb +4 -7
- data/lib/aws/sts.rb +12 -6
- data/lib/aws/sts/client.rb +6 -8
- data/lib/aws/sts/client/xml.rb +4 -8
- data/lib/aws/sts/config.rb +18 -0
- data/lib/aws/sts/errors.rb +1 -4
- data/lib/aws/sts/federated_session.rb +0 -2
- data/lib/aws/sts/policy.rb +3 -5
- data/lib/aws/sts/request.rb +3 -7
- metadata +60 -50
- data/lib/aws/async_handle.rb +0 -90
- data/lib/aws/authorize_v2.rb +0 -37
- data/lib/aws/base_client.rb +0 -488
- data/lib/aws/cacheable.rb +0 -79
- data/lib/aws/client_logging.rb +0 -122
- data/lib/aws/collections.rb +0 -230
- data/lib/aws/configuration.rb +0 -357
- data/lib/aws/configured_client_methods.rb +0 -81
- data/lib/aws/configured_grammars.rb +0 -65
- data/lib/aws/default_signer.rb +0 -65
- data/lib/aws/http/curb_handler.rb +0 -127
- data/lib/aws/http/handler.rb +0 -77
- data/lib/aws/http/httparty_handler.rb +0 -103
- data/lib/aws/http/request.rb +0 -165
- data/lib/aws/http/request_param.rb +0 -64
- data/lib/aws/http/response.rb +0 -72
- data/lib/aws/indifferent_hash.rb +0 -86
- data/lib/aws/inflection.rb +0 -46
- data/lib/aws/lazy_error_classes.rb +0 -64
- data/lib/aws/meta_utils.rb +0 -43
- data/lib/aws/model.rb +0 -57
- data/lib/aws/option_grammar.rb +0 -565
- data/lib/aws/policy.rb +0 -914
- data/lib/aws/resource.rb +0 -381
- data/lib/aws/response.rb +0 -125
- data/lib/aws/response_cache.rb +0 -50
- data/lib/aws/service_interface.rb +0 -60
- data/lib/aws/xml_grammar.rb +0 -925
data/lib/aws/resource.rb
DELETED
@@ -1,381 +0,0 @@
|
|
1
|
-
|
2
|
-
# Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
5
|
-
# may not use this file except in compliance with the License. A copy of
|
6
|
-
# the License is located at
|
7
|
-
#
|
8
|
-
# http://aws.amazon.com/apache2.0/
|
9
|
-
#
|
10
|
-
# or in the "license" file accompanying this file. This file is
|
11
|
-
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
12
|
-
# ANY KIND, either express or implied. See the License for the specific
|
13
|
-
# language governing permissions and limitations under the License.
|
14
|
-
|
15
|
-
require 'aws/model'
|
16
|
-
require 'aws/cacheable'
|
17
|
-
|
18
|
-
module AWS
|
19
|
-
|
20
|
-
# @private
|
21
|
-
class Resource
|
22
|
-
|
23
|
-
include Model
|
24
|
-
include Cacheable
|
25
|
-
|
26
|
-
# @private
|
27
|
-
class NotFound < StandardError; end
|
28
|
-
|
29
|
-
def initialize *args
|
30
|
-
|
31
|
-
super
|
32
|
-
|
33
|
-
# cache static attributes passed into options
|
34
|
-
|
35
|
-
options = args.last.is_a?(Hash) ? args.last : {}
|
36
|
-
options.each_pair do |opt_name,opt_value|
|
37
|
-
if
|
38
|
-
self.class.attributes.has_key?(opt_name) and
|
39
|
-
self.class.attributes[opt_name].static?
|
40
|
-
then
|
41
|
-
static_attributes[opt_name] = opt_value
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
# @return [String] Returns a simple string representation of this resource.
|
48
|
-
def inspect
|
49
|
-
|
50
|
-
identifiers = []
|
51
|
-
resource_identifiers.each do |key, value|
|
52
|
-
if attr = self.class.attributes.values.find{|a| a.get_as == key }
|
53
|
-
identifiers << "#{attr.name}:#{value}"
|
54
|
-
else
|
55
|
-
identifiers << "#{key}:#{value}"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
"<#{self::class} #{identifiers.join(' ')}>"
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
# @return [Boolean] Returns true if the objects references the same
|
64
|
-
# AWS resource.
|
65
|
-
def == other
|
66
|
-
other.kind_of?(self.class) and
|
67
|
-
resource_identifiers == other.resource_identifiers
|
68
|
-
end
|
69
|
-
|
70
|
-
alias_method :eql?, :==
|
71
|
-
|
72
|
-
# @private
|
73
|
-
protected
|
74
|
-
def get_resource attr_name
|
75
|
-
raise NotImplementedError
|
76
|
-
end
|
77
|
-
|
78
|
-
# @private
|
79
|
-
protected
|
80
|
-
def update_resource attr, value
|
81
|
-
raise NotImplementedError
|
82
|
-
end
|
83
|
-
|
84
|
-
# Overide this method is subclasses of Resource. This method should
|
85
|
-
# return an array of identifying key/value pairs.
|
86
|
-
#
|
87
|
-
# # @private
|
88
|
-
# protected
|
89
|
-
# def resource_identifiers
|
90
|
-
# [[:user_name, name]]
|
91
|
-
# end
|
92
|
-
#
|
93
|
-
# @private
|
94
|
-
protected
|
95
|
-
def resource_identifiers
|
96
|
-
raise NotImplementedError
|
97
|
-
end
|
98
|
-
|
99
|
-
# @protected
|
100
|
-
protected
|
101
|
-
def resource_options(additional = {})
|
102
|
-
Hash[resource_identifiers].merge(additional)
|
103
|
-
end
|
104
|
-
|
105
|
-
# @private
|
106
|
-
protected
|
107
|
-
def local_cache_key
|
108
|
-
resource_identifiers.collect{|name,value| value.to_s }.join(":")
|
109
|
-
end
|
110
|
-
|
111
|
-
# @private
|
112
|
-
protected
|
113
|
-
def static_attributes
|
114
|
-
@static_attributes ||= {}
|
115
|
-
end
|
116
|
-
|
117
|
-
# @private
|
118
|
-
protected
|
119
|
-
def ruby_name
|
120
|
-
@ruby_name ||= Inflection.ruby_name(self.class.name)
|
121
|
-
end
|
122
|
-
|
123
|
-
# @private
|
124
|
-
public
|
125
|
-
def attributes_from_response resp
|
126
|
-
|
127
|
-
attributes = {}
|
128
|
-
|
129
|
-
self.class.attribute_providers_for(resp.request_type).each do |provider|
|
130
|
-
attributes.merge!(provider.attributes_from_response(self, resp))
|
131
|
-
end
|
132
|
-
|
133
|
-
# cache static attributes
|
134
|
-
attributes.each do |attr_name,value|
|
135
|
-
if self.class.attributes[attr_name].static?
|
136
|
-
static_attributes[attr_name] = value
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
attributes.empty? ? nil : attributes
|
141
|
-
|
142
|
-
end
|
143
|
-
|
144
|
-
# @private
|
145
|
-
protected
|
146
|
-
def cache_static_attributes request_type, resp_obj
|
147
|
-
self.class.attribute_providers_for(request_type).each do |provider|
|
148
|
-
attributes = provider.attributes_from_response_object(resp_obj)
|
149
|
-
attributes.each_pair do |attr_name,value|
|
150
|
-
if self.class.attributes[attr_name].static?
|
151
|
-
static_attributes[attr_name] = value
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
|
158
|
-
class << self
|
159
|
-
|
160
|
-
# @private
|
161
|
-
def new_from request_type, resp_obj, *args
|
162
|
-
resource = new(*args)
|
163
|
-
resource.send(:cache_static_attributes, request_type, resp_obj)
|
164
|
-
resource
|
165
|
-
end
|
166
|
-
|
167
|
-
# @private
|
168
|
-
def attributes
|
169
|
-
@attributes ||= Hash.new do |hash,attr_name|
|
170
|
-
raise "uknown attribute #{attr_name}"
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
# @private
|
175
|
-
def attribute_providers
|
176
|
-
@attribute_providers ||= []
|
177
|
-
end
|
178
|
-
|
179
|
-
# @private
|
180
|
-
def attribute_providers_for request_type
|
181
|
-
attribute_providers.select do |provider|
|
182
|
-
provider.request_types.include?(request_type)
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
# @private
|
187
|
-
protected
|
188
|
-
def attribute name, options = {}, &block
|
189
|
-
attr = Attribute.new(name, options)
|
190
|
-
attr.instance_eval(&block) if block_given?
|
191
|
-
define_attribute_getter(attr)
|
192
|
-
define_attribute_setter(attr) if attr.mutable?
|
193
|
-
attributes[attr.name] = attr
|
194
|
-
end
|
195
|
-
|
196
|
-
# @private
|
197
|
-
protected
|
198
|
-
def mutable_attribute name, options = {}, &block
|
199
|
-
attribute(name, options.merge(:mutable => true), &block)
|
200
|
-
end
|
201
|
-
|
202
|
-
# @private
|
203
|
-
protected
|
204
|
-
def define_attribute_getter attribute
|
205
|
-
define_method(attribute.name) do
|
206
|
-
|
207
|
-
return static_attributes[attribute.name] if
|
208
|
-
static_attributes.has_key?(attribute.name)
|
209
|
-
|
210
|
-
begin
|
211
|
-
retrieve_attribute(attribute) { get_resource(attribute) }
|
212
|
-
rescue Cacheable::NoData => e
|
213
|
-
name = ruby_name.tr("_", " ")
|
214
|
-
raise NotFound, "unable to find the #{name}"
|
215
|
-
end
|
216
|
-
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
# @private
|
221
|
-
protected
|
222
|
-
def define_attribute_setter attribute
|
223
|
-
setter = attribute.name.to_s.sub(/\?/, '') + '='
|
224
|
-
define_method(setter) do |value|
|
225
|
-
translated_value = attribute.translate_input_value(value)
|
226
|
-
update_resource(attribute, translated_value)
|
227
|
-
if attribute.static?
|
228
|
-
static_attributes[attribute.name] = translated_value
|
229
|
-
end
|
230
|
-
value
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
# @private
|
235
|
-
protected
|
236
|
-
def populates_from *request_types, &block
|
237
|
-
provider = provider(*request_types)
|
238
|
-
provider.find(&block)
|
239
|
-
provider.provides(*attributes.keys)
|
240
|
-
provider
|
241
|
-
end
|
242
|
-
|
243
|
-
# @private
|
244
|
-
protected
|
245
|
-
def provider *request_types, &block
|
246
|
-
provider = AttributeProvider.new(self, request_types)
|
247
|
-
if block_given?
|
248
|
-
yield(provider)
|
249
|
-
end
|
250
|
-
attribute_providers << provider
|
251
|
-
provider
|
252
|
-
end
|
253
|
-
|
254
|
-
end
|
255
|
-
|
256
|
-
# @private
|
257
|
-
class Attribute
|
258
|
-
|
259
|
-
def initialize name, options = {}
|
260
|
-
@name = name
|
261
|
-
@options = options
|
262
|
-
@request_types = []
|
263
|
-
end
|
264
|
-
|
265
|
-
attr_reader :name
|
266
|
-
|
267
|
-
attr_reader :request_types
|
268
|
-
|
269
|
-
def get_as
|
270
|
-
@get_as ||= (@options[:get_as] || @options[:as] || name)
|
271
|
-
end
|
272
|
-
|
273
|
-
def set_as
|
274
|
-
@set_as ||= (@options[:set_as] || @options[:as] || name)
|
275
|
-
end
|
276
|
-
|
277
|
-
def mutable?
|
278
|
-
@options[:mutable] == true
|
279
|
-
end
|
280
|
-
|
281
|
-
def static?
|
282
|
-
@options[:static] == true
|
283
|
-
end
|
284
|
-
|
285
|
-
def translates_input &block
|
286
|
-
@input_translator = block
|
287
|
-
end
|
288
|
-
|
289
|
-
def translates_output options = {}, &block
|
290
|
-
@translates_nil = options[:nil]
|
291
|
-
@output_translator = block
|
292
|
-
end
|
293
|
-
|
294
|
-
def translate_input_value value
|
295
|
-
@input_translator ? @input_translator.call(value) : value
|
296
|
-
end
|
297
|
-
|
298
|
-
def translate_output_value value
|
299
|
-
|
300
|
-
# by default nil values are not translated
|
301
|
-
return nil if value.nil? and @translates_nil != true
|
302
|
-
|
303
|
-
case
|
304
|
-
when @options[:to_sym] then value.tr('-','_').downcase.to_sym
|
305
|
-
when @output_translator then @output_translator.call(value)
|
306
|
-
else value
|
307
|
-
end
|
308
|
-
|
309
|
-
end
|
310
|
-
|
311
|
-
end
|
312
|
-
|
313
|
-
# @private
|
314
|
-
class AttributeProvider
|
315
|
-
|
316
|
-
def initialize klass, request_types
|
317
|
-
@klass = klass
|
318
|
-
@id = klass.attribute_providers.length
|
319
|
-
@request_types = request_types
|
320
|
-
@provides = {}
|
321
|
-
end
|
322
|
-
|
323
|
-
attr_reader :request_types
|
324
|
-
|
325
|
-
def find &block
|
326
|
-
@klass.send(:define_method, finder_method, &block)
|
327
|
-
end
|
328
|
-
|
329
|
-
def finder_method
|
330
|
-
"find_in_response_#{@id}"
|
331
|
-
end
|
332
|
-
|
333
|
-
# Indicates that all of the the named attributes can be retrieved
|
334
|
-
# from an appropriate response object.
|
335
|
-
#
|
336
|
-
# @param [Symbol] attr_names A list of attributes provided
|
337
|
-
# @param [Hash] options
|
338
|
-
# @option options [Boolean] :value_wrapped (false) If true, then
|
339
|
-
# the value returned by the response object will also receive
|
340
|
-
# the message :value before it is translated and returned.
|
341
|
-
# @option options [Symbol] :get_as Defaults to the method named
|
342
|
-
# by the attribute. This is useful when you have two providers
|
343
|
-
# for the same attribute but their response object name
|
344
|
-
# them differently.
|
345
|
-
def provides *attr_names
|
346
|
-
options = attr_names.last.is_a?(Hash) ? attr_names.pop : {}
|
347
|
-
attr_names.each do |attr_name|
|
348
|
-
attr = @klass.attributes[attr_name]
|
349
|
-
attr.request_types.push(*request_types)
|
350
|
-
@provides[attr_name] = options
|
351
|
-
end
|
352
|
-
end
|
353
|
-
|
354
|
-
def attributes_from_response resource, response
|
355
|
-
if response_object = resource.send(finder_method, response)
|
356
|
-
attributes_from_response_object(response_object)
|
357
|
-
else
|
358
|
-
{}
|
359
|
-
end
|
360
|
-
end
|
361
|
-
|
362
|
-
def attributes_from_response_object resp_obj
|
363
|
-
attributes = {}
|
364
|
-
@provides.each do |attr_name, options|
|
365
|
-
|
366
|
-
attr = @klass.attributes[attr_name]
|
367
|
-
method = options[:get_as] || attr.get_as
|
368
|
-
|
369
|
-
v = resp_obj.respond_to?(method) ? resp_obj.send(method) : nil
|
370
|
-
v = v.value if v and options[:value_wrapped]
|
371
|
-
v = attr.translate_output_value(v)
|
372
|
-
|
373
|
-
attributes[attr_name] = v
|
374
|
-
|
375
|
-
end
|
376
|
-
attributes
|
377
|
-
end
|
378
|
-
|
379
|
-
end
|
380
|
-
end
|
381
|
-
end
|
data/lib/aws/response.rb
DELETED
@@ -1,125 +0,0 @@
|
|
1
|
-
# Copyright 2011 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
|
-
require 'aws/async_handle'
|
15
|
-
|
16
|
-
module AWS
|
17
|
-
|
18
|
-
# @private
|
19
|
-
class Response
|
20
|
-
|
21
|
-
include AsyncHandle
|
22
|
-
|
23
|
-
# @return [AWS::Error] Returns nil unless the request failed.
|
24
|
-
# Normally this will be nil unless you are using the Asynchronous
|
25
|
-
# interface.
|
26
|
-
attr_accessor :error
|
27
|
-
|
28
|
-
# @return [Hash] The hash of options passed to the low level request
|
29
|
-
# method that generated this response.
|
30
|
-
attr_accessor :request_options
|
31
|
-
|
32
|
-
# @return [Symbol] The low-level request method that generated
|
33
|
-
# this response
|
34
|
-
attr_accessor :request_type
|
35
|
-
|
36
|
-
# @return [Http::Request] the HTTP request object
|
37
|
-
attr_accessor :http_request
|
38
|
-
|
39
|
-
# @return [Http::Response] the HTTP response object
|
40
|
-
attr_accessor :http_response
|
41
|
-
|
42
|
-
# @return [Boolean] true if the response is cached
|
43
|
-
attr_accessor :cached
|
44
|
-
|
45
|
-
# @param [Http::Request] http_request
|
46
|
-
# @param [Http::Response] http_request
|
47
|
-
def initialize http_request = nil, http_response = nil, &block
|
48
|
-
@http_request = http_request
|
49
|
-
@http_response = http_response
|
50
|
-
@request_builder = block
|
51
|
-
rebuild_request if @request_builder && !http_request
|
52
|
-
end
|
53
|
-
|
54
|
-
# Rebuilds the HTTP request using the block passed to the initializer
|
55
|
-
def rebuild_request
|
56
|
-
@http_request = @request_builder.call
|
57
|
-
end
|
58
|
-
|
59
|
-
# @return [Boolean] Returns true unless there is a response error.
|
60
|
-
def successful?
|
61
|
-
error.nil?
|
62
|
-
end
|
63
|
-
|
64
|
-
# @return [Boolean] Returns true if the http request was throttled
|
65
|
-
# by AWS.
|
66
|
-
def throttled?
|
67
|
-
!successful? and
|
68
|
-
http_response.body and
|
69
|
-
parsed_body = XmlGrammar.parse(http_response.body) and
|
70
|
-
parsed_body.respond_to?(:code) and
|
71
|
-
parsed_body.code == "Throttling"
|
72
|
-
end
|
73
|
-
|
74
|
-
# @return [Boolean] Returns true if the http request timed out.
|
75
|
-
def timeout?
|
76
|
-
http_response.timeout?
|
77
|
-
end
|
78
|
-
|
79
|
-
# @private
|
80
|
-
def inspect
|
81
|
-
if request_type
|
82
|
-
"<#{self.class}:#{request_type}>"
|
83
|
-
else
|
84
|
-
"<#{self.class}>"
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def cache_key
|
89
|
-
[http_request.access_key_id,
|
90
|
-
http_request.host,
|
91
|
-
request_type,
|
92
|
-
serialized_options].join(":")
|
93
|
-
end
|
94
|
-
|
95
|
-
def serialized_options
|
96
|
-
serialize_options_hash(request_options)
|
97
|
-
end
|
98
|
-
|
99
|
-
private
|
100
|
-
def serialize_options_hash(hash)
|
101
|
-
"(" + hash.keys.sort_by(&:to_s).map do |key|
|
102
|
-
"#{key}=#{serialize_options_value(hash[key])}"
|
103
|
-
end.join(" ") + ")"
|
104
|
-
end
|
105
|
-
|
106
|
-
private
|
107
|
-
def serialize_options_value(value)
|
108
|
-
case value
|
109
|
-
when Hash
|
110
|
-
serialize_options_hash(value)
|
111
|
-
when Array
|
112
|
-
serialize_options_array(value)
|
113
|
-
else
|
114
|
-
value.inspect
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
private
|
119
|
-
def serialize_options_array(ary)
|
120
|
-
"[" + ary.map { |v| serialize_options_value(v) }.join(" ") +
|
121
|
-
"]"
|
122
|
-
end
|
123
|
-
|
124
|
-
end
|
125
|
-
end
|