Class: Seekmodo::Sdk::Tools::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/seekmodo/sdk/tools/registry.rb

Constant Summary collapse

ADMIN_PREFIXES =
%w[
  synonyms. pins. ltr. analytics. tenant. merchandising. experiments.
  catalog. queries. segments. banners. deboosts. esp. regions.
  recommendations. bundles. image_search. bot_check. schema.
].freeze
ADMIN_TOOLS =
%w[
  synonyms.list synonyms.add synonyms.remove
  pins.list pins.set pins.remove
  ltr.status ltr.retrain ltr.toggle ltr.config.set
  analytics.top_queries analytics.zero_results
  tenant.snapshot tenant.config tenant.config.set
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(connector: nil, admin: nil, tenant_id: nil) ⇒ Registry

Returns a new instance of Registry.



21
22
23
24
25
# File 'lib/seekmodo/sdk/tools/registry.rb', line 21

def initialize(connector: nil, admin: nil, tenant_id: nil)
  @connector = connector
  @admin = admin
  @tenant_id = tenant_id
end

Instance Method Details

#call(tool, args = {}, tenant_id: @tenant_id) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/seekmodo/sdk/tools/registry.rb', line 27

def call(tool, args = {}, tenant_id: @tenant_id)
  normalized = normalize_tool(tool)
  if admin_tool?(normalized)
    unless @admin
      raise ArgumentError, "Admin client required for tool #{normalized}"
    end
    unless tenant_id
      raise ArgumentError, "tenant_id required for admin tool #{normalized}"
    end
    return @admin.call(normalized, args, tenant_id: tenant_id)
  end

  unless @connector
    raise ArgumentError, "Connector client required for tool #{normalized}"
  end

  route_connector(normalized, args)
end