aws-sdk-core 2.0.48 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. checksums.yaml +4 -4
  2. data/apis/autoscaling/2011-01-01/api-2.json +636 -33
  3. data/apis/cloudhsm/2014-05-30/api-2.json +3 -6
  4. data/apis/ec2/2014-10-01/api-2.json +10267 -0
  5. data/apis/ec2/2014-10-01/paginators-1.json +125 -0
  6. data/apis/ec2/2014-10-01/resources-1.json +2289 -0
  7. data/apis/ec2/2014-10-01/waiters-2.json +453 -0
  8. data/apis/ec2/2015-03-01/api-2.json +11245 -0
  9. data/apis/ec2/2015-03-01/paginators-1.json +125 -0
  10. data/apis/ec2/2015-03-01/resources-1.json +2479 -0
  11. data/apis/ec2/2015-03-01/waiters-2.json +458 -0
  12. data/apis/ec2/2015-04-15/api-2.json +182 -2
  13. data/apis/ecs/2014-11-13/api-2.json +316 -7
  14. data/apis/ecs/2014-11-13/paginators-1.json +40 -0
  15. data/apis/ecs/2014-11-13/waiters-2.json +93 -0
  16. data/apis/redshift/2012-12-01/waiters-2.json +19 -0
  17. data/apis/s3/2006-03-01/api-2.json +1 -2
  18. data/apis/sqs/2012-11-05/api-2.json +5 -6
  19. data/ca-bundle.crt +3554 -0
  20. data/lib/aws-sdk-core.rb +127 -44
  21. data/lib/aws-sdk-core/api/builder.rb +95 -0
  22. data/lib/aws-sdk-core/api/customizations.rb +152 -0
  23. data/lib/aws-sdk-core/api/docs/builder.rb +220 -0
  24. data/lib/aws-sdk-core/api/docs/client_type_documenter.rb +109 -0
  25. data/lib/aws-sdk-core/api/docs/docstring_provider.rb +66 -0
  26. data/lib/aws-sdk-core/api/docs/operation_documenter.rb +107 -0
  27. data/lib/aws-sdk-core/api/docs/param_formatter.rb +163 -0
  28. data/lib/aws-sdk-core/api/docs/request_syntax_example.rb +22 -0
  29. data/lib/aws-sdk-core/api/docs/response_structure_example.rb +91 -0
  30. data/lib/aws-sdk-core/api/docs/utils.rb +133 -0
  31. data/lib/aws-sdk-core/api/shape_map.rb +140 -0
  32. data/lib/aws-sdk-core/assume_role_credentials.rb +9 -6
  33. data/lib/aws-sdk-core/client.rb +9 -6
  34. data/lib/aws-sdk-core/client_stubs.rb +127 -133
  35. data/lib/aws-sdk-core/client_waiters.rb +1 -1
  36. data/lib/aws-sdk-core/credential_provider.rb +44 -0
  37. data/lib/aws-sdk-core/credential_provider_chain.rb +3 -2
  38. data/lib/aws-sdk-core/credentials.rb +5 -0
  39. data/lib/aws-sdk-core/deprecations.rb +69 -0
  40. data/lib/aws-sdk-core/dynamodb.rb +12 -0
  41. data/lib/aws-sdk-core/eager_loader.rb +31 -0
  42. data/lib/aws-sdk-core/ecs.rb +2 -0
  43. data/lib/aws-sdk-core/empty_structure.rb +1 -82
  44. data/lib/aws-sdk-core/endpoint_provider.rb +1 -1
  45. data/lib/aws-sdk-core/instance_profile_credentials.rb +9 -10
  46. data/lib/aws-sdk-core/json.rb +56 -0
  47. data/lib/aws-sdk-core/json/builder.rb +33 -34
  48. data/lib/aws-sdk-core/json/error_handler.rb +2 -2
  49. data/lib/aws-sdk-core/json/handler.rb +67 -0
  50. data/lib/aws-sdk-core/json/json_engine.rb +15 -0
  51. data/lib/aws-sdk-core/json/oj_engine.rb +15 -0
  52. data/lib/aws-sdk-core/json/parser.rb +30 -38
  53. data/lib/aws-sdk-core/pageable_response.rb +9 -12
  54. data/lib/aws-sdk-core/pager.rb +69 -0
  55. data/lib/aws-sdk-core/param_converter.rb +203 -0
  56. data/lib/aws-sdk-core/param_validator.rb +148 -0
  57. data/lib/aws-sdk-core/plugins/dynamodb_simple_attributes.rb +21 -18
  58. data/lib/aws-sdk-core/plugins/glacier_account_id.rb +9 -1
  59. data/lib/aws-sdk-core/plugins/glacier_checksums.rb +2 -3
  60. data/lib/aws-sdk-core/plugins/param_converter.rb +27 -0
  61. data/lib/aws-sdk-core/plugins/param_validator.rb +28 -0
  62. data/lib/aws-sdk-core/plugins/protocols/json_rpc.rb +3 -7
  63. data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +1 -2
  64. data/lib/aws-sdk-core/plugins/protocols/rest_xml.rb +1 -1
  65. data/lib/aws-sdk-core/plugins/regional_endpoint.rb +1 -1
  66. data/lib/aws-sdk-core/plugins/request_signer.rb +5 -5
  67. data/lib/aws-sdk-core/plugins/response_paging.rb +20 -11
  68. data/lib/aws-sdk-core/plugins/s3_get_bucket_location_fix.rb +1 -1
  69. data/lib/aws-sdk-core/plugins/s3_request_signer.rb +1 -2
  70. data/lib/aws-sdk-core/plugins/stub_responses.rb +25 -27
  71. data/lib/aws-sdk-core/query/ec2_param_builder.rb +29 -34
  72. data/lib/aws-sdk-core/query/handler.rb +32 -18
  73. data/lib/aws-sdk-core/query/param_builder.rb +45 -53
  74. data/lib/aws-sdk-core/refreshing_credentials.rb +3 -15
  75. data/lib/aws-sdk-core/rest/handler.rb +22 -0
  76. data/lib/aws-sdk-core/rest/request/body.rb +58 -0
  77. data/lib/aws-sdk-core/rest/request/builder.rb +50 -0
  78. data/lib/aws-sdk-core/rest/request/endpoint.rb +70 -0
  79. data/lib/aws-sdk-core/rest/request/headers.rb +48 -0
  80. data/lib/aws-sdk-core/rest/response/body.rb +43 -0
  81. data/lib/aws-sdk-core/rest/response/headers.rb +60 -0
  82. data/lib/aws-sdk-core/rest/response/parser.rb +47 -0
  83. data/lib/aws-sdk-core/rest/response/status_code.rb +24 -0
  84. data/lib/aws-sdk-core/shared_credentials.rb +11 -6
  85. data/lib/aws-sdk-core/signers/base.rb +1 -1
  86. data/lib/aws-sdk-core/signers/s3.rb +2 -3
  87. data/lib/aws-sdk-core/signers/v2.rb +7 -4
  88. data/lib/aws-sdk-core/signers/v4.rb +11 -22
  89. data/lib/aws-sdk-core/structure.rb +26 -145
  90. data/lib/aws-sdk-core/stubbing/data_applicator.rb +46 -0
  91. data/lib/aws-sdk-core/stubbing/empty_stub.rb +53 -0
  92. data/lib/aws-sdk-core/stubbing/protocols/ec2.rb +49 -0
  93. data/lib/aws-sdk-core/stubbing/protocols/json.rb +40 -0
  94. data/lib/aws-sdk-core/stubbing/protocols/query.rb +40 -0
  95. data/lib/aws-sdk-core/stubbing/protocols/rest.rb +67 -0
  96. data/lib/aws-sdk-core/stubbing/protocols/rest_json.rb +25 -0
  97. data/lib/aws-sdk-core/stubbing/protocols/rest_xml.rb +38 -0
  98. data/lib/aws-sdk-core/stubbing/stub_data.rb +34 -0
  99. data/lib/aws-sdk-core/version.rb +1 -1
  100. data/lib/aws-sdk-core/xml/builder.rb +58 -52
  101. data/lib/aws-sdk-core/xml/default_map.rb +10 -0
  102. data/lib/aws-sdk-core/xml/doc_builder.rb +86 -0
  103. data/lib/aws-sdk-core/xml/error_handler.rb +7 -2
  104. data/lib/aws-sdk-core/xml/parser.rb +4 -4
  105. data/lib/aws-sdk-core/xml/parser/frame.rb +75 -70
  106. data/lib/aws-sdk-core/xml/parser/stack.rb +4 -4
  107. data/lib/seahorse.rb +0 -11
  108. data/lib/seahorse/client/base.rb +3 -12
  109. data/lib/seahorse/client/http/request.rb +9 -5
  110. data/lib/seahorse/client/plugins/endpoint.rb +5 -56
  111. data/lib/seahorse/client/plugins/restful_bindings.rb +38 -31
  112. data/lib/seahorse/client/request_context.rb +2 -2
  113. data/lib/seahorse/client/response.rb +6 -5
  114. data/lib/seahorse/model/api.rb +18 -61
  115. data/lib/seahorse/model/operation.rb +24 -54
  116. data/lib/seahorse/model/shapes.rb +120 -364
  117. data/lib/seahorse/util.rb +2 -6
  118. metadata +56 -109
  119. data/apis/autoscaling/2011-01-01/docs-2.json +0 -1246
  120. data/apis/cloudformation/2010-05-15/docs-2.json +0 -725
  121. data/apis/cloudfront/2014-11-06/docs-2.json +0 -1125
  122. data/apis/cloudhsm/2014-05-30/docs-2.json +0 -472
  123. data/apis/cloudsearch/2013-01-01/docs-2.json +0 -865
  124. data/apis/cloudsearchdomain/2013-01-01/docs-2.json +0 -311
  125. data/apis/cloudtrail/2013-11-01/docs-2.json +0 -328
  126. data/apis/codedeploy/2014-10-06/docs-2.json +0 -1261
  127. data/apis/cognito-identity/2014-06-30/docs-2.json +0 -506
  128. data/apis/cognito-sync/2014-06-30/docs-2.json +0 -582
  129. data/apis/config/2014-10-17/docs-2.json +0 -513
  130. data/apis/config/2014-11-12/docs-2.json +0 -514
  131. data/apis/datapipeline/2012-10-29/docs-2.json +0 -607
  132. data/apis/directconnect/2012-10-25/docs-2.json +0 -494
  133. data/apis/ds/2015-04-16/docs-2.json +0 -753
  134. data/apis/dynamodb/2011-12-05/api-2.json +0 -949
  135. data/apis/dynamodb/2011-12-05/docs-2.json +0 -606
  136. data/apis/dynamodb/2011-12-05/paginators-1.json +0 -26
  137. data/apis/dynamodb/2011-12-05/waiters-2.json +0 -35
  138. data/apis/dynamodb/2012-08-10/docs-2.json +0 -977
  139. data/apis/ec2/2015-04-15/docs-2.json +0 -5368
  140. data/apis/ecs/2014-11-13/docs-2.json +0 -791
  141. data/apis/elasticache/2015-02-02/docs-2.json +0 -1390
  142. data/apis/elasticbeanstalk/2010-12-01/docs-2.json +0 -1114
  143. data/apis/elasticfilesystem/2015-02-01/docs-2.json +0 -414
  144. data/apis/elasticloadbalancing/2012-06-01/docs-2.json +0 -1078
  145. data/apis/elasticmapreduce/2009-03-31/docs-2.json +0 -969
  146. data/apis/elastictranscoder/2012-09-25/docs-2.json +0 -1152
  147. data/apis/email/2010-12-01/docs-2.json +0 -441
  148. data/apis/glacier/2012-06-01/docs-2.json +0 -575
  149. data/apis/iam/2010-05-08/docs-2.json +0 -2138
  150. data/apis/importexport/2010-06-01/docs-2.json +0 -432
  151. data/apis/kinesis/2013-12-02/docs-2.json +0 -424
  152. data/apis/kms/2014-11-01/docs-2.json +0 -628
  153. data/apis/lambda/2014-11-11/docs-2.json +0 -303
  154. data/apis/lambda/2015-03-31/docs-2.json +0 -490
  155. data/apis/logs/2014-03-28/docs-2.json +0 -599
  156. data/apis/machinelearning/2014-12-12/docs-2.json +0 -1034
  157. data/apis/monitoring/2010-08-01/docs-2.json +0 -514
  158. data/apis/opsworks/2013-02-18/docs-2.json +0 -1592
  159. data/apis/rds/2014-10-31/docs-2.json +0 -2074
  160. data/apis/redshift/2012-12-01/docs-2.json +0 -1890
  161. data/apis/route53/2013-04-01/docs-2.json +0 -1159
  162. data/apis/route53domains/2014-05-15/docs-2.json +0 -620
  163. data/apis/s3/2006-03-01/docs-2.json +0 -2213
  164. data/apis/sdb/2009-04-15/docs-2.json +0 -339
  165. data/apis/sns/2010-03-31/docs-2.json +0 -564
  166. data/apis/sqs/2012-11-05/docs-2.json +0 -503
  167. data/apis/ssm/2014-11-06/docs-2.json +0 -440
  168. data/apis/storagegateway/2013-06-30/docs-2.json +0 -1331
  169. data/apis/sts/2011-06-15/docs-2.json +0 -351
  170. data/apis/support/2013-04-15/docs-2.json +0 -680
  171. data/apis/swf/2012-01-25/docs-2.json +0 -1569
  172. data/apis/workspaces/2015-04-08/docs-2.json +0 -457
  173. data/lib/aws-sdk-core/api/customizer.rb +0 -75
  174. data/lib/aws-sdk-core/api/docstrings.rb +0 -38
  175. data/lib/aws-sdk-core/api/documenter.rb +0 -241
  176. data/lib/aws-sdk-core/api/operation_documenter.rb +0 -173
  177. data/lib/aws-sdk-core/api/operation_example.rb +0 -133
  178. data/lib/aws-sdk-core/api/service_customizations.rb +0 -140
  179. data/lib/aws-sdk-core/client_paging.rb +0 -31
  180. data/lib/aws-sdk-core/json/rest_handler.rb +0 -20
  181. data/lib/aws-sdk-core/json/rpc_body_handler.rb +0 -38
  182. data/lib/aws-sdk-core/json/rpc_headers_handler.rb +0 -34
  183. data/lib/aws-sdk-core/json/simple_body_handler.rb +0 -34
  184. data/lib/aws-sdk-core/paging/null_pager.rb +0 -20
  185. data/lib/aws-sdk-core/paging/null_provider.rb +0 -13
  186. data/lib/aws-sdk-core/paging/pager.rb +0 -70
  187. data/lib/aws-sdk-core/paging/provider.rb +0 -22
  188. data/lib/aws-sdk-core/rest_body_handler.rb +0 -111
  189. data/lib/aws-sdk-core/signers/handler.rb +0 -18
  190. data/lib/aws-sdk-core/xml/rest_handler.rb +0 -20
  191. data/lib/seahorse/client/param_converter.rb +0 -207
  192. data/lib/seahorse/client/param_validator.rb +0 -139
  193. data/lib/seahorse/client/plugins/json_simple.rb +0 -33
  194. data/lib/seahorse/client/plugins/param_conversion.rb +0 -29
  195. data/lib/seahorse/client/plugins/param_validation.rb +0 -30
  196. data/lib/seahorse/client/xml/builder.rb +0 -91
  197. data/lib/seahorse/model/shape_map.rb +0 -47
@@ -3,11 +3,14 @@ require 'cgi'
3
3
  module Seahorse
4
4
  module Client
5
5
  module Plugins
6
+ # @api private
6
7
  class RestfulBindings < Plugin
7
8
 
8
9
  # @api private
9
10
  class Handler < Client::Handler
10
11
 
12
+ include Seahorse::Model::Shapes
13
+
11
14
  def call(context)
12
15
  build_request(context)
13
16
  @handler.call(context).on(200..299) do |response|
@@ -30,31 +33,31 @@ module Seahorse
30
33
  def populate_http_headers(context)
31
34
  params = context.params
32
35
  headers = context.http_request.headers
33
- each_member(context.operation.input) do |member_name, member|
36
+ each_member(context.operation.input) do |member_name, member_ref|
34
37
  value = params[member_name]
35
38
  next if value.nil?
36
- case member.location
37
- when 'header' then serialize_header(headers, member, value)
38
- when 'headers' then serialize_header_map(headers, member, value)
39
+ case member_ref.location
40
+ when 'header' then serialize_header(headers, member_ref, value)
41
+ when 'headers' then serialize_header_map(headers, member_ref, value)
39
42
  end
40
43
  end
41
44
  end
42
45
 
43
- def serialize_header(headers, shape, value)
44
- headers[shape.location_name] = serialize_header_value(shape, value)
46
+ def serialize_header(headers, ref, value)
47
+ headers[ref.location_name] = serialize_header_value(ref, value)
45
48
  end
46
49
 
47
- def serialize_header_map(headers, shape, values)
48
- prefix = shape.location_name || ''
50
+ def serialize_header_map(headers, ref, values)
51
+ prefix = ref.location_name || ''
49
52
  values.each_pair do |name, value|
50
- value = serialize_header_value(shape.value, value)
53
+ value = serialize_header_value(ref.shape.value, value)
51
54
  headers["#{prefix}#{name}"] = value
52
55
  end
53
56
  end
54
57
 
55
- def serialize_header_value(shape, value)
56
- if shape.is_a?(Model::Shapes::Timestamp)
57
- shape.format_time(value, 'httpdate')
58
+ def serialize_header_value(ref, value)
59
+ if TimestampShape === ref.shape
60
+ value.utc.httpdate
58
61
  else
59
62
  value.to_s
60
63
  end
@@ -63,51 +66,55 @@ module Seahorse
63
66
  # Extracts HTTP response headers and status code.
64
67
  def parse_response(response)
65
68
  headers = response.context.http_response.headers
66
- each_member(response.context.operation.output) do |key, shape|
67
- case shape.location
69
+ each_member(response.context.operation.output) do |key, ref|
70
+ case ref.location
68
71
  when 'statusCode'
69
72
  status_code = response.context.http_response.status_code
70
73
  response.data[key] = status_code
71
74
  when 'header'
72
- if headers.key?(shape.location_name)
73
- response.data[key] = extract_header(headers, shape)
75
+ if headers.key?(ref.location_name)
76
+ response.data[key] = extract_header(headers, ref)
74
77
  end
75
78
  when 'headers'
76
- response.data[key] = extract_header_map(headers, shape)
79
+ response.data[key] = extract_header_map(headers, ref)
77
80
  end
78
81
  end
79
82
  end
80
83
 
81
- def extract_header(headers, shape)
82
- parse_header_value(shape, headers[shape.location_name])
84
+ def extract_header(headers, ref)
85
+ parse_header_value(ref, headers[ref.location_name])
83
86
  end
84
87
 
85
- def extract_header_map(headers, shape)
86
- prefix = shape.location_name || ''
88
+ def extract_header_map(headers, ref)
89
+ prefix = ref.location_name || ''
87
90
  hash = {}
88
91
  headers.each do |header, value|
89
92
  if match = header.match(/^#{prefix}(.+)/i)
90
- hash[match[1]] = parse_header_value(shape.value, value)
93
+ hash[match[1]] = parse_header_value(ref.shape.value, value)
91
94
  end
92
95
  end
93
96
  hash
94
97
  end
95
98
 
96
- def parse_header_value(shape, value)
99
+ def parse_header_value(ref, value)
97
100
  if value
98
- case shape
99
- when Model::Shapes::Integer then value.to_i
100
- when Model::Shapes::Float then value.to_f
101
- when Model::Shapes::Boolean then value == 'true'
102
- when Model::Shapes::Timestamp
103
- shape.format == 'unix_timestamp' ? value.to_i : Time.parse(value)
101
+ case ref.shape
102
+ when IntegerShape then value.to_i
103
+ when FloatShape then value.to_f
104
+ when BooleanShape then value == 'true'
105
+ when TimestampShape
106
+ if value =~ /\d+(\.\d*)/
107
+ Time.at(value.to_f)
108
+ else
109
+ Time.parse(value)
110
+ end
104
111
  else value
105
112
  end
106
113
  end
107
114
  end
108
115
 
109
- def each_member(shape, &block)
110
- shape.members.each(&block) if shape
116
+ def each_member(ref, &block)
117
+ ref.shape.members.each(&block) if ref
111
118
  end
112
119
 
113
120
  end
@@ -4,7 +4,7 @@ module Seahorse
4
4
  module Client
5
5
  class RequestContext
6
6
 
7
- # @option options [required,String] :operation_name (nil)
7
+ # @option options [required,Symbol] :operation_name (nil)
8
8
  # @option options [required,Model::Operation] :operation (nil)
9
9
  # @option options [Hash] :params ({})
10
10
  # @option options [Configuration] :config (nil)
@@ -23,7 +23,7 @@ module Seahorse
23
23
  @metadata = {}
24
24
  end
25
25
 
26
- # @return [String] Name of the API operation called.
26
+ # @return [Symbol] Name of the API operation called.
27
27
  attr_accessor :operation_name
28
28
 
29
29
  # @return [Model::Operation]
@@ -59,11 +59,12 @@ module Seahorse
59
59
 
60
60
  # @api private
61
61
  def inspect
62
- if @data
63
- @data.respond_to?(:pretty_inspect) ? @data.pretty_inspect : super
64
- else
65
- super
66
- end
62
+ @data.inspect
63
+ end
64
+
65
+ # @api private
66
+ def pretty_print(q)
67
+ @data.pretty_print(q)
67
68
  end
68
69
 
69
70
  # @api private
@@ -2,82 +2,39 @@ module Seahorse
2
2
  module Model
3
3
  class Api
4
4
 
5
- # @param [Hash] definition
6
- def initialize(definition = {})
7
- @metadata = definition['metadata'] || {}
8
- @version = metadata('apiVersion')
9
- @documentation = definition['documentation']
10
- @definition = definition
11
- @shape_map = ShapeMap.new(definition['shapes'] || {})
12
- compute_operations
5
+ def initialize
6
+ @metadata = {}
7
+ @operations = {}
13
8
  end
14
9
 
15
10
  # @return [String, nil]
16
- attr_reader :version
17
-
18
- # @return [Array<Symbol>]
19
- attr_reader :operation_names
20
-
21
- # @return [String, nil]
22
- attr_reader :documentation
23
-
24
- # @return [ShapeMap]
25
- attr_reader :shape_map
11
+ attr_accessor :version
26
12
 
27
13
  # @return [Hash]
28
- attr_reader :definition
14
+ attr_accessor :metadata
29
15
 
30
- # @param [Symbol] name
31
- # @return [Boolean] Returns `true` if this API provides an operation
32
- # with the given name.
33
- def operation?(name)
34
- @operation_defs.key?(name.to_sym)
16
+ def operations(&block)
17
+ if block_given?
18
+ @operations.each(&block)
19
+ else
20
+ @operations.enum_for(:each)
21
+ end
35
22
  end
36
23
 
37
- # @param [Symbol] name
38
- # @return [Operation]
39
24
  def operation(name)
40
- name = name.to_sym
41
- if definition = @operation_defs[name]
42
- @operations[name] ||= Operation.new(definition, shape_map: @shape_map)
25
+ if @operations.key?(name.to_sym)
26
+ @operations[name.to_sym]
43
27
  else
44
- raise ArgumentError, "unknown operation :#{name}"
28
+ raise ArgumentError, "unknown operation #{name.inspect}"
45
29
  end
46
30
  end
47
31
 
48
- # @return [Enumerable]
49
- def operations
50
- enum_for(:each_operation) { |*args| operation_names.size }
51
- end
52
-
53
- # @param [String] key
54
- # @return [Object, nil]
55
- def metadata(key)
56
- @metadata[key]
32
+ def operation_names
33
+ @operations.keys
57
34
  end
58
35
 
59
- # @api private
60
- # @return [String]
61
- def inspect
62
- "#<#{self.class.name} version=#{version.inspect}>"
63
- end
64
-
65
- private
66
-
67
- def each_operation(&block)
68
- operation_names.each do |name|
69
- yield(name, operation(name))
70
- end
71
- end
72
-
73
- def compute_operations
74
- @operations = {}
75
- @operation_defs = {}
76
- (definition['operations'] || {}).each do |name,definition|
77
- name = Util.underscore(name).to_sym
78
- @operation_defs[name] = definition
79
- end
80
- @operation_names = @operation_defs.keys
36
+ def add_operation(name, operation)
37
+ @operations[name.to_sym] = operation
81
38
  end
82
39
 
83
40
  end
@@ -2,74 +2,44 @@ module Seahorse
2
2
  module Model
3
3
  class Operation
4
4
 
5
- # @param [Hash] definition
6
- # @option options [ShapeMap] :shape_map
7
- def initialize(definition = {}, options = {})
8
- @definition = definition
9
- @shape_map = options[:shape_map] || ShapeMap.new
10
- @name = definition['name']
11
- @input = shape_for(definition['input']) if definition['input']
12
- @output = shape_for(definition['output']) if definition['output']
13
- @deprecated = !!definition['deprecated']
14
- @documentation = definition['documentation']
15
- @paging = definition['paging'] || {}
5
+ def initialize
6
+ @http_method = 'POST'
7
+ @http_request_uri = '/'
8
+ @deprecated = false
9
+ @errors = []
10
+ @metadata = {}
16
11
  end
17
12
 
18
- # @return [String]
19
- attr_reader :name
13
+ # @return [String, nil]
14
+ attr_accessor :name
20
15
 
21
16
  # @return [String]
22
- attr_reader :http_method
17
+ attr_accessor :http_method
23
18
 
24
19
  # @return [String]
25
- attr_reader :http_request_uri
26
-
27
- # @return [String<HTML>, nil]
28
- attr_reader :documentation
29
-
30
- # @return [Shape, nil]
31
- attr_reader :input
20
+ attr_accessor :http_request_uri
32
21
 
33
- # @return [Shape, nil]
34
- attr_reader :output
22
+ # @return [Boolean]
23
+ attr_accessor :deprecated
35
24
 
36
- # @return [Hash]
37
- attr_reader :paging
25
+ # @return [String, nil]
26
+ attr_accessor :documentation
38
27
 
39
- # @return [Hash]
40
- attr_reader :definition
41
-
42
- # @return [String]
43
- def http_method
44
- (@definition['http'] || {})['method'] || 'POST'
45
- end
28
+ # @return [ShapeRef, nil]
29
+ attr_accessor :input
46
30
 
47
- # @return [String]
48
- def http_request_uri
49
- (@definition['http'] || {})['requestUri'] || '/'
50
- end
31
+ # @return [ShapeRef, nil]
32
+ attr_accessor :output
51
33
 
52
- # @return [Boolean] Returns `true` if this API operation is deprecated.
53
- def deprecated?
54
- !!@definition['deprecated']
55
- end
34
+ # @return [Array<ShapeRef>]
35
+ attr_accessor :errors
56
36
 
57
- # @return [Enumerator] Returns an enumerator that yields error
58
- # shapes.
59
- def errors
60
- errors = (definition['errors'] || [])
61
- errors = errors.map { |error| shape_for(error) }
62
- errors.enum_for(:each)
37
+ def [](key)
38
+ @metadata[key.to_s]
63
39
  end
64
40
 
65
- private
66
-
67
- def shape_for(definition)
68
- if definition.key?('shape')
69
- @shape_map.shape(definition)
70
- else
71
- Shapes::Shape.new(definition, shape_map: @shape_map)
72
- end
41
+ def []=(key, value)
42
+ @metadata[key.to_s] = value
73
43
  end
74
44
 
75
45
  end
@@ -4,447 +4,203 @@ module Seahorse
4
4
  module Model
5
5
  module Shapes
6
6
 
7
- @types = {}
8
-
9
- class << self
10
-
11
- # Registers a shape by type.
12
- #
13
- # Shapes.register('structure', Shapes::StructureShape)
14
- #
15
- # Shapes.type('structure')
16
- # #=> #<Shapes::StructureShape>
17
- #
18
- # @param [String] type
19
- # @param [Class<Shape>] shape_class
20
- # @return [void]
21
- # @raise [ArgumentError] Raises an error if the given type or
22
- # shape class have already been registered.
23
- def register(type, shape_class)
24
- shape_class.type = type
25
- @types[type] = shape_class
26
- end
27
-
28
- # Given a type, this method returned the registered shape class.
29
- # @param [String] type
30
- # @return [Class<Shape>]
31
- # @raise [ArgumentError] Raises an ArgumentError if there is no
32
- # shape class registered with the given `type`.
33
- def shape_class(type)
34
- if @types.key?(type)
35
- @types[type]
36
- else
37
- raise ArgumentError, "unregistered type `#{type}'"
38
- end
39
- end
40
-
41
- # Returns an enumerator that yields registered type names and shape
42
- # classes.
43
- #
44
- # Seahorse::Model::Shapes.types.each do |type, shape_class|
45
- # puts "%s => %s" % [type, shape_class.name]
46
- # end
47
- #
48
- # @return [Enumerator] Returns an enumerable object that yields
49
- # registered type names and shape classes.
50
- def types
51
- Enumerator.new do |y|
52
- @types.each do |name, shape_class|
53
- y.yield(name, shape_class)
7
+ class ShapeRef
8
+
9
+ def initialize(options = {})
10
+ @metadata = {}
11
+ @required = false
12
+ @deprecated = false
13
+ options.each do |key, value|
14
+ if key == :metadata
15
+ value.each do |k,v|
16
+ self[k] = v
17
+ end
18
+ else
19
+ send("#{key}=", value)
54
20
  end
55
21
  end
56
22
  end
57
23
 
58
- end
59
-
60
- class Shape
61
-
62
- # @param [Hash] definition
63
- # @option options [ShapeMap] :shape_map (nil)
64
- def initialize(definition, options = {})
65
- definition['type'] ||= self.class.type
66
- @name = definition['shape']
67
- @definition = definition
68
- @type = definition['type']
69
- @location = definition['location'] || 'body'
70
- @location_name = definition['locationName']
71
- @shape_map = options[:shape_map] || ShapeMap.new
72
- end
73
-
74
- # @return [String]
75
- attr_reader :name
76
-
77
- # @return [Hash]
78
- attr_reader :definition
79
-
80
- # @return [String] The type name for this shape.
81
- attr_reader :type
82
-
83
- # @return [String] Returns one of 'body', 'uri', 'headers', 'status_code'
84
- attr_reader :location
85
-
86
- # @return [String, nil] Typically only set for shapes that are
87
- # structure members. Serialized names are typically set on the
88
- # shape references, not on the shape definition.
89
- attr_reader :location_name
90
-
91
- attr_reader :documentation
92
-
93
- # @return [ShapeMap]
94
- attr_reader :shape_map
24
+ # @return [Shape]
25
+ attr_accessor :shape
95
26
 
96
27
  # @return [String, nil]
97
- def documentation
98
- @definition['documentation']
99
- end
100
-
101
- # @param [String] key
102
- # @return [Object, nil]
103
- def metadata(key)
104
- @definition[key.to_s]
105
- end
28
+ attr_accessor :location
106
29
 
107
- # @api private
108
- # @return [String]
109
- def inspect
110
- "#<#{self.class.name}>"
111
- end
112
-
113
- # @api private
114
- def with(options)
115
- self.class.new(@definition.merge(options), shape_map: shape_map)
116
- end
30
+ # @return [String, nil]
31
+ attr_accessor :location_name
117
32
 
118
- private
33
+ # @return [Boolean]
34
+ attr_accessor :required
119
35
 
120
- def underscore(string)
121
- Util.underscore(string)
122
- end
36
+ # @return [String, nil]
37
+ attr_accessor :documentation
123
38
 
124
- def shape_at(key)
125
- if @definition[key]
126
- shape_for(@definition[key])
127
- else
128
- raise ArgumentError, "expected shape definition at #{key.inspect}"
129
- end
130
- end
39
+ # @return [Boolean]
40
+ attr_accessor :deprecated
131
41
 
132
- def shape_for(reference)
133
- if reference.key?('shape')
134
- # shape ref given, e.g. { "shape" => "ShapeName" },
135
- # use the shape map to resolve this reference
136
- @shape_map.shape(reference)
42
+ # Gets metadata for the given `key`.
43
+ def [](key)
44
+ if @metadata.key?(key.to_s)
45
+ @metadata[key.to_s]
137
46
  else
138
- Shape.new(reference, shape_map: @shape_map)
47
+ @shape[key.to_s]
139
48
  end
140
49
  end
141
50
 
142
- class << self
143
-
144
- # @return [String]
145
- attr_accessor :type
146
-
147
- # Constructs and returns a new shape object. You must specify
148
- # the shape type using the "type" option or you must construct
149
- # the shape using the appropriate subclass of `Shape`.
150
- #
151
- # @example Constructing a new shape
152
- #
153
- # shape = Seahorse::Model::Shapes::Shape.new("type" => "structure")
154
- #
155
- # shape.class
156
- # #=> Seahorse::Model::Shapes::Structure
157
- #
158
- # shape.definition
159
- # #=> { "type" => "structure" }
160
- #
161
- # @example Constructing a new shape using the shape class
162
- #
163
- # shape = Seahorse::Model::Shapes::String.new
164
- # shape.definition
165
- # #=> { "type" => "string" }
166
- #
167
- # @param [Hash] definition
168
- # @option options [ShapeMap] :shape_map
169
- # @return [Shape]
170
- def new(definition = {}, options = {})
171
- if self == Shape
172
- from_type(definition, options)
173
- else
174
- super(apply_type(definition), options)
175
- end
176
- end
177
-
178
- private
179
-
180
- def apply_type(definition)
181
- case definition['type']
182
- when type then definition
183
- when nil then { 'type' => type }.merge(definition)
184
- else raise ArgumentError, "expected 'type' to be `#{type}'"
185
- end
186
- end
187
-
188
- def from_type(definition, options)
189
- if type = definition['type']
190
- Shapes.shape_class(type).new(definition, options)
191
- else
192
- raise ArgumentError, 'must specify "type" in the definition'
193
- end
194
- end
195
-
51
+ # Sets metadata for the given `key`.
52
+ def []=(key, value)
53
+ @metadata[key.to_s] = value
196
54
  end
197
55
 
198
56
  end
199
57
 
200
- class Structure < Shape
58
+ class Shape
201
59
 
202
- def initialize(definition, options = {})
203
- super
204
- @members = {}
205
- @member_refs = {}
206
- @member_names = {}
207
- compute_member_names
208
- compute_required_member_names
209
- @member_names = @member_names.values
60
+ def initialize
61
+ @metadata = {}
210
62
  end
211
63
 
212
- # @return [Array<Symbol>] Returns a list of members names.
213
- attr_reader :member_names
214
-
215
- # @return [Array<Symbol>] Returns a list of required members names.
216
- attr_reader :required
217
-
218
- # @return [String, nil] Returns the name of the payload member if set.
219
- attr_reader :payload
220
-
221
- # @return [Shape, nil]
222
- def payload_member
223
- if payload
224
- @payload_member ||= member(payload)
225
- else
226
- nil
227
- end
228
- end
229
-
230
- # @param [Symbol] name
231
- # @return [Shape]
232
- def member(name)
233
- if ref = @member_refs[name.to_sym]
234
- @members[name] ||= shape_for(ref)
235
- else
236
- raise ArgumentError, "no such member :#{name}"
237
- end
238
- end
64
+ # @return [String]
65
+ attr_accessor :name
239
66
 
240
- # @param [Symbol] name
241
- # @return [Boolean] Returns `true` if this structure has a member with
242
- # the given name.
243
- def member?(name)
244
- @member_refs.key?(name.to_sym)
245
- end
67
+ # @return [String, nil]
68
+ attr_accessor :documentation
246
69
 
247
- # @return [Enumerable<Symbol,Shape>] Returns an enumerator that yields
248
- # member names and shapes.
249
- def members
250
- Enumerator.new do |y|
251
- member_names.map do |member_name|
252
- y.yield(member_name, member(member_name))
253
- end
254
- end
70
+ # Gets metadata for the given `key`.
71
+ def [](key)
72
+ @metadata[key.to_s]
255
73
  end
256
74
 
257
- # Searches the structure members for a shape with the given
258
- # serialized name.
259
- #
260
- # If found, the shape will be returned with its symbolized member
261
- # name.
262
- #
263
- # If no shape is found with the given serialized name, then
264
- # nil is returned.
265
- #
266
- # @example
267
- #
268
- # name, shape = structure.member_by_location_name('SerializedName')
269
- # name #=> :member_name
270
- # shape #=> instance of Seahorse::Model::Shapes::Shape
271
- #
272
- # @param [String] location_name
273
- # @return [Array<Symbol,Shape>, nil]
274
- def member_by_location_name(location_name)
275
- @by_location_name ||= index_members_by_location_name
276
- @by_location_name[location_name]
75
+ # Sets metadata for the given `key`.
76
+ def []=(key, value)
77
+ @metadata[key.to_s] = value
277
78
  end
278
79
 
279
- private
80
+ end
280
81
 
281
- def index_members_by_location_name
282
- members.each.with_object({}) do |(name, shape), hash|
283
- hash[shape.location_name] = [name, shape]
284
- end
285
- end
82
+ class BlobShape < Shape
286
83
 
287
- def compute_member_names
288
- (definition['members'] || {}).each do |orig_name,ref|
289
- name = underscore(orig_name).to_sym
290
- if ref['location'] == 'headers'
291
- @member_refs[name] = ref
292
- else
293
- @member_refs[name] = { 'locationName' => orig_name }.merge(ref)
294
- end
295
- @member_names[orig_name] = name
296
- end
297
- @payload = @member_names[definition['payload']] if definition['payload']
298
- end
84
+ # @return [Integer, nil]
85
+ attr_accessor :min
299
86
 
300
- def compute_required_member_names
301
- @required = (definition['required'] || []).map do |orig_name|
302
- @member_names[orig_name]
303
- end
304
- end
87
+ # @return [Integer, nil]
88
+ attr_accessor :max
305
89
 
306
90
  end
307
91
 
308
- class List < Shape
92
+ class BooleanShape < Shape; end
309
93
 
310
- def initialize(definition, options = {})
311
- super
312
- @min = definition['min']
313
- @max = definition['max']
314
- @member = shape_at('member')
315
- end
94
+ class FloatShape < Shape; end
316
95
 
317
- # @return [Shape]
318
- attr_reader :member
96
+ class IntegerShape < Shape
319
97
 
320
98
  # @return [Integer, nil]
321
- attr_reader :min
99
+ attr_accessor :min
322
100
 
323
101
  # @return [Integer, nil]
324
- attr_reader :max
102
+ attr_accessor :max
325
103
 
326
104
  end
327
105
 
328
- class Map < Shape
106
+ class ListShape < Shape
329
107
 
330
- def initialize(definition, options = {})
331
- super
332
- @min = definition['min']
333
- @max = definition['max']
334
- @key = shape_at('key')
335
- @value = shape_at('value')
336
- end
337
-
338
- # @return [Shape]
339
- attr_reader :key
340
-
341
- # @return [Shape]
342
- attr_reader :value
108
+ # @return [ShapeRef]
109
+ attr_accessor :member
343
110
 
344
111
  # @return [Integer, nil]
345
- attr_reader :min
112
+ attr_accessor :min
346
113
 
347
114
  # @return [Integer, nil]
348
- attr_reader :max
115
+ attr_accessor :max
349
116
 
350
117
  end
351
118
 
352
- class String < Shape
119
+ class MapShape < Shape
353
120
 
354
- def initialize(definition, options = {})
355
- super
356
- @enum = Set.new(definition['enum']) if definition['enum']
357
- @pattern = definition['pattern']
358
- @min = definition['min']
359
- @max = definition['max']
360
- end
361
-
362
- # @return [Set, nil]
363
- attr_reader :enum
121
+ # @return [ShapeRef]
122
+ attr_accessor :key
364
123
 
365
- # @return [String, nil]
366
- attr_reader :pattern
124
+ # @return [ShapeRef]
125
+ attr_accessor :value
367
126
 
368
127
  # @return [Integer, nil]
369
- attr_reader :min
128
+ attr_accessor :min
370
129
 
371
130
  # @return [Integer, nil]
372
- attr_reader :max
131
+ attr_accessor :max
373
132
 
374
133
  end
375
134
 
376
- class Character < String; end
135
+ class StringShape < Shape
377
136
 
378
- class Byte < String; end
137
+ # @return [Set<String>, nil]
138
+ attr_accessor :enum
379
139
 
380
- class Timestamp < Shape
381
-
382
- def initialize(definition, options = {})
383
- @format = definition['timestampFormat']
384
- super
385
- end
386
-
387
- # @return [String]
388
- attr_reader :format
140
+ # @return [Integer, nil]
141
+ attr_accessor :min
389
142
 
390
- # @param [Time] time
391
- # @param [String] default_format The format to default to
392
- # when {#format} is not set on this timestamp shape.
393
- # @return [String]
394
- def format_time(time, default_format)
395
- format = @format || default_format
396
- case format
397
- when 'iso8601' then time.utc.iso8601
398
- when 'rfc822' then time.utc.rfc822
399
- when 'httpdate' then time.httpdate
400
- when 'unixTimestamp' then time.utc.to_i
401
- else
402
- msg = "invalid timestamp format #{format.inspect}"
403
- raise ArgumentError, msg
404
- end
405
- end
143
+ # @return [Integer, nil]
144
+ attr_accessor :max
406
145
 
407
146
  end
408
147
 
409
- class Integer < Shape
148
+ class StructureShape < Shape
410
149
 
411
- def initialize(definition, options = {})
412
- @min = definition['min']
413
- @max = definition['max']
414
- super
150
+ def initialize(options = {})
151
+ @members = {}
152
+ @members_by_location_name = {}
153
+ @required = Set.new
154
+ super()
415
155
  end
416
156
 
417
- # @return [Integer, nil]
418
- attr_reader :min
157
+ # @return [Set<Symbol>]
158
+ attr_accessor :required
419
159
 
420
- # @return [Integer, nil]
421
- attr_reader :max
160
+ # @param [Symbol] name
161
+ # @param [ShapeRef] shape_ref
162
+ def add_member(name, shape_ref)
163
+ name = name.to_sym
164
+ @required << name if shape_ref.required
165
+ @members_by_location_name[shape_ref.location_name] = [name, shape_ref]
166
+ @members[name] = shape_ref
167
+ end
422
168
 
423
- end
169
+ # @return [Array<Symbol>]
170
+ def member_names
171
+ @members.keys
172
+ end
424
173
 
425
- class Long < Integer; end
174
+ # @param [Symbol] member_name
175
+ # @return [Boolean] Returns `true` if there exists a member with
176
+ # the given name.
177
+ def member?(member_name)
178
+ @members.key?(member_name.to_sym)
179
+ end
426
180
 
427
- class Float < Shape; end
181
+ # @return [Enumerator<[Symbol,ShapeRef]>]
182
+ def members
183
+ @members.to_enum
184
+ end
428
185
 
429
- class Double < Float; end
186
+ # @param [Symbol] name
187
+ # @return [ShapeRef]
188
+ def member(name)
189
+ if member?(name)
190
+ @members[name.to_sym]
191
+ else
192
+ raise ArgumentError, "no such member #{name.inspect}"
193
+ end
194
+ end
430
195
 
431
- class Boolean < Shape; end
196
+ # @api private
197
+ def member_by_location_name(location_name)
198
+ @members_by_location_name[location_name]
199
+ end
432
200
 
433
- class Blob < Shape; end
201
+ end
434
202
 
435
- register('blob', Shapes::Blob)
436
- register('byte', Shapes::Byte)
437
- register('boolean', Shapes::Boolean)
438
- register('character', Shapes::Character)
439
- register('double', Shapes::Double)
440
- register('float', Shapes::Float)
441
- register('integer', Shapes::Integer)
442
- register('list', Shapes::List)
443
- register('long', Shapes::Long)
444
- register('map', Shapes::Map)
445
- register('string', Shapes::String)
446
- register('structure', Shapes::Structure)
447
- register('timestamp', Shapes::Timestamp)
203
+ class TimestampShape < Shape; end
448
204
 
449
205
  end
450
206
  end