aws-sdk-core 2.0.0.rc14 → 2.0.0.rc15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +32 -3
  3. data/apis/AutoScaling.api.json +1943 -0
  4. data/apis/{autoscaling-2011-01-01.paginators.json → AutoScaling.paginators.json} +0 -0
  5. data/apis/CloudFormation.api.json +785 -0
  6. data/apis/{cloudformation-2010-05-15.paginators.json → CloudFormation.paginators.json} +0 -0
  7. data/apis/CloudFront.api.json +2581 -0
  8. data/apis/{cloudfront-2014-05-31.paginators.json → CloudFront.paginators.json} +0 -0
  9. data/apis/{cloudfront-2014-01-31.waiters.json → CloudFront.waiters.json} +0 -0
  10. data/apis/CloudSearch.api.json +1955 -0
  11. data/apis/{cloudsearch-2013-01-01.paginators.json → CloudSearch.paginators.json} +0 -0
  12. data/apis/CloudSearchDomain.api.json +349 -0
  13. data/apis/CloudTrail.api.json +559 -0
  14. data/apis/{cloudtrail-2013-11-01.paginators.json → CloudTrail.paginators.json} +0 -0
  15. data/apis/CloudWatch.api.json +917 -0
  16. data/apis/{monitoring-2010-08-01.paginators.json → CloudWatch.paginators.json} +0 -0
  17. data/apis/CloudWatchLogs.api.json +816 -0
  18. data/apis/{logs-2014-03-28.paginators.json → CloudWatchLogs.paginators.json} +0 -0
  19. data/apis/CognitoIdentity.api.json +631 -0
  20. data/apis/CognitoSync.api.json +721 -0
  21. data/apis/DataPipeline.api.json +940 -0
  22. data/apis/{datapipeline-2012-10-29.paginators.json → DataPipeline.paginators.json} +0 -0
  23. data/apis/DirectConnect.api.json +833 -0
  24. data/apis/{directconnect-2012-10-25.paginators.json → DirectConnect.paginators.json} +0 -0
  25. data/apis/DynamoDB.api.json +1210 -0
  26. data/apis/{dynamodb-2011-12-05.paginators.json → DynamoDB.paginators.json} +0 -0
  27. data/apis/{dynamodb-2012-08-10.waiters.json → DynamoDB.waiters.json} +0 -0
  28. data/apis/EC2.api.json +9914 -0
  29. data/apis/{ec2-2014-06-15.paginators.json → EC2.paginators.json} +0 -0
  30. data/apis/{ec2-2014-06-15.resources.json → EC2.resources.json} +0 -0
  31. data/apis/{ec2-2014-06-15.waiters.json → EC2.waiters.json} +0 -0
  32. data/apis/EMR.api.json +1339 -0
  33. data/apis/{elasticmapreduce-2009-03-31.paginators.json → EMR.paginators.json} +0 -0
  34. data/apis/ElastiCache.api.json +3410 -0
  35. data/apis/{elasticache-2014-03-24.paginators.json → ElastiCache.paginators.json} +0 -0
  36. data/apis/ElasticBeanstalk.api.json +1540 -0
  37. data/apis/{elasticbeanstalk-2010-12-01.paginators.json → ElasticBeanstalk.paginators.json} +0 -0
  38. data/apis/ElasticLoadBalancing.api.json +2131 -0
  39. data/apis/{elasticloadbalancing-2012-06-01.paginators.json → ElasticLoadBalancing.paginators.json} +0 -0
  40. data/apis/ElasticTranscoder.api.json +1647 -0
  41. data/apis/{elastictranscoder-2012-09-25.paginators.json → ElasticTranscoder.paginators.json} +0 -0
  42. data/apis/Glacier.api.json +1456 -0
  43. data/apis/{glacier-2012-06-01.paginators.json → Glacier.paginators.json} +0 -0
  44. data/apis/{glacier-2012-06-01.resources.json → Glacier.resources.json} +0 -0
  45. data/apis/{glacier-2012-06-01.waiters.json → Glacier.waiters.json} +0 -0
  46. data/apis/IAM.api.json +4033 -0
  47. data/apis/{iam-2010-05-08.paginators.json → IAM.paginators.json} +0 -0
  48. data/apis/{iam-2010-05-08.resources.json → IAM.resources.json} +0 -0
  49. data/apis/ImportExport.api.json +515 -0
  50. data/apis/{importexport-2010-06-01.paginators.json → ImportExport.paginators.json} +0 -0
  51. data/apis/Kinesis.api.json +548 -0
  52. data/apis/{kinesis-2013-12-02.paginators.json → Kinesis.paginators.json} +0 -0
  53. data/apis/OpsWorks.api.json +2524 -0
  54. data/apis/{opsworks-2013-02-18.paginators.json → OpsWorks.paginators.json} +0 -0
  55. data/apis/RDS.api.json +4473 -0
  56. data/apis/{rds-2013-02-12.paginators.json → RDS.paginators.json} +0 -0
  57. data/apis/{rds-2013-09-09.waiters.json → RDS.waiters.json} +0 -0
  58. data/apis/Redshift.api.json +4482 -0
  59. data/apis/{redshift-2012-12-01.paginators.json → Redshift.paginators.json} +0 -0
  60. data/apis/{redshift-2012-12-01.waiters.json → Redshift.waiters.json} +0 -0
  61. data/apis/Route53.api.json +1935 -0
  62. data/apis/{route53-2013-04-01.paginators.json → Route53.paginators.json} +0 -0
  63. data/apis/Route53Domains.api.json +1129 -0
  64. data/apis/{s3-2006-03-01.api.json → S3.api.json} +336 -942
  65. data/apis/{s3-2006-03-01.paginators.json → S3.paginators.json} +1 -1
  66. data/apis/{s3-2006-03-01.resources.json → S3.resources.json} +0 -0
  67. data/apis/{s3-2006-03-01.waiters.json → S3.waiters.json} +0 -0
  68. data/apis/SES.api.json +644 -0
  69. data/apis/{email-2010-12-01.paginators.json → SES.paginators.json} +0 -0
  70. data/apis/{email-2010-12-01.waiters.json → SES.waiters.json} +0 -0
  71. data/apis/SNS.api.json +1760 -0
  72. data/apis/{sns-2010-03-31.paginators.json → SNS.paginators.json} +0 -0
  73. data/apis/{sns-2010-03-31.resources.json → SNS.resources.json} +0 -0
  74. data/apis/SQS.api.json +1113 -0
  75. data/apis/{sqs-2012-11-05.paginators.json → SQS.paginators.json} +0 -0
  76. data/apis/{sqs-2012-11-05.resources.json → SQS.resources.json} +0 -0
  77. data/apis/STS.api.json +594 -0
  78. data/apis/SWF.api.json +2656 -0
  79. data/apis/{swf-2012-01-25.paginators.json → SWF.paginators.json} +0 -0
  80. data/apis/SimpleDB.api.json +954 -0
  81. data/apis/{sdb-2009-04-15.paginators.json → SimpleDB.paginators.json} +0 -0
  82. data/apis/StorageGateway.api.json +2311 -0
  83. data/apis/{storagegateway-2013-06-30.paginators.json → StorageGateway.paginators.json} +0 -0
  84. data/apis/Support.api.json +869 -0
  85. data/apis/{support-2013-04-15.paginators.json → Support.paginators.json} +0 -0
  86. data/lib/aws.rb +96 -53
  87. data/lib/aws/api/documenter.rb +238 -0
  88. data/lib/aws/api/{documentor.rb → operation_documenter.rb} +9 -5
  89. data/lib/aws/api/{doc_example.rb → operation_example.rb} +8 -7
  90. data/lib/aws/api/service_customizations.rb +3 -1
  91. data/lib/aws/client.rb +38 -0
  92. data/lib/aws/credential_provider_chain.rb +1 -0
  93. data/lib/aws/dynamodb/attribute_value.rb +87 -0
  94. data/lib/aws/empty_structure.rb +4 -3
  95. data/lib/aws/endpoint_provider.rb +1 -0
  96. data/lib/aws/errors.rb +2 -0
  97. data/lib/aws/instance_profile_credentials.rb +1 -1
  98. data/lib/aws/plugins/csd_conditional_signing.rb +32 -0
  99. data/lib/aws/plugins/dynamodb_simple_attributes.rb +179 -0
  100. data/lib/aws/plugins/global_configuration.rb +13 -3
  101. data/lib/aws/plugins/protocols/json_rpc.rb +9 -7
  102. data/lib/aws/plugins/regional_endpoint.rb +1 -1
  103. data/lib/aws/plugins/request_signer.rb +13 -6
  104. data/lib/aws/plugins/response_paging.rb +1 -2
  105. data/lib/aws/plugins/s3_url_encoded_keys.rb +92 -0
  106. data/lib/aws/plugins/user_agent.rb +1 -2
  107. data/lib/aws/signers/v4.rb +1 -1
  108. data/lib/aws/structure.rb +49 -2
  109. data/lib/aws/version.rb +1 -1
  110. data/lib/aws/xml/builder.rb +1 -0
  111. data/lib/seahorse.rb +2 -1
  112. data/lib/seahorse/client/handler_list.rb +10 -3
  113. data/lib/seahorse/client/http/request.rb +0 -8
  114. data/lib/seahorse/client/xml/builder.rb +0 -1
  115. data/lib/seahorse/model/shape_map.rb +1 -0
  116. data/lib/seahorse/model/shapes.rb +5 -0
  117. metadata +93 -107
  118. data/apis/autoscaling-2011-01-01.api.json +0 -3063
  119. data/apis/cloudformation-2010-05-15.api.json +0 -1306
  120. data/apis/cloudfront-2014-01-31.api.json +0 -3478
  121. data/apis/cloudfront-2014-01-31.paginators.json +0 -32
  122. data/apis/cloudfront-2014-05-31.api.json +0 -3540
  123. data/apis/cloudfront-2014-05-31.waiters.json +0 -29
  124. data/apis/cloudsearch-2011-02-01.api.json +0 -2093
  125. data/apis/cloudsearch-2011-02-01.paginators.json +0 -13
  126. data/apis/cloudsearch-2013-01-01.api.json +0 -2655
  127. data/apis/cloudsearchdomain-2013-01-01.api.json +0 -508
  128. data/apis/cloudtrail-2013-11-01.api.json +0 -773
  129. data/apis/cognito-identity-2014-06-30.api.json +0 -884
  130. data/apis/cognito-sync-2014-06-30.api.json +0 -1029
  131. data/apis/datapipeline-2012-10-29.api.json +0 -1432
  132. data/apis/directconnect-2012-10-25.api.json +0 -1174
  133. data/apis/dynamodb-2011-12-05.api.json +0 -1208
  134. data/apis/dynamodb-2011-12-05.waiters.json +0 -27
  135. data/apis/dynamodb-2012-08-10.api.json +0 -1857
  136. data/apis/dynamodb-2012-08-10.paginators.json +0 -26
  137. data/apis/ec2-2014-06-15.api.json +0 -11670
  138. data/apis/elasticache-2014-03-24.api.json +0 -4789
  139. data/apis/elasticache-2014-07-15.api.json +0 -4826
  140. data/apis/elasticache-2014-07-15.paginators.json +0 -76
  141. data/apis/elasticbeanstalk-2010-12-01.api.json +0 -2442
  142. data/apis/elasticloadbalancing-2012-06-01.api.json +0 -2605
  143. data/apis/elasticmapreduce-2009-03-31.api.json +0 -2282
  144. data/apis/elastictranscoder-2012-09-25.api.json +0 -2478
  145. data/apis/email-2010-12-01.api.json +0 -954
  146. data/apis/glacier-2012-06-01.api.json +0 -2012
  147. data/apis/iam-2010-05-08.api.json +0 -5322
  148. data/apis/importexport-2010-06-01.api.json +0 -687
  149. data/apis/kinesis-2013-12-02.api.json +0 -769
  150. data/apis/logs-2014-03-28.api.json +0 -942
  151. data/apis/manifest.json +0 -259
  152. data/apis/monitoring-2010-08-01.api.json +0 -1338
  153. data/apis/opsworks-2013-02-18.api.json +0 -4348
  154. data/apis/rds-2013-01-10.api.json +0 -6074
  155. data/apis/rds-2013-01-10.paginators.json +0 -97
  156. data/apis/rds-2013-02-12.api.json +0 -6392
  157. data/apis/rds-2013-09-09.api.json +0 -6564
  158. data/apis/rds-2013-09-09.paginators.json +0 -110
  159. data/apis/redshift-2012-12-01.api.json +0 -6318
  160. data/apis/route53-2013-04-01.api.json +0 -2493
  161. data/apis/route53domains-2014-05-15.api.json +0 -1622
  162. data/apis/sdb-2009-04-15.api.json +0 -1178
  163. data/apis/sns-2010-03-31.api.json +0 -2275
  164. data/apis/sqs-2012-11-05.api.json +0 -1438
  165. data/apis/storagegateway-2013-06-30.api.json +0 -3153
  166. data/apis/sts-2011-06-15.api.json +0 -786
  167. data/apis/support-2013-04-15.api.json +0 -1379
  168. data/apis/swf-2012-01-25.api.json +0 -4463
  169. data/lib/aws/api/manifest.rb +0 -29
  170. data/lib/aws/api/manifest_builder.rb +0 -57
  171. data/lib/aws/api/minifier.rb +0 -42
  172. data/lib/aws/response_handler.rb +0 -38
  173. data/lib/aws/service_builder.rb +0 -56
@@ -1,10 +1,10 @@
1
1
  module Aws
2
2
  module Api
3
- class Documentor
3
+ class OperationDocumenter
4
4
 
5
- def initialize(obj_name, method_name, operation)
6
- @operation = operation
7
- @example = DocExample.new(obj_name, method_name, operation)
5
+ def initialize(options)
6
+ @operation = options[:operation]
7
+ @example = OperationExample.new(options)
8
8
  end
9
9
 
10
10
  def input
@@ -50,7 +50,11 @@ module Aws
50
50
  private
51
51
 
52
52
  def params(shape, &block)
53
- ['<div class="params">', api_ref(shape)] + yield + ['</div>']
53
+ if shape && shape.name == 'AttributeValue'
54
+ ['<p>An attribute value may be one of:<ul><li>`String`</li><li>`Numeric`</li><li>`IO`</li><li>`Set<String,Numeric,IO>`</li></ul></p>']
55
+ else
56
+ ['<div class="params">', api_ref(shape)] + yield + ['</div>']
57
+ end
54
58
  end
55
59
 
56
60
  def param(shape, key_name, value_type, required, visited, &block)
@@ -1,13 +1,13 @@
1
1
  module Aws
2
2
  module Api
3
- class DocExample
3
+ class OperationExample
4
4
 
5
5
  include Seahorse::Model::Shapes
6
6
 
7
- def initialize(obj_name, method_name, operation)
8
- @obj_name = obj_name
9
- @method_name = method_name
10
- @operation = operation
7
+ def initialize(options)
8
+ @obj_name = options[:svc_var_name]
9
+ @method_name = options[:method_name]
10
+ @operation = options[:operation]
11
11
  end
12
12
 
13
13
  def to_str
@@ -46,7 +46,6 @@ module Aws
46
46
  def multiline_map(shape, i, visited)
47
47
  lines = ["{"]
48
48
  lines << "#{i} #{key_name(shape)} => #{member(shape.value, i + ' ', visited)},"
49
- #lines << "#{i} # repeated ..."
50
49
  lines << "#{i}}"
51
50
  lines.join("\n")
52
51
  end
@@ -62,7 +61,6 @@ module Aws
62
61
  def multiline_list(shape, i, visited)
63
62
  lines = ["["]
64
63
  lines << "#{i} #{member(shape.member, i + ' ', visited)},"
65
- #lines << "#{i} # repeated ... "
66
64
  lines << "#{i}]"
67
65
  lines.join("\n")
68
66
  end
@@ -73,6 +71,9 @@ module Aws
73
71
  recursive << "#{i} # recursive #{shape.name} ..."
74
72
  recursive << "#{i}}"
75
73
  return recursive.join("\n")
74
+ elsif shape.name == 'AttributeValue'
75
+ msg='"value", #<String,Numeric,IO,Set>'
76
+ return msg
76
77
  else
77
78
  visited = visited + [shape.name]
78
79
  end
@@ -78,12 +78,13 @@ module Aws
78
78
  end
79
79
 
80
80
  customize 'cloudsearchdomain' do
81
- remove_plugin 'Aws::Plugins::RequestSigner'
82
81
  remove_plugin 'Aws::Plugins::RegionalEndpoint'
82
+ add_plugin 'Aws::Plugins::CSDConditionalSigning'
83
83
  end
84
84
 
85
85
  customize 'dynamodb' do
86
86
  add_plugin 'Aws::Plugins::DynamoDBExtendedRetries'
87
+ add_plugin 'Aws::Plugins::DynamoDBSimpleAttributes'
87
88
  end
88
89
 
89
90
  customize 'ec2' do
@@ -123,6 +124,7 @@ module Aws
123
124
  add_plugin 'Aws::Plugins::S3Md5s'
124
125
  add_plugin 'Aws::Plugins::S3Redirects'
125
126
  add_plugin 'Aws::Plugins::S3SseCpk'
127
+ add_plugin 'Aws::Plugins::S3UrlEncodedKeys'
126
128
  end
127
129
 
128
130
  customize 'sqs' do
@@ -0,0 +1,38 @@
1
+ module Aws
2
+
3
+ # Base class for all {Aws} service clients.
4
+ class Client < Seahorse::Client::Base
5
+ class << self
6
+
7
+ # @return [Symbol]
8
+ # @api private
9
+ attr_accessor :identifier
10
+
11
+ # @return [Paging::Provider]
12
+ # @api private
13
+ attr_accessor :paginators
14
+
15
+ # @api private
16
+ def define(svc_name, options)
17
+ client_class = Class.new(self)
18
+ client_class.identifier = svc_name.downcase.to_sym
19
+ client_class.set_api(load_api(options[:api]))
20
+ Api::ServiceCustomizations.apply(client_class)
21
+ client_class
22
+ end
23
+
24
+ private
25
+
26
+ def load_api(api)
27
+ case api
28
+ when Seahorse::Model::Api then api
29
+ when Hash then Seahorse::Model::Api.new(api)
30
+ when String then Seahorse::Model::Api.new(Aws.load_json(api))
31
+ else
32
+ raise ArgumentError, "expected :api to be an Api, Hash or String"
33
+ end
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -1,4 +1,5 @@
1
1
  module Aws
2
+ # @api private
2
3
  class CredentialProviderChain
3
4
 
4
5
  def initialize(config)
@@ -0,0 +1,87 @@
1
+ require 'bigdecimal'
2
+ require 'stringio'
3
+ require 'set'
4
+
5
+ module Aws
6
+ module DynamoDB
7
+ # @api private
8
+ class AttributeValue
9
+
10
+ def initialize
11
+ @marshaler = Marshaler.new
12
+ @unmarshaler = Unmarshaler.new
13
+ end
14
+
15
+ def marshal(value)
16
+ @marshaler.format(value)
17
+ end
18
+
19
+ def unmarshal(value)
20
+ @unmarshaler.format(value)
21
+ end
22
+
23
+ class Marshaler
24
+
25
+ def format(obj)
26
+ case obj
27
+ when String then { s: obj }
28
+ when Numeric then { n: obj.to_s }
29
+ when StringIO, IO then { b: obj.read }
30
+ when Set then format_set(obj)
31
+ else
32
+ msg = "unsupported type, expected Set, String, Numeric, or "
33
+ msg << "IO object, got #{obj.class.name}"
34
+ raise ArgumentError, msg
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def format_set(set)
41
+ case set.first
42
+ when String then { ss: set.map(&:to_s) }
43
+ when Numeric then { ns: set.map(&:to_s) }
44
+ when StringIO, IO then { bs: set.map(&:read) }
45
+ else
46
+ msg = "set types only support String, Numeric, or IO objects"
47
+ raise ArgumentError, msg
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ class Unmarshaler
54
+
55
+ def format(obj)
56
+ type, value = extract_type_and_value(obj)
57
+ case type
58
+ when :s then value
59
+ when :n then BigDecimal.new(value)
60
+ when :b then StringIO.new(value)
61
+ when :ss then Set.new(value)
62
+ when :ns then Set.new(value.map { |n| BigDecimal.new(n) })
63
+ when :bs then Set.new(value.map { |b| StringIO.new(b) })
64
+ else
65
+ raise ArgumentError, "unhandled type #{type.inspect}"
66
+ end
67
+ end
68
+
69
+ private
70
+
71
+ def extract_type_and_value(obj)
72
+ case obj
73
+ when Hash then obj.to_a.first
74
+ when Struct
75
+ obj.members.each do |key|
76
+ value = obj[key]
77
+ return [key, value] unless value.nil?
78
+ end
79
+ else
80
+ raise ArgumentError, "unhandled type #{obj.inspect}"
81
+ end
82
+ end
83
+
84
+ end
85
+ end
86
+ end
87
+ end
@@ -6,14 +6,14 @@ module Aws
6
6
  end
7
7
 
8
8
  def ==(other)
9
- other.is_a?(EmptyStruct)
9
+ other.is_a?(EmptyStructure)
10
10
  end
11
11
 
12
12
  def [](member_name)
13
13
  raise NameError, "no member '#{member_name}' in struct"
14
14
  end
15
15
 
16
- def []=(member_name)
16
+ def []=(member_name, value)
17
17
  raise NameError, "no member '#{member_name}' in struct"
18
18
  end
19
19
 
@@ -30,7 +30,7 @@ module Aws
30
30
  end
31
31
 
32
32
  def eql?(other)
33
- other.is_a?(EmptyStruct)
33
+ other.is_a?(EmptyStructure)
34
34
  end
35
35
 
36
36
  # @api private
@@ -52,6 +52,7 @@ module Aws
52
52
  end
53
53
 
54
54
  def select(&block)
55
+ []
55
56
  end
56
57
 
57
58
  def size
@@ -1,6 +1,7 @@
1
1
  require 'multi_json'
2
2
 
3
3
  module Aws
4
+ # @api private
4
5
  class EndpointProvider
5
6
 
6
7
  # @option options [Array<Hash>] :rules ([]) An array of grouped rules.
@@ -1,6 +1,8 @@
1
1
  require 'thread'
2
2
 
3
3
  module Aws
4
+
5
+ # Each Service module has its own Errors module, e.g. {S3::Errors}.
4
6
  module Errors
5
7
 
6
8
  # The base class for all errors returned by an Amazon Web Service.
@@ -96,7 +96,7 @@ module Aws
96
96
  end
97
97
 
98
98
  def open_connection
99
- http = Net::HTTP.new(@ip_address, @port)
99
+ http = Net::HTTP.new(@ip_address, @port, nil)
100
100
  http.open_timeout = @http_open_timeout
101
101
  http.read_timeout = @http_read_timeout
102
102
  http.set_debug_output(@http_debug_output) if @http_debug_output
@@ -0,0 +1,32 @@
1
+ module Aws
2
+ module Plugins
3
+
4
+ # Makes it possible to conditional sign {Aws::CloudSearchDomain::Client}
5
+ # requests. When credentials are configured, requests are signed.
6
+ # When they are omitted, the request is sent anonymously.
7
+ #
8
+ # @seahorse.client.option [String] :sigv4_region Only needed when sending
9
+ # authenticated/signed requests to a Cloud Search domain and the
10
+ # endpoint does not contain the region name.
11
+ #
12
+ class CSDConditionalSigning < Seahorse::Client::Plugin
13
+
14
+ option(:sigv4_region) do |cfg|
15
+ # extract the region name from the cloud search domain endpoint
16
+ if cfg.endpoint
17
+ cfg.endpoint.to_s.split('.')[1]
18
+ else
19
+ raise ArgumentError, 'missing required option :endpoint'
20
+ end
21
+ end
22
+
23
+ def after_initialize(client)
24
+ # disable request singing when credentials are not set
25
+ if client.config.credentials.nil? or !client.config.credentials.set?
26
+ client.config.signature_version = nil
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,179 @@
1
+ module Aws
2
+ module Plugins
3
+
4
+ # Simplifies working with Amazon DynamoDB attribute values.
5
+ # Translates attribute values for requests and responses to sensible
6
+ # Ruby natives.
7
+ #
8
+ # This plugin is enabled by default for all {DynamoDB::Client}
9
+ # objects. You can disable this plugin by passing
10
+ # `simple_attributes: false` to the client constructor:
11
+ #
12
+ # ddb = Aws::DynamoDB::Client.new(simple_attributes: false)
13
+ #
14
+ # ## Input Examples
15
+ #
16
+ # With this plugin **enabled**, `simple_attributes: true`:
17
+ #
18
+ # dynamodb.put_item(
19
+ # table_name: 'aws-sdk',
20
+ # item: {
21
+ # id: 'uuid',
22
+ # age: 35,
23
+ # tags: Set.new(%w(simple attributes)),
24
+ # data: StringIO.new('data')
25
+ # }
26
+ # )
27
+ #
28
+ # With this plugin **disabled**, `simple_attributes: false`:
29
+ #
30
+ # # note that all types are prefixed in a hash and that
31
+ # # numeric types must be serialized as strings
32
+ # dynamodb.put_item(
33
+ # table_name: 'aws-sdk',
34
+ # item: {
35
+ # 'id' => { s: 'uuid' },
36
+ # 'age' => { n: '35' },
37
+ # 'tags' => { ss: ['simple', 'attributes'] },
38
+ # 'data' => { b: 'data' },
39
+ # }
40
+ # )
41
+ #
42
+ # ## Output Examples
43
+ #
44
+ # With this plugin **enabled**, `simple_attributes: true`:
45
+ #
46
+ # resp = dynamodb.get(table_name: 'aws-sdk', key: { id: 'uuid' })
47
+ # resp.item
48
+ # {
49
+ # id: 'uuid',
50
+ # age: 35,
51
+ # tags: Set.new(%w(simple attributes)),
52
+ # data: StringIO.new('data')
53
+ # }
54
+ #
55
+ # With this plugin **disabled**, `simple_attributes: false`:
56
+ #
57
+ # # note that the request `:key` had to be type prefixed
58
+ # resp = dynamodb.get(table_name: 'aws-sdk', key: { 'id' => { s: 'uuid' }})
59
+ # resp.item
60
+ # # {
61
+ # # "id"=> <struct s='uuid', n=nil, b=nil, ss=nil, ns=nil, bs=nil>,
62
+ # # "age"=> <struct s=nil, n="35", b=nil, ss=nil, ns=nil, bs=nil>,
63
+ # # "tags"=> <struct s=nil, n=nil, b=nil, ss=['simple', 'attributes'], ns=nil, bs=nil>,
64
+ # # "data"=> <struct s=nil, n=nil, b="data", ss=nil, ns=nil, bs=nil>,
65
+ # # }
66
+ #
67
+ # @seahorse.client.option [Boolean] :simple_attributes (true)
68
+ # Enables working with DynamoDB attribute values using simple
69
+ # Ruby natives.
70
+ #
71
+ # Disabling this option requires that all attribute values have
72
+ # their types specified, e.g. `{ s: 'abc' }` instead of simply
73
+ # `'abc'`.
74
+ #
75
+ class DynamoDBSimpleAttributes < Seahorse::Client::Plugin
76
+
77
+ option(:simple_attributes) { |config| !config.simple_json }
78
+
79
+ def add_handlers(handlers, config)
80
+ if config.simple_attributes
81
+ handlers.add(Handler, step: :initialize)
82
+ end
83
+ end
84
+
85
+ class Handler < Seahorse::Client::Handler
86
+
87
+ def call(context)
88
+ context.params = translate_input(context)
89
+ @handler.call(context).on(200) do |response|
90
+ response.data = translate_output(response)
91
+ end
92
+ end
93
+
94
+ private
95
+
96
+ def translate_input(context)
97
+ if shape = context.operation.input
98
+ ValueTranslator.new(shape, :marshal).apply(context.params)
99
+ else
100
+ context.params
101
+ end
102
+ end
103
+
104
+ def translate_output(response)
105
+ if shape = response.context.operation.output
106
+ ValueTranslator.new(shape, :unmarshal).apply(response.data)
107
+ else
108
+ response.data
109
+ end
110
+ end
111
+
112
+ end
113
+
114
+ # @api private
115
+ class ValueTranslator
116
+
117
+ # @param [Seahorse::Model::Shapes::Shape] shape
118
+ # @param [Symbol<:marshal,:unmarshal>] mode
119
+ def initialize(shape, mode)
120
+ @shape = shape
121
+ @mode = mode
122
+ end
123
+
124
+ def apply(values)
125
+ structure(@shape, values) if @shape
126
+ end
127
+
128
+ private
129
+
130
+ def structure(shape, values)
131
+ if values.is_a?(Struct)
132
+ values.members.each do |key|
133
+ values[key] = translate(shape.member(key), values[key])
134
+ end
135
+ values
136
+ elsif values.is_a?(Hash)
137
+ values.each.with_object({}) do |(key, value), hash|
138
+ hash[key] = translate(shape.member(key), value)
139
+ end
140
+ else
141
+ values
142
+ end
143
+ end
144
+
145
+ def list(shape, values)
146
+ return values unless values.is_a?(Array)
147
+ values.inject([]) do |list, value|
148
+ list << translate(shape.member, value)
149
+ end
150
+ end
151
+
152
+ def map(shape, values)
153
+ return values unless values.is_a?(Hash)
154
+ values.each.with_object({}) do |(key, value), hash|
155
+ hash[key] = translate(shape.value, value)
156
+ end
157
+ end
158
+
159
+ def translate(shape, value)
160
+ if shape.name == 'AttributeValue'
161
+ DynamoDB::AttributeValue.new.send(@mode, value)
162
+ else
163
+ translate_complex(shape, value)
164
+ end
165
+ end
166
+
167
+ def translate_complex(shape, value)
168
+ case shape
169
+ when Seahorse::Model::Shapes::Structure then structure(shape, value)
170
+ when Seahorse::Model::Shapes::List then list(shape, value)
171
+ when Seahorse::Model::Shapes::Map then map(shape, value)
172
+ else value
173
+ end
174
+ end
175
+
176
+ end
177
+ end
178
+ end
179
+ end