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
data/lib/aws.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'multi_json'
2
+
1
3
  module Aws
2
4
 
3
5
  # @api private
@@ -12,6 +14,7 @@ module Aws
12
14
 
13
15
  @service_added_callbacks = []
14
16
 
17
+ autoload :Client, "#{SRC}/client"
15
18
  autoload :CredentialProviderChain, "#{SRC}/credential_provider_chain"
16
19
  autoload :Credentials, "#{SRC}/credentials"
17
20
  autoload :EmptyStructure, "#{SRC}/empty_structure"
@@ -21,7 +24,6 @@ module Aws
21
24
  autoload :PageableResponse, "#{SRC}/pageable_response"
22
25
  autoload :RestBodyHandler, "#{SRC}/rest_body_handler"
23
26
  autoload :Service, "#{SRC}/service"
24
- autoload :ServiceBuilder, "#{SRC}/service_builder"
25
27
  autoload :SharedCredentials, "#{SRC}/shared_credentials"
26
28
  autoload :Structure, "#{SRC}/structure"
27
29
  autoload :TreeHash, "#{SRC}/tree_hash"
@@ -30,10 +32,11 @@ module Aws
30
32
  # @api private
31
33
  module Api
32
34
  autoload :Customizer, "#{SRC}/api/customizer"
33
- autoload :DocExample, "#{SRC}/api/doc_example"
34
- autoload :Documentor, "#{SRC}/api/documentor"
35
+ autoload :Documenter, "#{SRC}/api/documenter"
35
36
  autoload :Manifest, "#{SRC}/api/manifest"
36
37
  autoload :ManifestBuilder, "#{SRC}/api/manifest_builder"
38
+ autoload :OperationDocumenter, "#{SRC}/api/operation_documenter"
39
+ autoload :OperationExample, "#{SRC}/api/operation_example"
37
40
  autoload :ServiceCustomizations, "#{SRC}/api/service_customizations"
38
41
  end
39
42
 
@@ -57,7 +60,9 @@ module Aws
57
60
  end
58
61
 
59
62
  module Plugins
63
+ autoload :CSDConditionalSigning, "#{SRC}/plugins/csd_conditional_signing"
60
64
  autoload :DynamoDBExtendedRetries, "#{SRC}/plugins/dynamodb_extended_retries"
65
+ autoload :DynamoDBSimpleAttributes, "#{SRC}/plugins/dynamodb_simple_attributes"
61
66
  autoload :EC2CopyEncryptedSnapshot, "#{SRC}/plugins/ec2_copy_encrypted_snapshot"
62
67
  autoload :GlacierAccountId, "#{SRC}/plugins/glacier_account_id"
63
68
  autoload :GlacierApiVersion, "#{SRC}/plugins/glacier_api_version"
@@ -76,6 +81,7 @@ module Aws
76
81
  autoload :S3Md5s, "#{SRC}/plugins/s3_md5s"
77
82
  autoload :S3Redirects, "#{SRC}/plugins/s3_redirects"
78
83
  autoload :S3SseCpk, "#{SRC}/plugins/s3_sse_cpk"
84
+ autoload :S3UrlEncodedKeys, "#{SRC}/plugins/s3_url_encoded_keys"
79
85
  autoload :SQSQueueUrls, "#{SRC}/plugins/sqs_queue_urls"
80
86
  autoload :SWFReadTimeouts, "#{SRC}/plugins/swf_read_timeouts"
81
87
  autoload :UserAgent, "#{SRC}/plugins/user_agent"
@@ -132,9 +138,8 @@ module Aws
132
138
  end
133
139
  end
134
140
 
135
- # Adds a plugin to every AWS client class. This registers the plugin
136
- # with each versioned client for each service.
137
- # @param [Plugin] plugin
141
+ # Applies the plugin to every AWS client class.
142
+ # @param [Seahorse::Client::Plugin] plugin
138
143
  # @return [void]
139
144
  def add_plugin(plugin)
140
145
  client_classes.each do |client_class|
@@ -142,9 +147,8 @@ module Aws
142
147
  end
143
148
  end
144
149
 
145
- # Removes a plugin to from AWS client class. This removes the plugin
146
- # from each versioned client for each service.
147
- # @param [Plugin] plugin
150
+ # Removes the plugin from every AWS client class.
151
+ # @param [Seahorse::Client::Plugin] plugin
148
152
  # @return [void]
149
153
  def remove_plugin(plugin)
150
154
  client_classes.each do |client_class|
@@ -152,76 +156,115 @@ module Aws
152
156
  end
153
157
  end
154
158
 
155
- # @api private
156
- def services
157
- @services
158
- end
159
-
160
- # @return [Array<Class>]
161
- # @api private
162
- def client_classes
163
- @services.values.map { |svc_module, options| svc_module.const_get(:Client) }
164
- end
165
-
166
159
  # Yields to the given block for each service that has already been
167
160
  # defined via {add_service}. Also yields to the given block for
168
161
  # each new service added after the callback is registered.
169
162
  # @api private
170
163
  def service_added(&block)
171
164
  callback = Proc.new
165
+ services.each(&callback)
166
+ @service_added_callbacks << callback
167
+ end
168
+
169
+ # @api private
170
+ def services(&block)
171
+ return enum_for(:services) unless block_given?
172
172
  @services.each do |svc_name, (svc_module, options)|
173
- callback.call(svc_name, svc_module, options)
173
+ yield(svc_name, svc_module, options)
174
174
  end
175
- @service_added_callbacks << callback
176
175
  end
177
176
 
178
- # Registers a new service. Creates a Client class and an Errors
179
- # module.
180
- #
181
- # # register a new service & API version
182
- # Aws.add_service('S3', {
183
- # 'api' => '/path/to/api.json',
184
- # 'paginators' => '/path/to/paginators.json',
185
- # 'resources' => '/path/to/resources.json',
186
- # })
177
+ # @api private
178
+ def load_json(path)
179
+ path = File.join(GEM_ROOT, path) unless path.match(/^#{File::SEPARATOR}/)
180
+ MultiJson.load(File.open(path, 'r', encoding: 'UTF-8') { |f| f.read })
181
+ end
182
+
183
+ # Registers a new service.
187
184
  #
188
- # # create a versioned client
189
- # Aws::S3::Client.new
190
- # #=> #<Aws::S3::Client>
185
+ # Aws.add_service('SvcName',
186
+ # api: '/path/to/svc.api.json',
187
+ # paginators: '/path/to/svc.paginators.json',
188
+ # resources: '/path/to/svc.resources.json')
191
189
  #
192
- # To register multiple API versions for the same service, use separate
193
- # service names.
190
+ # Aws::SvcName::Client.new
191
+ # #=> #<Aws::SvcName::Client>
194
192
  #
195
- # @param (see ServiceBuilder.new)
196
- # @option (see ServiceBuilder.new)
197
- # @return (see ServiceBuilder.new)
193
+ # @param [String] svc_name The name of the service. This will also be
194
+ # the namespace under {Aws}.
195
+ # @option options[required,String,Hash,Seahorse::Model::Api] :api
196
+ # @option options[String,Hash,Paging::Provider] :paginators
197
+ # @option options[String] :resources
198
+ # @return [Module<Service>]
198
199
  def add_service(svc_name, options = {})
199
- identifier = svc_name.downcase.to_sym
200
- svc_module = ServiceBuilder.new(identifier, options)
200
+ svc_module = Module.new { extend Service }
201
201
  const_set(svc_name, svc_module)
202
- @services[identifier] = [svc_module, options]
202
+ @services[svc_name] = [svc_module, options]
203
203
  @service_added_callbacks.each do |callback|
204
- callback.call(identifier, svc_module, options)
204
+ callback.call(svc_name, *@services[svc_name])
205
205
  end
206
206
  svc_module
207
207
  end
208
208
 
209
+ private
210
+
211
+ def client_classes
212
+ @services.values.map { |svc_module, options| svc_module.const_get(:Client) }
213
+ end
214
+
215
+ def api_files
216
+ files = Dir.glob(File.join(GEM_ROOT, 'apis', '*.json'))
217
+ files.each.with_object({}) do |path, services|
218
+ svc_name, type = File.basename(path).split('.')
219
+ services[svc_name] ||= {}
220
+ services[svc_name][type.to_sym] = path
221
+ end
222
+ end
223
+
224
+ end
225
+
226
+ api_files.each do |service_name, files|
227
+ add_service(service_name, files)
228
+ end
229
+
230
+ # build service client classes
231
+ service_added do |name, svc_module, options|
232
+ svc_module.const_set(:Client, Client.define(name, options))
233
+ svc_module.const_set(:Errors, Module.new { extend Errors::DynamicErrors })
234
+ end
235
+
236
+ # build service paginators
237
+ service_added do |name, svc_module, options|
238
+ paginators = options[:paginators]
239
+ paginators = case paginators
240
+ when Paging::Provider then paginators
241
+ when Hash then Paging::Provider.new(paginators)
242
+ when String then Paging::Provider.new(Aws.load_json(paginators))
243
+ when nil then Paging::NullProvider.new
244
+ else raise ArgumentError, 'invalid :paginators option'
245
+ end
246
+ svc_module.const_get(:Client).paginators = paginators
209
247
  end
210
248
 
211
- service_added do |identifier, svc_module, _|
212
- define_singleton_method(identifier) do |options={}|
213
- unless instance_variable_get("@#{identifier}_warned")
214
- instance_variable_set("@#{identifier}_warned", true)
215
- warn(<<-MSG.strip)
216
- Aws.#{identifier} deprecated as of v2.0.0.rc14 and will be removed as of v2.0.0.0 final; use #{svc_module.name}::Client.new() instead
217
- MSG
249
+ # deprecated = define helper method for client class, this will be
250
+ # replaced eventually with a helper that returns a resource object
251
+ # for the service.
252
+ service_added do |name, svc_module, _|
253
+ method_name = name.downcase.to_sym
254
+ define_singleton_method(method_name) do |options={}|
255
+ unless instance_variable_get("@#{method_name}_warned")
256
+ instance_variable_set("@#{method_name}_warned", true)
257
+ msg = "Aws.#{method_name} is deprecated as of v2.0.0.rc14 and will be "
258
+ msg << "removed as of v2.0.0.0 final; use Aws::#{name}::Client.new "
259
+ msg << "instead"
260
+ warn(msg)
218
261
  end
219
- svc_module::Client.new(options)
262
+ svc_module.const_get(:Client).new(options)
220
263
  end
221
264
  end
222
265
 
223
- Api::Manifest.default_manifest.services.each do |service|
224
- add_service(service.name, service.versions.values.last)
266
+ module DynamoDB
267
+ autoload :AttributeValue, "#{SRC}/dynamodb/attribute_value"
225
268
  end
226
269
 
227
270
  end
@@ -0,0 +1,238 @@
1
+ require 'multi_json'
2
+ require 'erb'
3
+
4
+ module Aws
5
+ module Api
6
+ class Documenter
7
+
8
+ def initialize(svc_module, docs_path)
9
+ @svc_module = svc_module
10
+ @svc_name = svc_module.name.split('::').last
11
+ @client_class = svc_module.const_get(:Client)
12
+ @api = @client_class.api
13
+ @full_name = @api.metadata('serviceFullName')
14
+ @error_names = @api.operations.map {|_,o| o.errors.map(&:name) }
15
+ @error_names = @error_names.flatten.uniq.sort
16
+ @namespace = YARD::Registry['Aws']
17
+ apply_docstrings(docs_path)
18
+ end
19
+
20
+ def apply
21
+ document_service
22
+ document_client
23
+ document_errors
24
+ end
25
+
26
+ private
27
+
28
+ def document_service
29
+ yard_mod = YARD::CodeObjects::ModuleObject.new(@namespace, @svc_name)
30
+ yard_mod.docstring = service_docstring
31
+ yard_mod.docstring.add_tag(YARD::Tags::Tag.new(:service, @svc_name))
32
+ @namespace = yard_mod
33
+ end
34
+
35
+ def service_docstring
36
+ path = "doc-src/services/#{@svc_name}/service.md"
37
+ path = 'doc-src/services/default/service.md' unless File.exists?(path)
38
+ template = read(path)
39
+ svc_name = @svc_name
40
+ api = @api
41
+ full_name = @full_name
42
+ ERB.new(template).result(binding)
43
+ end
44
+
45
+ def document_errors
46
+ yard_mod = YARD::CodeObjects::ModuleObject.new(@namespace, 'Errors')
47
+ yard_mod.docstring = errors_docstring
48
+
49
+ base_error = YARD::CodeObjects::ClassObject.new(yard_mod, 'ServiceError')
50
+ base_error.docstring = "Base class for all Aws::#{@svc_name} errors."
51
+ base_error.superclass = YARD::Registry['Aws::Errors::ServiceError']
52
+
53
+ @error_names.each do |error_name|
54
+ error_klass = YARD::CodeObjects::ClassObject.new(yard_mod, error_name)
55
+ error_klass.superclass = base_error
56
+ end
57
+ end
58
+
59
+ def errors_docstring
60
+ path = "doc-src/services/#{@svc_name}/errors.md"
61
+ path = 'doc-src/services/default/errors.md' unless File.exists?(path)
62
+ template = read(path)
63
+ svc_name = @svc_name
64
+ api = @api
65
+ full_name = @full_name
66
+ known_errors = @error_names
67
+ ERB.new(template).result(binding)
68
+ end
69
+
70
+ def document_client
71
+ yard_class = YARD::CodeObjects::ClassObject.new(@namespace, 'Client')
72
+ yard_class.superclass = YARD::Registry['Seahorse::Client::Base']
73
+ yard_class.docstring = client_docstring
74
+ document_client_constructor(yard_class)
75
+ document_client_operations(yard_class)
76
+ end
77
+
78
+ def client_docstring
79
+ path = "doc-src/services/#{@svc_name}/client.md"
80
+ path = 'doc-src/services/default/client.md' unless File.exists?(path)
81
+ render(path)
82
+ end
83
+
84
+ def render(path)
85
+ svc_name = @svc_name
86
+ api = @api
87
+ full_name = @full_name
88
+ ERB.new(File.read(path)).result(binding)
89
+ end
90
+
91
+ def document_client_constructor(namespace)
92
+ constructor = YARD::CodeObjects::MethodObject.new(namespace, :initialize)
93
+ constructor.group = 'Constructor'
94
+ constructor.scope = :instance
95
+ constructor.parameters << ['options', '{}']
96
+ constructor.docstring = client_constructor_docstring
97
+ end
98
+
99
+ def client_constructor_docstring
100
+ <<-DOCS.strip
101
+ Constructs an API client.
102
+ #{client_constructor_options}
103
+ @return [#{@client_class.name}] Returns an API client.
104
+ DOCS
105
+ end
106
+
107
+ def client_constructor_options
108
+ options = {}
109
+ @client_class.plugins.each do |plugin|
110
+ if p = YARD::Registry[plugin.name]
111
+ p.tags.each do |tag|
112
+ if tag.tag_name == 'seahorse_client_option'
113
+ option_name = tag.text.match(/.+(:\w+)/)[1]
114
+ option_text = "@option options " + tag.text.split("\n").join("\n ")
115
+ options[option_name] = option_text +
116
+ " See {#{plugin.name}} for more details."
117
+ end
118
+ end
119
+ end
120
+ end
121
+ options.sort_by { |k,v| k }.map(&:last).join("\n")
122
+ end
123
+
124
+ def document_client_operations(namespace)
125
+ @api.operations.each do |method_name, operation|
126
+ document_client_operation(namespace, method_name, operation)
127
+ end
128
+ end
129
+
130
+ def document_client_operation(namespace, method_name, operation)
131
+ m = YARD::CodeObjects::MethodObject.new(namespace, method_name)
132
+ m.group = 'Service Operations'
133
+ m.scope = :instance
134
+ m.parameters << ['params', '{}']
135
+ m.docstring = operation_docstring(method_name, operation)
136
+ end
137
+
138
+ def operation_docstring(method_name, operation)
139
+
140
+ documentor = OperationDocumenter.new(
141
+ svc_var_name: @svc_name.downcase,
142
+ method_name: method_name,
143
+ operation: operation)
144
+
145
+ tabs = Tabulator.new.tap do |t|
146
+ t.tab(method_name, 'Formatting Example') do
147
+ "<pre><code>#{documentor.example}</code></pre>"
148
+ end
149
+ t.tab(method_name, 'Request Parameters') do
150
+ documentor.input
151
+ end
152
+ t.tab(method_name, 'Response Structure') do
153
+ documentor.output
154
+ end
155
+ end
156
+
157
+ errors = (operation.errors || []).map { |shape| shape.name }
158
+ errors = errors.map { |e| "@raise [Errors::#{e}]" }.join("\n")
159
+
160
+ docstring = <<-DOCSTRING.strip
161
+ <p>Calls the #{operation.name} operation.<p>
162
+ #{documentor.api_ref(operation)}
163
+ #{tabs}
164
+ @param [Hash] params ({})
165
+ @return [PageableResponse]
166
+ #{errors}
167
+ DOCSTRING
168
+ end
169
+
170
+ class Tabulator
171
+
172
+ def initialize
173
+ @tabs = []
174
+ @tab_contents = []
175
+ end
176
+
177
+ def tab(method_name, tab_name, &block)
178
+ tab_class = tab_name.downcase.gsub(/[^a-z]+/i, '-')
179
+ tab_id = "#{method_name.to_s.gsub(/_/, '-')}-#{tab_class}"
180
+ class_names = ['tab-contents', tab_class]
181
+ @tabs << [tab_id, tab_name]
182
+ @tab_contents << "<div class=\"#{class_names.join(' ')}\" id=\"#{tab_id}\">"
183
+ @tab_contents << yield
184
+ @tab_contents << '</div>'
185
+ end
186
+
187
+ def to_html
188
+ lines = []
189
+ lines << '<div class="tab-box">'
190
+ lines << '<ul class="tabs">'
191
+ @tabs.each do |tab_id, tab_name|
192
+ lines << "<li data-tab-id=\"#{tab_id}\">#{tab_name}</li>"
193
+ end
194
+ lines << '</ul>'
195
+ lines.concat(@tab_contents)
196
+ lines << '</div>'
197
+ lines.join
198
+ end
199
+ alias inspect to_html
200
+ alias to_str to_html
201
+ alias to_s to_html
202
+
203
+ end
204
+
205
+ def apply_docstrings(path)
206
+ docs = MultiJson.load(read(path))
207
+ api = @api.definition
208
+
209
+ api['documentation'] = docs['service']
210
+
211
+ docs['operations'].each do |operation, doc|
212
+ api['operations'][operation]['documentation'] = doc
213
+ end
214
+
215
+ docs['shapes'].each do |shape_name, shape|
216
+ api['shapes'][shape_name]['documentation'] = shape['base']
217
+ shape['refs'].each do |ref,doc|
218
+ target_shape_name, member = ref.split('$')
219
+ target_shape = api['shapes'][target_shape_name]
220
+ case target_shape['type']
221
+ when 'structure' then target_shape['members'][member]['documentation'] = doc
222
+ when 'list' then target_shape[member]['documentation'] = doc
223
+ when 'map' then target_shape[member]['documentation'] = doc
224
+ else raise 'not handled'
225
+ end
226
+ end
227
+ end
228
+
229
+ @api = Seahorse::Model::Api.new(api)
230
+ end
231
+
232
+ def read(path)
233
+ File.open(path, 'r', encoding: 'UTF-8') { |f| f.read }
234
+ end
235
+
236
+ end
237
+ end
238
+ end