-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathclient.rb
More file actions
368 lines (350 loc) · 16.8 KB
/
client.rb
File metadata and controls
368 lines (350 loc) · 16.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# frozen_string_literal: true
# This is generated code!
require_relative 'plugins/endpoint'
require 'smithy-client/plugins/checksum_required'
require 'smithy-client/plugins/content_length'
require 'smithy-client/plugins/default_params'
require 'smithy-client/plugins/host_prefix'
require 'smithy-client/plugins/idempotency_token'
require 'smithy-client/plugins/logging'
require 'smithy-client/plugins/net_http'
require 'smithy-client/plugins/pageable_response'
require 'smithy-client/plugins/param_converter'
require 'smithy-client/plugins/param_validator'
require 'smithy-client/plugins/raise_response_errors'
require 'smithy-client/plugins/request_compression'
require 'smithy-client/plugins/resolve_auth'
require 'smithy-client/plugins/response_target'
require 'smithy-client/plugins/retry_errors'
require 'smithy-client/plugins/sign_requests'
require 'smithy-client/plugins/stub_responses'
require 'smithy-client/plugins/user_agent'
module Weather
# An API client for Weather.
# See {#initialize} for a full list of supported configuration options.
class Client < Smithy::Client::Base
include Smithy::Client::Stubs
self.service = Schema::Weather
@identifier = :weather
add_plugin(::Weather::Plugins::Endpoint)
add_plugin(Smithy::Client::Plugins::ChecksumRequired)
add_plugin(Smithy::Client::Plugins::ContentLength)
add_plugin(Smithy::Client::Plugins::DefaultParams)
add_plugin(Smithy::Client::Plugins::HostPrefix)
add_plugin(Smithy::Client::Plugins::IdempotencyToken)
add_plugin(Smithy::Client::Plugins::Logging)
add_plugin(Smithy::Client::Plugins::NetHTTP)
add_plugin(Smithy::Client::Plugins::PageableResponse)
add_plugin(Smithy::Client::Plugins::ParamConverter)
add_plugin(Smithy::Client::Plugins::ParamValidator)
add_plugin(Smithy::Client::Plugins::RaiseResponseErrors)
add_plugin(Smithy::Client::Plugins::RequestCompression)
add_plugin(Smithy::Client::Plugins::ResolveAuth)
add_plugin(Smithy::Client::Plugins::ResponseTarget)
add_plugin(Smithy::Client::Plugins::RetryErrors)
add_plugin(Smithy::Client::Plugins::SignRequests)
add_plugin(Smithy::Client::Plugins::StubResponses)
add_plugin(Smithy::Client::Plugins::UserAgent)
# @param options [Hash] Client options
# @option options [Boolean] :adaptive_retry_wait_to_fill (true)
# When true, the request will sleep until there is sufficient client side capacity to retry
# the request. When false, the request will raise a `CapacityNotAvailableError` and will
# not retry instead of sleeping.
# @option options [#resolve(context)] :auth_resolver (AuthResolver.new)
# An object that resolves authentication schemes for request signing.
# @option options [Array<String>] :auth_scheme_preference
# An ordered list of preferred authentication schemes to use when making a request.
# The items in the list must be a fully qualified scheme IDs, such as `smithy.api#httpBearerAuth`.
# @option options [Boolean] :convert_params (true)
# When `true`, request parameters are coerced into the required types.
# @option options [Boolean] :disable_host_prefix_injection
# When `true`, the SDK will not prepend the modeled host prefix to the endpoint.
# @option options [Boolean] :disable_request_compression
# When `true`, the request body will not be compressed for supported operations.
# @option options [String] :endpoint
# The endpoint to send requests to.
# The endpoint should be a URI formatted like "http://example.com:123"'
# @option options [#resolve(parameters)] :endpoint_provider (Weather::EndpointProvider)
# An object that provides an endpoint to use for the request.
# @option options [String] :http_ca_file
# The path to a CA certification file in PEM format. Defaults to `nil` which uses
# the Net::HTTP default value.
# See {https://docs.ruby-lang.org/en/master/Net/HTTP.html#attribute-i-ca_file Net::HTTP#ca_file}.
# @option options [String] :http_ca_path
# The path of to CA directory containing certification files in PEM format. Defaults to
# `nil` which uses the Net::HTTP default value.
# See {https://docs.ruby-lang.org/en/master/Net/HTTP.html#attribute-i-ca_path Net::HTTP#ca_path}.
# @option options [OpenSSL::X509::Certificate] :http_cert
# Sets the OpenSSL::X509::Certificate object to be used for client certification. Defaults
# to `nil` which uses the Net::HTTP default value.
# See {https://docs.ruby-lang.org/en/master/Net/HTTP.html#attribute-i-cert Net::HTTP#cert}.
# @option options [OpenSSL::X509::Store] :http_cert_store
# Sets the OpenSSL::X509::Store to be used for verifying peer certificate. Defaults to
# `nil` which uses the Net::HTTP default value.
# See {https://docs.ruby-lang.org/en/master/Net/HTTP.html#attribute-i-cert_store Net::HTTP#cert_store}.
# @option options [Numeric] :http_continue_timeout
# Sets the continue timeout value, which is the number of seconds to wait for an
# expected 100 Continue response. If the HTTP object does not receive a response
# in this many seconds it sends the request body. Defaults to `nil` which uses the
# Net::HTTP default value.
# See {https://docs.ruby-lang.org/en/master/Net/HTTP.html#attribute-i-continue_timeout Net::HTTP#continue_timeout}.
# @option options [Boolean] :http_debug_output
# When `true`, Net::HTTP debug output will be sent to the configured logger.
# See {https://docs.ruby-lang.org/en/master/Net/HTTP.html#method-i-set_debug_output Net::HTTP#set_debug_output}.
# @option options [Numeric] :http_keep_alive_timeout
# The number of seconds to keep the connection open after a request is sent. If a
# new request is made during the given interval, the still-open connection is used;
# otherwise the connection will have been closed and a new connection is opened.
# Defaults to `nil` which uses the Net::HTTP default value.
# See {https://docs.ruby-lang.org/en/master/Net/HTTP.html#attribute-i-keep_alive_timeout Net::HTTP#keep_alive_timeout}.
# @option options [OpenSSL::PKey::RSA, OpenSSL::PKey::DSA] :http_key
# Sets the OpenSSL::PKey object to be used for client private key. Defaults to `nil` which
# uses the Net::HTTP default value.
# See {https://docs.ruby-lang.org/en/master/Net/HTTP.html#attribute-i-key Net::HTTP#key}.
# @option options [Numeric] :http_open_timeout
# The number of seconds to wait for a connection to open. If the connection is not
# made in the given interval, an exception is raised. Defaults to `nil` which uses
# the Net::HTTP default value.
# See {https://docs.ruby-lang.org/en/master/Net/HTTP.html#attribute-i-open_timeout Net::HTTP#open_timeout}.
# @option options [URI::HTTP, String] :http_proxy
# A proxy to send requests through. Formatted like 'http://proxy.com:123'.
# @option options [Numeric] :http_read_timeout
# The number of seconds to wait for one block to be read (via one read(2) call).
# Defaults to `nil` which uses the Net::HTTP default value.
# See {https://docs.ruby-lang.org/en/master/Net/HTTP.html#attribute-i-read_timeout Net::HTTP#read_timeout}.
# @option options [Numeric] :http_ssl_timeout
# Sets the SSL timeout seconds. Defaults to `nil` which uses the Net::HTTP default value.
# See {https://docs.ruby-lang.org/en/master/Net/HTTP.html#attribute-i-ssl_timeout Net::HTTP#ssl_timeout}.
# @option options [Integer] :http_verify_mode (OpenSSL::SSL::VERIFY_PEER)
# Sets the verify mode for SSL. Defaults to `OpenSSL::SSL::VERIFY_PEER`.
# See {https://docs.ruby-lang.org/en/master/Net/HTTP.html#attribute-i-verify_mode Net::HTTP#verify_mode}.
# @option options [Numeric] :http_write_timeout
# The number of seconds to wait for one block to be written (via one write(2) call).
# Defaults to `nil` which uses the Net::HTTP default value.
# See {https://docs.ruby-lang.org/en/master/Net/HTTP.html#attribute-i-write_timeout Net::HTTP#write_timeout}.
# @option options [Smithy::Client::LogFormatter] :log_formatter (Aws::Log::Formatter.default)
# The log formatter used by the logger.
# @option options [Symbol] :log_level (:info)
# The log level to send messages to the logger at.
# @option options [Logger] :logger
# The Logger instance to send log messages to. If this option is not set, logging is disabled.
# @option options [Boolean] :raise_response_errors (true)
# When `true`, response errors are raised. When `false`, the error is placed on the
# output in the {Smithy::Client::Response#error error accessor}.
# @option options [Integer] :request_min_compression_size_bytes (10240)
# The minimum size in bytes that triggers compression for request bodies.
# The value must be non-negative integer value between 0 and 10,485,780 bytes inclusive.
# @option options [lambda] :retry_backoff (Smithy::Client::Retry::EXPONENTIAL_BACKOFF)
# A callable object that calculates a backoff delay for a retry attempt. The callable
# should accept a single argument, `attempts`, that represents the number of attempts
# that have been made. Used in the `standard` and `adaptive` retry strategies.
# @option options [Integer] :retry_max_attempts (3)
# The maximum number attempts that will be made for a single request, including
# the initial attempt. Used in the `standard` and `adaptive` retry strategies.
# @option options [String, Class] :retry_strategy ('standard')
# The retry strategy to use when retrying errors. This can be one of the following:
# * `standard` - A standardized retry strategy used by the AWS SDKs. This includes support
# for retry quotas, which limit the number of unsuccessful retries a client can make.
# * `adaptive` - An experimental retry strategy that includes all the functionality of the
# `standard` strategy along with automatic client side throttling. This is a provisional
# strategy that may change behavior in the future.
# * Any instance of a class that implements the following methods:
# - `acquire_initial_retry_token(token_scope)`
# - `refresh_retry_token(retry_token, error_info)`
# - `record_success(retry_token)`
# @option options [Boolean] :stub_responses
# When `true`, the client will return stubbed responses instead of networking requests.
# By default fake responses are generated and returned. You can specify the response data
# to return or errors to raise by calling {Smithy::Client::Stubs#stub_responses}.
# @option options [String] :user_agent_suffix
# An optional string that is appended to the User-Agent header.
# The default User-Agent includes the smithy-client version,
# the ruby platform and version, and host OS information.
# @option options [Boolean] :validate_params (true)
# When `true`, request parameters are validated before sending the request.
def initialize(*options)
super
end
# @param [Hash, Types::GetCityInput] params
# @option params [String] :city_id
# @example Request syntax with placeholder values
# params = {
# city_id: "CityId", # required
# }
# options = {}
# response = client.get_city(params, options)
# @example Response structure with placeholder values
# response.to_h #=>
# {
# name: "String", # required
# coordinates: { # required
# latitude: 1.0, # required
# longitude: 1.0, # required
# }
# }
# @return [Types::GetCityOutput]
def get_city(params = {}, options = {})
request = build_request(:get_city, params)
request.send_request(options)
end
# @param [Hash, Smithy::Schema::EmptyStructure] params
# @example Request syntax with placeholder values
# params = {}
# options = {}
# response = client.get_current_time(params, options)
# @example Response structure with placeholder values
# response.to_h #=>
# {
# time: Time.now, # required
# }
# @return [Types::GetCurrentTimeOutput]
def get_current_time(params = {}, options = {})
request = build_request(:get_current_time, params)
request.send_request(options)
end
# @param [Hash, Types::GetForecastInput] params
# @option params [String] :city_id
# @example Request syntax with placeholder values
# params = {
# city_id: "CityId", # required
# }
# options = {}
# response = client.get_forecast(params, options)
# @example Response structure with placeholder values
# response.to_h #=>
# {
# chance_of_rain: 1.0
# }
# @return [Types::GetForecastOutput]
def get_forecast(params = {}, options = {})
request = build_request(:get_forecast, params)
request.send_request(options)
end
# @param [Hash, Types::ListCitiesInput] params
# @option params [String] :next_token
# @option params [Integer] :page_size
# @example Request syntax with placeholder values
# params = {
# next_token: "String",
# page_size: 1
# }
# options = {}
# response = client.list_cities(params, options)
# @example Response structure with placeholder values
# response.to_h #=>
# {
# next_token: "String",
# items: [ # required
# {
# city_id: "CityId", # required
# name: "String", # required
# }
# ]
# }
# @return [Types::ListCitiesOutput]
def list_cities(params = {}, options = {})
request = build_request(:list_cities, params)
request.send_request(options)
end
# Polls an API operation until a resource enters a desired state.
#
# ## Basic Usage
#
# A waiter will call an API operation until:
#
# * It is successful
# * It enters a terminal state
# * It reaches the maximum wait time allowed
#
# In between attempts, the waiter will sleep.
#
# # polls in a loop, sleeping between attempts
# client.wait_until(waiter_name, params, options)
#
# ## Configuration
#
# You must configure the maximum amount of time in seconds a
# waiter should wait for. You may also configure the minimum
# and maximum amount of time in seconds to delay between
# retries. You can pass these configuration as the final
# arguments hash.
#
# weather = Weather::Client.new
#
# # poll for a maximum of 25 seconds
# weather.wait_until(:forecast_exists, { forecast_id: '1' }, {
# max_wait_time: 25,
# min_delay: 2,
# max_delay: 10
# })
#
# ## Handling Errors
#
# When a waiter is unsuccessful, it will raise an error.
# All the failure errors extend from
# {Smithy::Client::Waiters::WaiterFailed}.
#
# weather = Weather::Client.new
# begin
# weather.wait_until(:forecast_exists, { forecast_id: '1' }, max_wait_time: 60)
# rescue Smithy::Client::Waiters::WaiterFailed
# # resource did not enter the desired state in time
# end
#
# @param [Symbol] waiter_name
# @param [Hash] params ({})
# @param [Hash] options ({})
# @option options [Integer] :max_wait_time
# @option options [Integer] :min_delay
# @option options [Integer] :max_delay
# @return [nil] Returns `nil` if the waiter was successful.
# @raise [FailureStateError] Raised when the waiter terminates
# because the waiter has entered a state that it will not transition
# out of, preventing success.
# @raise [MaxWaitTimeExceededError] Raised when the configured
# maximum wait time is reached and the waiter is not yet successful.
# @raise [UnexpectedError] Raised when an error that is not
# expected is encountered while polling for a resource.
# @raise [NoSuchWaiterError] Raised when you request to wait
# for an unknown state.
def wait_until(waiter_name, params = {}, options = {})
waiter(waiter_name, options).wait(params)
end
# @api private
def build_request(operation_name, params)
handlers = @handlers.for(operation_name)
context = Smithy::Client::HandlerContext.new(
operation_name: operation_name,
operation: config.service.operation(operation_name),
client: self,
config: config,
params: params
)
context[:gem_name] = 'weather'
context[:gem_version] = '1.0.0'
Smithy::Client::Request.new(handlers: handlers, context: context)
end
private
def waiters
{
forecast_exists: Waiters::ForecastExists
}
end
class << self
# @api private
attr_reader :identifier
# @api private
def auth_parameters
AuthParameters
end
# @api private
def auth_resolver
AuthResolver
end
# @api private
def errors_module
Errors
end
end
end
end