Module: Smplkit::Platform

Defined in:
lib/smplkit/platform/types.rb,
lib/smplkit/platform/client.rb,
lib/smplkit/platform/models.rb

Defined Under Namespace

Modules: EnvironmentClassification Classes: Color, ContextType, ContextTypesClient, ContextsClient, Environment, EnvironmentsClient, PlatformClient, Service, ServicesClient

Constant Summary collapse

HEX_RE =
/\A#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})\z/

Class Method Summary collapse

Class Method Details

.app_transport(api_key:, base_url:, profile:, base_domain:, scheme:, debug:, extra_headers:) ⇒ Object

Build a standalone app transport from resolved config.

base_url/api_key are used directly when supplied (the path the top-level client takes after it has already resolved them); otherwise the management config resolver fills in whatever is missing (+~/.smplkit+ / env vars / defaults).



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/smplkit/platform/client.rb', line 47

def self.app_transport(api_key:, base_url:, profile:, base_domain:, scheme:, debug:, extra_headers:)
  cfg = ConfigResolution.resolve_management_config(
    profile: profile, api_key: api_key, base_domain: base_domain, scheme: scheme, debug: debug
  )
  resolved_key = api_key.nil? ? cfg.api_key : api_key
  merged = {}
  merged.merge!(cfg.extra_headers || {})
  merged.merge!(extra_headers || {})
  tcfg = ConfigResolution::ResolvedManagementConfig.new(
    api_key: resolved_key, base_domain: cfg.base_domain, scheme: cfg.scheme,
    debug: cfg.debug, extra_headers: merged
  )
  Transport.build_api_client(SmplkitGeneratedClient::App, "app", tcfg, base_url: base_url)
end

.coerce_color(value) ⇒ Object

Accept Color, hex string, or nil; reject anything else.

Raises:

  • (TypeError)


6
7
8
9
10
11
# File 'lib/smplkit/platform/models.rb', line 6

def self.coerce_color(value)
  return value if value.nil? || value.is_a?(Color)
  return Color.new(value) if value.is_a?(String)

  raise TypeError, "color must be a Color, hex string, or nil; got #{value.class}: #{value.inspect}"
end

.split_context_id(id_or_type, key) ⇒ Object

Resolve the two-arg or composite-id form to [type, key].



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/smplkit/platform/client.rb', line 29

def self.split_context_id(id_or_type, key)
  return [id_or_type, key] unless key.nil?

  unless id_or_type.include?(":")
    raise ArgumentError,
          "context id must be 'type:key' (got #{id_or_type.inspect}); " \
          "alternatively pass type and key as separate args"
  end

  id_or_type.split(":", 2)
end