class Seahorse::Client::Base

def add_plugin(plugin)

Returns:
  • (void) -

Other tags:
    See: .plugins -
    See: .remove_plugin -
    See: .set_plugins -
    See: .clear_plugins -

Parameters:
  • plugin (Class, Symbol, String, Object) --

Other tags:
    Example: Register a plugin with an object -
    Example: Register a plugin by name -
    Example: Register a plugin -
def add_plugin(plugin)
  @plugins.add(plugin)
end

def after_initialize(plugins)

Gives each plugin the opportunity to modify this client.
def after_initialize(plugins)
  plugins.reverse.each do |plugin|
    plugin.after_initialize(self) if plugin.respond_to?(:after_initialize)
  end
end

def api

Returns:
  • (Model::Api) -
def api
  @api ||= Model::Api.new
end

def before_initialize(plugins, options)

def before_initialize(plugins, options)
  plugins.each do |plugin|
    plugin.before_initialize(self, options) if plugin.respond_to?(:before_initialize)
  end
end

def build_config(plugins, options)

opportunity to register options with default values.
Constructs a {Configuration} object and gives each plugin the
def build_config(plugins, options)
  config = Configuration.new
  config.add_option(:api)
  plugins.each do |plugin|
    plugin.add_options(config) if plugin.respond_to?(:add_options)
  end
  config.build!(options.merge(api: self.class.api))
end

def build_handler_list(plugins)

Gives each plugin the opportunity to register handlers for this client.
def build_handler_list(plugins)
  plugins.inject(HandlerList.new) do |handlers, plugin|
    if plugin.respond_to?(:add_handlers)
      plugin.add_handlers(handlers, @config)
    end
    handlers
  end
end

def build_plugins

def build_plugins
  plugins.map { |plugin| plugin.is_a?(Class) ? plugin.new : plugin }
end

def build_request(operation_name, params = {})

Returns:
  • (Request) -

Parameters:
  • operation_name (Symbol, String) --
def build_request(operation_name, params = {})
  Request.new(
    @handlers.for(operation_name),
    context_for(operation_name, params))
end

def clear_plugins

Returns:
  • (void) -

Other tags:
    See: .plugins -
    See: .remove_plugin -
    See: .add_plugin -
    See: .set_plugins -
def clear_plugins
  @plugins.set([])
end

def context_for(operation_name, params)

Returns:
  • (RequestContext) -
def context_for(operation_name, params)
  RequestContext.new(
    operation_name: operation_name,
    operation: config.api.operation(operation_name),
    client: self,
    params: params,
    config: config)
end

def define(options = {})

Returns:
  • (Class) -

Options Hash: (**options)
  • :plugins (Array) -- A list of plugins to
  • :api (Model::Api, Hash) --
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

def define_operation_methods

def define_operation_methods
  operations_module = Module.new
  @api.operation_names.each do |method_name|
    operations_module.send(:define_method, method_name) do |*args, &block|
      params = args[0] || {}
      options = args[1] || {}
      build_request(method_name, params).send_request(options, &block)
    end
  end
  include(operations_module)
end

def inherited(subclass)

def inherited(subclass)
  subclass.instance_variable_set('@plugins', PluginList.new(@plugins))
end

def initialize(plugins, options)

Other tags:
    Api: - private
def initialize(plugins, options)
  @config = build_config(plugins, options)
  @handlers = build_handler_list(plugins)
  after_initialize(plugins)
end

def inspect

Other tags:
    Api: - private
def inspect
  "#<#{self.class.name}>"
end

def new(options = {})

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

def operation_names

Returns:
  • (Array) - Returns a list of valid request operation
def operation_names
  self.class.api.operation_names - self.class.api.async_operation_names
end

def plugins

Returns:
  • (Array) -

Other tags:
    See: .remove_plugin -
    See: .add_plugin -
    See: .set_plugins -
    See: .clear_plugins -
def plugins
  Array(@plugins).freeze
end

def remove_plugin(plugin)

Returns:
  • (void) -

Other tags:
    See: .plugins -
    See: .add_plugin -
    See: .set_plugins -
    See: .clear_plugins -
def remove_plugin(plugin)
  @plugins.remove(plugin)
end

def set_api(api)

Returns:
  • (Model::Api) -

Parameters:
  • api (Model::Api) --
def set_api(api)
  @api = api
  define_operation_methods
  @api
end

def set_plugins(plugins)

Returns:
  • (void) -

Other tags:
    See: .plugins -
    See: .remove_plugin -
    See: .add_plugin -
    See: .clear_plugins -

Parameters:
  • plugins (Array) --
def set_plugins(plugins)
  @plugins.set(plugins)
end