Class: Seahorse::Client::Base

Inherits:
Object
  • Object
show all
Includes:
HandlerBuilder
Defined in:
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, #handler_for, #new_handler

Constructor Details

#initialize(plugins, options) ⇒ Base

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Base.



20
21
22
23
24
# File 'lib/seahorse/client/base.rb', line 20

def initialize(plugins, options)
  @config = build_config(plugins, options)
  @handlers = build_handler_list(plugins)
  after_initialize(plugins)
end

Instance Attribute Details

#configConfiguration<Struct> (readonly)

Returns:



27
28
29
# File 'lib/seahorse/client/base.rb', line 27

def config
  @config
end

#handlersHandlerList (readonly)

Returns:



30
31
32
# File 'lib/seahorse/client/base.rb', line 30

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:



132
133
134
# File 'lib/seahorse/client/base.rb', line 132

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

.apiModel::Api

Returns:



176
177
178
# File 'lib/seahorse/client/base.rb', line 176

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

.clear_pluginsvoid

This method returns an undefined value.



150
151
152
# File 'lib/seahorse/client/base.rb', line 150

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:



199
200
201
202
203
204
205
206
# File 'lib/seahorse/client/base.rb', line 199

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



102
103
104
105
106
107
108
109
# File 'lib/seahorse/client/base.rb', line 102

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.



171
172
173
# File 'lib/seahorse/client/base.rb', line 171

def plugins
  Array(@plugins).freeze
end

.remove_plugin(plugin) ⇒ void

This method returns an undefined value.



141
142
143
# File 'lib/seahorse/client/base.rb', line 141

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

.set_api(api) ⇒ Model::Api

Parameters:

Returns:



182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/seahorse/client/base.rb', line 182

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:



160
161
162
# File 'lib/seahorse/client/base.rb', line 160

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:



36
37
38
39
40
# File 'lib/seahorse/client/base.rb', line 36

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

#inspectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



49
50
51
# File 'lib/seahorse/client/base.rb', line 49

def inspect
  "#<#{self.class.name}>"
end

#operation(name) ⇒ Model::Operation

Parameters:

  • name (String)

Returns:



44
45
46
# File 'lib/seahorse/client/base.rb', line 44

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.



56
57
58
# File 'lib/seahorse/client/base.rb', line 56

def operation_names
  self.class.api.operation_names
end