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
@@ -15,7 +15,10 @@ module AWS
|
|
15
15
|
module Core
|
16
16
|
module Http
|
17
17
|
|
18
|
-
# Base class for all service reqeusts.
|
18
|
+
# Base class for all service reqeusts. This class describes
|
19
|
+
# a basic HTTP request, but will not make one. It is consumed
|
20
|
+
# by a HTTP handler class that sends the actual request
|
21
|
+
# and parses the actual response.
|
19
22
|
class Request
|
20
23
|
|
21
24
|
# Returns a new empty http request object.
|
@@ -67,9 +70,9 @@ module AWS
|
|
67
70
|
# to be populated for requests against signature v4 endpoints.
|
68
71
|
attr_accessor :region
|
69
72
|
|
70
|
-
# @param [Boolean]
|
71
|
-
def use_ssl=
|
72
|
-
@use_ssl =
|
73
|
+
# @param [Boolean] state If the request should be sent over ssl or not.
|
74
|
+
def use_ssl= state
|
75
|
+
@use_ssl = state
|
73
76
|
end
|
74
77
|
|
75
78
|
# @return [Boolean] If this request should be sent over ssl or not.
|
@@ -16,53 +16,75 @@ require 'thread'
|
|
16
16
|
module AWS
|
17
17
|
module Core
|
18
18
|
|
19
|
-
#
|
19
|
+
# Provides lazy creation of error classes via {#const_missing}.
|
20
|
+
#
|
21
|
+
# Extend this module provides 3 benefits to another module:
|
22
|
+
#
|
23
|
+
# * A method that accepts strings and returns error classes.
|
24
|
+
# * Thread-safe dynamic error class creation via {#const_missing}
|
25
|
+
# * An error grammar for parsing AWS xml errors
|
26
|
+
#
|
27
|
+
# Here is an example of how it works:
|
28
|
+
#
|
29
|
+
# Class Foo
|
30
|
+
# module Errors
|
31
|
+
# extend AWS::Core::LazyErrorClasses
|
32
|
+
# end
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# Foo::Errors.error_class('NoSuchKey')
|
36
|
+
# #=> Foo::Errors::NoSuckKey
|
37
|
+
#
|
38
|
+
# Foo::Errors.error_class('Nested.Error.Klasses')
|
39
|
+
# #=> Foo::Errors::Nested::Error::Klasses
|
40
|
+
#
|
41
|
+
# The errors returned from {#error_class} are subclasses
|
42
|
+
# of {AWS::Errors::Base}.
|
43
|
+
#
|
20
44
|
module LazyErrorClasses
|
21
|
-
|
22
|
-
# @private
|
23
|
-
module ClassMethods
|
24
|
-
|
25
|
-
def const_missing(name)
|
26
|
-
base_error_grammar = self::BASE_ERROR_GRAMMAR
|
27
|
-
mod = self::ERROR_MODULE
|
28
|
-
const_missing_mutex.synchronize do
|
29
|
-
const_set(name,
|
30
|
-
Class.new(self::Base) do
|
31
|
-
include mod::ModeledError
|
32
45
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def error_class(code)
|
42
|
-
module_eval("#{self}::#{code.gsub('.Range','Range').gsub(".","::")}")
|
46
|
+
# This grammar parses the defualt AWS XML error format
|
47
|
+
BASE_ERROR_GRAMMAR = XML::Grammar.customize do
|
48
|
+
element("Error") do
|
49
|
+
ignore
|
43
50
|
end
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
51
|
+
end
|
52
|
+
|
53
|
+
# @private
|
54
|
+
def self.extended base
|
55
|
+
|
56
|
+
unless base.const_defined?(:GRAMMAR)
|
57
|
+
base.const_set(:GRAMMAR, BASE_ERROR_GRAMMAR)
|
49
58
|
end
|
50
|
-
|
59
|
+
|
60
|
+
mutex = Mutex.new
|
61
|
+
MetaUtils.extend_method(base, :const_missing_mutex) { mutex }
|
62
|
+
|
51
63
|
end
|
52
64
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
65
|
+
# Defines a new error class.
|
66
|
+
# @param [String,Symbol] constant
|
67
|
+
# @return [nil]
|
68
|
+
def const_missing constant
|
69
|
+
const_missing_mutex.synchronize do
|
70
|
+
const_set(constant, Class.new(Errors::Base) { extend LazyErrorClasses })
|
59
71
|
end
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
72
|
+
end
|
73
|
+
|
74
|
+
# Converts the error code into an error class constant.
|
75
|
+
#
|
76
|
+
# AWS::EC2::Errors.error_class('Non.Existent.Error')
|
77
|
+
# #=> AWS::EC2::Errors::Non::Existent::Error
|
78
|
+
#
|
79
|
+
# @param [String] code An AWS error code.
|
80
|
+
#
|
81
|
+
# @return [Class] Returns the error class defiend by the error code.
|
82
|
+
#
|
83
|
+
def error_class code
|
84
|
+
module_eval("#{self}::#{code.gsub('.Range','Range').gsub(".","::")}")
|
64
85
|
end
|
65
86
|
|
66
87
|
end
|
88
|
+
|
67
89
|
end
|
68
90
|
end
|
data/lib/aws/core/policy.rb
CHANGED
@@ -354,7 +354,7 @@ module AWS
|
|
354
354
|
# http://docs.amazonwebservices.com/AmazonS3/latest/dev/UsingResOpsConditions.html
|
355
355
|
# for a list of the available keys for each action in S3.
|
356
356
|
#
|
357
|
-
# @param
|
357
|
+
# @param [Mixed] values The value to compare against.
|
358
358
|
# This can be:
|
359
359
|
# * a String
|
360
360
|
# * a number
|
@@ -362,6 +362,7 @@ module AWS
|
|
362
362
|
# * a boolean value
|
363
363
|
# This method does not attempt to validate that the values
|
364
364
|
# are valid for the operators or keys they are used with.
|
365
|
+
#
|
365
366
|
def add(operator, key, *values)
|
366
367
|
if operator.kind_of?(Symbol)
|
367
368
|
converted_values = values.map { |v| convert_value(v) }
|
data/lib/aws/core/resource.rb
CHANGED
@@ -121,21 +121,31 @@ module AWS
|
|
121
121
|
# @private
|
122
122
|
public
|
123
123
|
def attributes_from_response resp
|
124
|
-
|
125
|
-
|
126
|
-
|
124
|
+
|
125
|
+
# check each provider for this request type to see if it
|
126
|
+
# can find the resource and some of its attributes
|
127
|
+
attributes = []
|
127
128
|
self.class.attribute_providers_for(resp.request_type).each do |provider|
|
128
|
-
attributes
|
129
|
+
attributes << provider.attributes_from_response(self, resp)
|
129
130
|
end
|
131
|
+
|
132
|
+
# drop out those that returned no attributesj
|
133
|
+
attributes.compact!
|
134
|
+
|
135
|
+
# stop here if nothing was found for this resource
|
136
|
+
return nil if attributes.empty?
|
137
|
+
|
138
|
+
# merge the attributes together into a single hash
|
139
|
+
attributes = attributes.inject({}) {|hash,attribs| hash.merge(attribs) }
|
130
140
|
|
131
141
|
# cache static attributes
|
132
|
-
attributes.
|
142
|
+
attributes.each_pair do |attr_name,value|
|
133
143
|
if self.class.attributes[attr_name].static?
|
134
144
|
static_attributes[attr_name] = value
|
135
145
|
end
|
136
146
|
end
|
137
|
-
|
138
|
-
attributes
|
147
|
+
|
148
|
+
attributes
|
139
149
|
|
140
150
|
end
|
141
151
|
|
@@ -347,15 +357,16 @@ module AWS
|
|
347
357
|
# Indicates that all of the the named attributes can be retrieved
|
348
358
|
# from an appropriate response object.
|
349
359
|
#
|
350
|
-
# @
|
351
|
-
#
|
352
|
-
#
|
353
|
-
#
|
354
|
-
#
|
355
|
-
#
|
356
|
-
#
|
357
|
-
#
|
358
|
-
#
|
360
|
+
# @overload provides(*attr_names, options = {})
|
361
|
+
# @param [Symbol] attr_names A list of attributes provided
|
362
|
+
# @param [Hash] options
|
363
|
+
# @option options [Boolean] :value_wrapped (false) If true, then
|
364
|
+
# the value returned by the response object will also receive
|
365
|
+
# the message :value before it is translated and returned.
|
366
|
+
# @option options [Symbol] :get_as Defaults to the method named
|
367
|
+
# by the attribute. This is useful when you have two providers
|
368
|
+
# for the same attribute but their response object name
|
369
|
+
# them differently.
|
359
370
|
def provides *attr_names
|
360
371
|
options = attr_names.last.is_a?(Hash) ? attr_names.pop : {}
|
361
372
|
attr_names.each do |attr_name|
|
@@ -369,32 +380,26 @@ module AWS
|
|
369
380
|
if response_object = resource.send(finder_method, response)
|
370
381
|
attributes_from_response_object(response_object)
|
371
382
|
else
|
372
|
-
|
383
|
+
nil
|
373
384
|
end
|
374
385
|
end
|
375
386
|
|
376
387
|
def attributes_from_response_object resp_obj
|
377
|
-
|
378
|
-
@provides.
|
379
|
-
|
388
|
+
|
389
|
+
@provides.inject({}) do |attributes,(attr_name,options)|
|
390
|
+
|
380
391
|
attr = @klass.attributes[attr_name]
|
392
|
+
|
381
393
|
method = options[:get_as] || attr.get_as
|
382
394
|
|
383
|
-
v =
|
384
|
-
|
385
|
-
resp_obj[method.to_s]
|
386
|
-
when resp_obj.respond_to?(method)
|
387
|
-
resp_obj.send(method)
|
388
|
-
else
|
389
|
-
nil
|
390
|
-
end
|
391
|
-
v = v.value if v and options[:value_wrapped]
|
395
|
+
v = resp_obj.key?(method) ? resp_obj[method] : resp_obj[method.to_s]
|
396
|
+
v = v[:value] if v and options[:value_wrapped]
|
392
397
|
v = attr.translate_output_value(v)
|
393
|
-
|
394
|
-
attributes
|
395
|
-
|
398
|
+
|
399
|
+
attributes.merge(attr_name => v)
|
400
|
+
|
396
401
|
end
|
397
|
-
|
402
|
+
|
398
403
|
end
|
399
404
|
|
400
405
|
end
|
data/lib/aws/core/response.rb
CHANGED
@@ -14,33 +14,76 @@
|
|
14
14
|
module AWS
|
15
15
|
module Core
|
16
16
|
|
17
|
-
#
|
17
|
+
# = Response
|
18
|
+
#
|
19
|
+
# Each service request returns a response object. Responses provide
|
20
|
+
# access to response data and request/response metadata.
|
21
|
+
#
|
22
|
+
# == Response Data
|
23
|
+
#
|
24
|
+
# Each response has a hash of data that represents the data
|
25
|
+
# returned by the service. You can get at this data by
|
26
|
+
# calling {#data} (you can also use the {#[]} method as a shortcut)
|
27
|
+
#
|
28
|
+
# # make a request to describe one instance
|
29
|
+
# ec2 = AWS::EC2.new
|
30
|
+
# response = ec2.client.describe_instances(:instance_ids => ['i-12345678'])
|
31
|
+
#
|
32
|
+
# # find the instance in the response data (2 ways to get the data)
|
33
|
+
# instance = response[:reservation_set].first[:instance_set].first
|
34
|
+
# instance = response.data[:reservation_set].first[:instance_set].first
|
35
|
+
#
|
36
|
+
# instance[:status] #=> 'running'
|
37
|
+
#
|
38
|
+
# == Response Metadata
|
39
|
+
#
|
40
|
+
# In addition to the response data, there is additional information
|
41
|
+
# available with the response, including:
|
42
|
+
#
|
43
|
+
# * the name of the client request method called
|
44
|
+
# * the hash of options passed to the client request
|
45
|
+
# * the HTTP request object (useful for debugging)
|
46
|
+
# * the HTTP response object (useful for debugging)
|
47
|
+
#
|
48
|
+
# Given the example and response object from above:
|
49
|
+
#
|
50
|
+
# response.request_type #=> :describe_instances
|
51
|
+
# response.request_options #=> { :instance_ids => ['i-12345678'] }
|
52
|
+
# response.http_request #=> #<AWS::Core::Http::Request>
|
53
|
+
# response.http_response #=> #<AWS::Core::Http::Response>
|
54
|
+
#
|
18
55
|
class Response
|
19
56
|
|
20
57
|
include AsyncHandle
|
58
|
+
|
59
|
+
# @return [Hash] Returns the response data as a hash.
|
60
|
+
attr_accessor :data
|
21
61
|
|
22
|
-
# @return [
|
23
|
-
#
|
24
|
-
|
25
|
-
attr_accessor :error
|
62
|
+
# @return [Symbol] The name of the client request method that
|
63
|
+
# returned this response.
|
64
|
+
attr_accessor :request_type
|
26
65
|
|
27
|
-
# @return [Hash]
|
28
|
-
# method that generated this response.
|
66
|
+
# @return [Hash] Returns the hash of options passed to the client
|
67
|
+
# request method that generated this response.
|
29
68
|
attr_accessor :request_options
|
30
|
-
|
31
|
-
# @return [Symbol] The low-level request method that generated
|
32
|
-
# this response
|
33
|
-
attr_accessor :request_type
|
34
69
|
|
35
|
-
# @return [Http::Request]
|
70
|
+
# @return [Core::Http::Request]
|
36
71
|
attr_accessor :http_request
|
37
72
|
|
38
|
-
# @return [Http::Response]
|
73
|
+
# @return [Core::Http::Response]
|
39
74
|
attr_accessor :http_response
|
40
75
|
|
41
|
-
# @return [Boolean] true if the response
|
76
|
+
# @return [Boolean] true if the response was generated from a
|
77
|
+
# another cached response.
|
42
78
|
attr_accessor :cached
|
43
79
|
|
80
|
+
alias_method :cached?, :cached
|
81
|
+
|
82
|
+
# @return [AWS::Error,nil] Returns nil unless the request failed.
|
83
|
+
# Normally this will be nil unless you are using the Asynchronous
|
84
|
+
# interface.
|
85
|
+
attr_accessor :error
|
86
|
+
|
44
87
|
# @return [Integer] Returns the number of times the request
|
45
88
|
# was retried.
|
46
89
|
attr_accessor :retry_count
|
@@ -50,22 +93,27 @@ module AWS
|
|
50
93
|
attr_accessor :duration
|
51
94
|
|
52
95
|
# @param [Http::Request] http_request
|
53
|
-
# @param [Http::Response]
|
96
|
+
# @param [Http::Response] http_response
|
54
97
|
def initialize http_request = nil, http_response = nil, &block
|
55
98
|
@http_request = http_request
|
56
99
|
@http_response = http_response
|
57
100
|
@request_builder = block
|
101
|
+
@data = {}
|
58
102
|
@retry_count = 0
|
59
103
|
@duration = 0
|
60
104
|
rebuild_request if @request_builder && !http_request
|
61
105
|
end
|
62
|
-
|
63
|
-
#
|
64
|
-
|
65
|
-
|
106
|
+
|
107
|
+
# Provides access to the response data. This is a short-cut
|
108
|
+
# for calling +response.data[key]+.
|
109
|
+
#
|
110
|
+
# @param [Symbol,String] key
|
111
|
+
# @return [Hash,nil]
|
112
|
+
def [] key
|
113
|
+
data[key]
|
66
114
|
end
|
67
115
|
|
68
|
-
# @return [Boolean] Returns true
|
116
|
+
# @return [Boolean] Returns true if there is no response error.
|
69
117
|
def successful?
|
70
118
|
error.nil?
|
71
119
|
end
|
@@ -74,9 +122,9 @@ module AWS
|
|
74
122
|
# by AWS.
|
75
123
|
def throttled?
|
76
124
|
if !successful? and http_response.body
|
77
|
-
error =
|
78
|
-
error = error
|
79
|
-
error
|
125
|
+
error = XML::Parser.new.parse(http_response.body)
|
126
|
+
error = error[:error] if error[:error]
|
127
|
+
error[:code] == "Throttling"
|
80
128
|
else
|
81
129
|
false
|
82
130
|
end
|
@@ -87,49 +135,66 @@ module AWS
|
|
87
135
|
http_response.timeout?
|
88
136
|
end
|
89
137
|
|
138
|
+
# @return [String]
|
90
139
|
# @private
|
91
140
|
def inspect
|
92
|
-
|
93
|
-
"<#{self.class}:#{request_type}>"
|
94
|
-
else
|
95
|
-
"<#{self.class}>"
|
96
|
-
end
|
141
|
+
data.inspect
|
97
142
|
end
|
98
143
|
|
144
|
+
# @return [String]
|
145
|
+
# @private
|
99
146
|
def cache_key
|
100
|
-
[
|
101
|
-
|
102
|
-
|
103
|
-
|
147
|
+
[
|
148
|
+
http_request.access_key_id,
|
149
|
+
http_request.host,
|
150
|
+
request_type,
|
151
|
+
serialized_options
|
152
|
+
].join(":")
|
153
|
+
end
|
154
|
+
|
155
|
+
# Rebuilds the HTTP request using the block passed to the initializer.
|
156
|
+
# This is primarily used by the client when a request must be retried
|
157
|
+
# (throttling, server errors, socket errors, etc).
|
158
|
+
# @private
|
159
|
+
def rebuild_request
|
160
|
+
@http_request = @request_builder.call
|
161
|
+
end
|
162
|
+
|
163
|
+
protected
|
164
|
+
|
165
|
+
# @note The prefered method to get as response data is to use {#[]}.
|
166
|
+
#
|
167
|
+
# This provides a backwards-compat layer to the old response objects
|
168
|
+
# where each response value had a method extended onto this object.
|
169
|
+
# Now all response data is accessible as a hash.
|
170
|
+
#
|
171
|
+
# @see #[]
|
172
|
+
# @see #data
|
173
|
+
#
|
174
|
+
def method_missing *args, &block
|
175
|
+
Core::Data.new(data).send(*args, &block)
|
104
176
|
end
|
105
177
|
|
106
178
|
def serialized_options
|
107
179
|
serialize_options_hash(request_options)
|
108
180
|
end
|
109
181
|
|
110
|
-
private
|
111
182
|
def serialize_options_hash(hash)
|
112
183
|
"(" + hash.keys.sort_by(&:to_s).map do |key|
|
113
184
|
"#{key}=#{serialize_options_value(hash[key])}"
|
114
185
|
end.join(" ") + ")"
|
115
186
|
end
|
116
187
|
|
117
|
-
private
|
118
188
|
def serialize_options_value(value)
|
119
189
|
case value
|
120
|
-
when Hash
|
121
|
-
|
122
|
-
|
123
|
-
serialize_options_array(value)
|
124
|
-
else
|
125
|
-
value.inspect
|
190
|
+
when Hash then serialize_options_hash(value)
|
191
|
+
when Array then serialize_options_array(value)
|
192
|
+
else value.inspect
|
126
193
|
end
|
127
194
|
end
|
128
195
|
|
129
|
-
|
130
|
-
|
131
|
-
"[" + ary.map { |v| serialize_options_value(v) }.join(" ") +
|
132
|
-
"]"
|
196
|
+
def serialize_options_array array
|
197
|
+
"[" + array.map{|v| serialize_options_value(v) }.join(" ") + "]"
|
133
198
|
end
|
134
199
|
|
135
200
|
end
|