Class: AWS::Core::Client
- Inherits:
-
Object
- Object
- AWS::Core::Client
- Extended by:
- Naming
- Defined in:
- lib/aws/core/client.rb,
lib/aws/core/client/query_xml.rb,
lib/aws/core/client/query_json.rb
Overview
Base client class for all of the Amazon AWS service clients.
Direct Known Subclasses
AutoScaling::Client, AWS::CloudFormation::Client, DynamoDB::Client, EC2::Client, ELB::Client, IAM::Client, S3::Client, SNS::Client, SQS::Client, STS::Client, SimpleDB::Client, SimpleEmailService::Client, SimpleWorkflow::Client
Defined Under Namespace
Modules: QueryJSON, QueryXML Classes: ClientRequestMethodBuilder
Constant Summary collapse
- CACHEABLE_REQUESTS =
Set[]
Instance Attribute Summary collapse
-
#config ⇒ Configuration
readonly
This clients configuration.
-
#endpoint ⇒ String
readonly
Returns the service endpoint (hostname) this client makes requests against.
-
#port ⇒ Integer
readonly
What port this client makes requests via.
-
#service_ruby_name ⇒ String
readonly
The snake-cased ruby name for the service (e.g. ‘s3’, ‘iam’, ‘dynamo_db’, etc).
-
#signer ⇒ DefaultSigner, Object
readonly
Returns the signer for this client.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
Creates a new low-level client.
-
#new_stub_for(method_name) ⇒ Object
Primarily used for testing, this method returns an empty psuedo service response without making a request.
- #operations ⇒ Object
-
#stub_for(method_name) ⇒ Object
The stub returned is memoized.
-
#with_config(config) ⇒ Core::Client
Returns a new client object with the given configuration.
-
#with_http_handler(handler = nil, &blk) ⇒ Core::Client
Returns a copy of the client with a different HTTP handler.
- #with_options(options) ⇒ Object
Methods included from Naming
Constructor Details
#initialize(options = {}) ⇒ Client
Creates a new low-level client.
Required Options
To create a client you must provide access to AWS credentials. There are two options:
-
:signer
– An object that responds toaccess_key_id
(to return the AWS Access Key ID) and tosign(string_to_sign)
(to return a signature for a given string). An example implementation is AWS::Core::DefaultSigner. This option is useful if you want to more tightly control access to your secret access key (for example by moving the signature computation into a different process). -
:access_key_id
and:secret_access_key
– You can use these options to provide the AWS Access Key ID and AWS Secret Access Key directly to the client.
Optional
-
:http_handler
– Any object that implements ahandle(request, response)
method; an example is BuiltinHttpHandler. This method is used to perform the HTTP requests that this client constructs.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/aws/core/client.rb', line 57 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) @config ||= AWS.config @config = @config.with() @signer = @config.signer @http_handler = @config.http_handler @endpoint = config.send(:"#{service_ruby_name}_endpoint") @port = config.send(:"#{service_ruby_name}_port") end |
Instance Attribute Details
#config ⇒ Configuration (readonly)
Returns This clients configuration.
83 84 85 |
# File 'lib/aws/core/client.rb', line 83 def config @config end |
#endpoint ⇒ String (readonly)
Returns the service endpoint (hostname) this client makes requests against.
103 104 105 |
# File 'lib/aws/core/client.rb', line 103 def endpoint @endpoint end |
#port ⇒ Integer (readonly)
Returns What port this client makes requests via.
98 99 100 |
# File 'lib/aws/core/client.rb', line 98 def port @port end |
#service_ruby_name ⇒ String (readonly)
Returns The snake-cased ruby name for the service (e.g. ‘s3’, ‘iam’, ‘dynamo_db’, etc).
94 95 96 |
# File 'lib/aws/core/client.rb', line 94 def service_ruby_name @service_ruby_name end |
#signer ⇒ DefaultSigner, Object (readonly)
Returns the signer for this client. This is normally a DefaultSigner, but it can be configured to an other object.
89 90 91 |
# File 'lib/aws/core/client.rb', line 89 def signer @signer end |
Instance Method Details
#new_stub_for(method_name) ⇒ Object
Primarily used for testing, this method returns an empty psuedo service response without making a request. Its used primarily for testing the ligher level service interfaces.
160 161 162 163 164 165 166 167 |
# File 'lib/aws/core/client.rb', line 160 def new_stub_for method_name response = Response.new(Http::Request.new, Http::Response.new) response.request_type = method_name response. = {} send("simulate_#{method_name}_response", response) response.signal_success response end |
#operations ⇒ Object
106 107 108 |
# File 'lib/aws/core/client.rb', line 106 def operations self.class.operations end |
#stub_for(method_name) ⇒ Object
The stub returned is memoized.
151 152 153 154 |
# File 'lib/aws/core/client.rb', line 151 def stub_for method_name @stubs ||= {} @stubs[method_name] ||= new_stub_for(method_name) end |
#with_config(config) ⇒ Core::Client
Returns a new client object with the given configuration.
144 145 146 |
# File 'lib/aws/core/client.rb', line 144 def with_config config self.class.new(:config => config) 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
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.
130 131 132 133 |
# File 'lib/aws/core/client.rb', line 130 def with_http_handler(handler = nil, &blk) handler ||= Http::Handler.new(@http_handler, &blk) (:http_handler => handler) end |
#with_options(options) ⇒ Object
137 138 139 |
# File 'lib/aws/core/client.rb', line 137 def with_config(config.with()) end |