Class: AWS::Core::Client

Inherits:
Object
  • Object
show all
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.

Defined Under Namespace

Modules: QueryJSON, QueryXML

Instance Attribute Summary collapse

Instance Method Summary collapse

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 to access_key_id (to return the AWS Access Key ID) and to sign(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 a handle(request, response) method; an example is BuiltinHttpHandler. This method is used to perform the HTTP requests that this client constructs.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/aws/core/client.rb', line 56

def initialize options = {}

  options = options.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 options[opt]
      options[:"#{service_ruby_name}_#{opt}"] = options.delete(opt)
    end
  end
  
  @config = options.delete(:config)
  @config ||= AWS.config
  @config = @config.with(options)

  @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

#configConfiguration (readonly)

Returns This clients configuration.

Returns:



82
83
84
# File 'lib/aws/core/client.rb', line 82

def config
  @config
end

Instance Method Details

#operationsObject



105
106
107
# File 'lib/aws/core/client.rb', line 105

def operations
  self.class.operations
end

#with_config(config) ⇒ Core::Client

Returns a new client object with the given configuration.

Parameters:

Returns:

  • (Core::Client)

    Returns a new client object with the given configuration.



143
144
145
# File 'lib/aws/core/client.rb', line 143

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.

Parameters:

  • handler (nil) (defaults to: nil)

    A new http handler. Leave blank and pass a block to wrap the current handler with the block.

Returns:

  • (Core::Client)

    Returns a new instance of the client class with the modified or wrapped http handler.



129
130
131
132
# File 'lib/aws/core/client.rb', line 129

def with_http_handler(handler = nil, &blk)
  handler ||= Http::Handler.new(@http_handler, &blk)
  with_options(:http_handler => handler)
end

#with_options(options) ⇒ Object

Parameters:

  • options (Hash)

See Also:



136
137
138
# File 'lib/aws/core/client.rb', line 136

def with_options options
  with_config(config.with(options))
end