Class: Seahorse::Client::Base

Inherits:
Object
  • Object
show all
Includes:
HandlerBuilder
Defined in:
aws-sdk-core/lib/seahorse/client/base.rb

Direct Known Subclasses

Aws::Client

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HandlerBuilder

#handle, #handle_request, #handle_response

Instance Attribute Details

#configConfiguration<Struct> (readonly)

Returns:


26
27
28
# File 'aws-sdk-core/lib/seahorse/client/base.rb', line 26

def config
  @config
end

#handlersHandlerList (readonly)

Returns:


29
30
31
# File 'aws-sdk-core/lib/seahorse/client/base.rb', line 29

def handlers
  @handlers
end

Class Method Details

.add_plugin(plugin) ⇒ void

This method returns an undefined value.

Registers a plugin with this client.

Examples:

Register a plugin


ClientClass.add_plugin(PluginClass)

Register a plugin by name


ClientClass.add_plugin('gem-name.PluginClass')

Register a plugin with an object


plugin = MyPluginClass.new(options)
ClientClass.add_plugin(plugin)

Parameters:

  • plugin (Class, Symbol, String, Object)

See Also:


131
132
133
# File 'aws-sdk-core/lib/seahorse/client/base.rb', line 131

def add_plugin(plugin)
  @plugins.add(plugin)
end

.apiModel::Api

Returns:


175
176
177
# File 'aws-sdk-core/lib/seahorse/client/base.rb', line 175

def api
  @api ||= Model::Api.new
end

.clear_pluginsvoid

This method returns an undefined value.


149
150
151
# File 'aws-sdk-core/lib/seahorse/client/base.rb', line 149

def clear_plugins
  @plugins.set([])
end

.define(options = {}) ⇒ Class<Client::Base> Also known as: extend

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :api (Model::Api, Hash) — default: {}
  • :plugins (Array<Plugin>) — default: []

    A list of plugins to add to the client class created.

Returns:


198
199
200
201
202
203
204
205
# File 'aws-sdk-core/lib/seahorse/client/base.rb', line 198

def define(options = {})
  subclass = Class.new(self)
  subclass.set_api(options[:api] || api)
  Array(options[:plugins]).each do |plugin|
    subclass.add_plugin(plugin)
  end
  subclass
end

.new(options = {}) ⇒ Object


101
102
103
104
105
106
107
108
# File 'aws-sdk-core/lib/seahorse/client/base.rb', line 101

def new(options = {})
  plugins = build_plugins
  options = options.dup
  before_initialize(plugins, options)
  client = allocate
  client.send(:initialize, plugins, options)
  client
end

.pluginsArray<Plugin>

Returns the list of registered plugins for this Client. Plugins are inherited from the client super class when the client is defined.


170
171
172
# File 'aws-sdk-core/lib/seahorse/client/base.rb', line 170

def plugins
  Array(@plugins).freeze
end

.remove_plugin(plugin) ⇒ void

This method returns an undefined value.


140
141
142
# File 'aws-sdk-core/lib/seahorse/client/base.rb', line 140

def remove_plugin(plugin)
  @plugins.remove(plugin)
end

.set_api(api) ⇒ Model::Api

Parameters:

Returns:


181
182
183
184
185
186
187
188
189
190
191
192
# File 'aws-sdk-core/lib/seahorse/client/base.rb', line 181

def set_api(api)
  @api =
    case api
    when nil then Model::Api.new({})
    when Model::Api then api
    when Hash then Model::Api.new(api)
    when String, Pathname then Model::Api.new(Util.load_json(api))
    else raise ArgumentError, "invalid api definition #{api}"
    end
  define_operation_methods
  @api
end

.set_plugins(plugins) ⇒ void

This method returns an undefined value.

Parameters:

See Also:


159
160
161
# File 'aws-sdk-core/lib/seahorse/client/base.rb', line 159

def set_plugins(plugins)
  @plugins.set(plugins)
end

Instance Method Details

#build_request(operation_name, params = {}) ⇒ Request

Builds and returns a Request for the named operation. The request will not have been sent.

Parameters:

  • operation_name (Symbol, String)

Returns:


35
36
37
38
39
# File 'aws-sdk-core/lib/seahorse/client/base.rb', line 35

def build_request(operation_name, params = {})
  Request.new(
    @handlers.for(operation_name),
    context_for(operation_name, params))
end

#operation(name) ⇒ Model::Operation

Parameters:

  • name (String)

Returns:


43
44
45
# File 'aws-sdk-core/lib/seahorse/client/base.rb', line 43

def operation(name)
  config.api.operation(name)
end

#operation_namesArray<Symbol>

Returns a list of valid request operation names. These are valid arguments to #build_request and are also valid methods.

Returns:

  • (Array<Symbol>)

    Returns a list of valid request operation names. These are valid arguments to #build_request and are also valid methods.


55
56
57
# File 'aws-sdk-core/lib/seahorse/client/base.rb', line 55

def operation_names
  self.class.api.operation_names
end