Class: AWS::Core::Client
- Inherits:
-
Object
- Object
- AWS::Core::Client
- Defined in:
- lib/aws/core/client.rb
Overview
Base client class for all of the Amazon AWS service clients.
Direct Known Subclasses
JSONClient, QueryClient, RESTJSONClient, RESTXMLClient, S3::Client
Defined Under Namespace
Classes: NetworkError
Instance Attribute Summary collapse
-
#config ⇒ Configuration
readonly
This clients configuration.
-
#http_read_timeout ⇒ Integer
readonly
The number of seconds before requests made by this client should timeout if they have not received a response.
Class Method Summary collapse
-
.operations ⇒ Array<Symbol>
Returns a list of service operations as method names supported by this client.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
Creates a new low-level client.
-
#log_warning(warning) ⇒ nil
Logs the warning to the configured logger, otherwise to stderr.
- #operations ⇒ Object
-
#with_http_handler(handler = nil, &blk) ⇒ Core::Client
Returns a copy of the client with a different HTTP handler.
-
#with_options(options) ⇒ Client
Returns a new client with the passed configuration options merged with the current configuration options.
Constructor Details
#initialize(options = {}) ⇒ Client
Creates a new low-level client.
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 |
# File 'lib/aws/core/client.rb', line 41 def initialize = {} = .dup # so we don't modify the options passed in @service_ruby_name = self.class.service_ruby_name # translate these into service specific configuration options, # e.g. :endpoint into :s3_endpoint [:endpoint, :region, :port].each do |opt| if [opt] [:"#{service_ruby_name}_#{opt}"] = .delete(opt) end end @config = (.delete(:config) || AWS.config) @config = @config.with() @credential_provider = @config.credential_provider @http_handler = @config.http_handler @endpoint = config.send(:"#{service_ruby_name}_endpoint") @port = config.send(:"#{service_ruby_name}_port") if config.send(:"#{service_ruby_name}_service_path") <=> "/" @uri = config.send(:"#{service_ruby_name}_service_path") end @http_read_timeout = @config.http_read_timeout end |
Instance Attribute Details
#config ⇒ Configuration (readonly)
Returns This clients configuration.
70 71 72 |
# File 'lib/aws/core/client.rb', line 70 def config @config end |
#http_read_timeout ⇒ Integer (readonly)
Returns The number of seconds before requests made by this client should timeout if they have not received a response.
88 89 90 |
# File 'lib/aws/core/client.rb', line 88 def http_read_timeout @http_read_timeout end |
Class Method Details
.operations ⇒ Array<Symbol>
Returns a list of service operations as method names supported by this client.
557 558 559 |
# File 'lib/aws/core/client.rb', line 557 def operations @operations ||= [] end |
Instance Method Details
#log_warning(warning) ⇒ nil
Logs the warning to the configured logger, otherwise to stderr.
175 176 177 178 179 180 181 182 183 |
# File 'lib/aws/core/client.rb', line 175 def log_warning warning = '[aws-sdk-gem-warning] ' + warning if config.logger config.logger.warn() else $stderr.puts() end nil end |
#operations ⇒ Object
101 102 103 |
# File 'lib/aws/core/client.rb', line 101 def operations self.class.operations end |
#with_http_handler(handler = nil, &blk) ⇒ Core::Client
Returns a copy of the client with a different HTTP handler. You can pass an object like BuiltinHttpHandler or you can use a block; for example:
s3_with_logging = s3.with_http_handler do |request, response|
$stderr.puts request.inspect
super(request, response)
$stderr.puts response.inspect
end
The block executes in the context of an HttpHandler instance, and super
delegates to the HTTP handler used by this client. This provides an easy way to spy on requests and responses. See HttpHandler, HttpRequest, and HttpResponse for more details on how to implement a fully functional HTTP handler using a different HTTP library than the one that ships with Ruby.
126 127 128 129 |
# File 'lib/aws/core/client.rb', line 126 def with_http_handler(handler = nil, &blk) handler ||= Http::Handler.new(@http_handler, &blk) (:http_handler => handler) end |
#with_options(options) ⇒ Client
Returns a new client with the passed configuration options merged with the current configuration options.
no_retry_client = client.(:max_retries => 0)
139 140 141 |
# File 'lib/aws/core/client.rb', line 139 def with_config(config.with()) end |