smplkit 3.0.96 → 3.0.97
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/smplkit/account/client.rb +9 -2
- data/lib/smplkit/account/models.rb +18 -0
- data/lib/smplkit/api_support.rb +8 -0
- data/lib/smplkit/audit/buffer.rb +3 -1
- data/lib/smplkit/audit/categories.rb +21 -10
- data/lib/smplkit/audit/client.rb +16 -6
- data/lib/smplkit/audit/event_types.rb +26 -10
- data/lib/smplkit/audit/events.rb +93 -17
- data/lib/smplkit/audit/forwarders.rb +27 -16
- data/lib/smplkit/audit/models.rb +46 -31
- data/lib/smplkit/audit/resource_types.rb +21 -9
- data/lib/smplkit/buffers.rb +15 -0
- data/lib/smplkit/client.rb +38 -6
- data/lib/smplkit/config/client.rb +279 -26
- data/lib/smplkit/config/helpers.rb +44 -6
- data/lib/smplkit/config/models.rb +114 -7
- data/lib/smplkit/config_resolution.rb +6 -4
- data/lib/smplkit/errors.rb +6 -3
- data/lib/smplkit/flags/client.rb +135 -7
- data/lib/smplkit/flags/models.rb +110 -8
- data/lib/smplkit/flags/types.rb +2 -2
- data/lib/smplkit/jobs/client.rb +47 -26
- data/lib/smplkit/jobs/models.rb +47 -18
- data/lib/smplkit/logging/client.rb +125 -16
- data/lib/smplkit/logging/helpers.rb +4 -1
- data/lib/smplkit/logging/levels.rb +3 -1
- data/lib/smplkit/logging/models.rb +71 -5
- data/lib/smplkit/logging/normalize.rb +3 -1
- data/lib/smplkit/logging/resolution.rb +4 -4
- data/lib/smplkit/platform/client.rb +132 -7
- data/lib/smplkit/platform/models.rb +103 -3
- data/lib/smplkit/platform/types.rb +14 -0
- data/lib/smplkit/transport.rb +5 -1
- data/lib/smplkit/ws.rb +1 -1
- metadata +1 -1
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
module Smplkit
|
|
27
27
|
module Platform
|
|
28
28
|
# Resolve the two-arg or composite-id form to +[type, key]+.
|
|
29
|
+
#
|
|
30
|
+
# @api private
|
|
29
31
|
def self.split_context_id(id_or_type, key)
|
|
30
32
|
return [id_or_type, key] unless key.nil?
|
|
31
33
|
|
|
@@ -42,17 +44,19 @@ module Smplkit
|
|
|
42
44
|
#
|
|
43
45
|
# +base_url+/+api_key+ are used directly when supplied (the path the
|
|
44
46
|
# top-level client takes after it has already resolved them); otherwise the
|
|
45
|
-
#
|
|
46
|
-
#
|
|
47
|
+
# config resolver fills in whatever is missing (+~/.smplkit+ / env vars /
|
|
48
|
+
# defaults).
|
|
49
|
+
#
|
|
50
|
+
# @api private
|
|
47
51
|
def self.app_transport(api_key:, base_url:, profile:, base_domain:, scheme:, debug:, extra_headers:)
|
|
48
|
-
cfg = ConfigResolution.
|
|
52
|
+
cfg = ConfigResolution.resolve_client_config(
|
|
49
53
|
profile: profile, api_key: api_key, base_domain: base_domain, scheme: scheme, debug: debug
|
|
50
54
|
)
|
|
51
55
|
resolved_key = api_key.nil? ? cfg.api_key : api_key
|
|
52
56
|
merged = {}
|
|
53
57
|
merged.merge!(cfg.extra_headers || {})
|
|
54
58
|
merged.merge!(extra_headers || {})
|
|
55
|
-
tcfg = ConfigResolution::
|
|
59
|
+
tcfg = ConfigResolution::ResolvedClientConfig.new(
|
|
56
60
|
api_key: resolved_key, base_domain: cfg.base_domain, scheme: cfg.scheme,
|
|
57
61
|
debug: cfg.debug, extra_headers: merged
|
|
58
62
|
)
|
|
@@ -69,11 +73,28 @@ module Smplkit
|
|
|
69
73
|
@api = SmplkitGeneratedClient::App::EnvironmentsApi.new(app_http)
|
|
70
74
|
end
|
|
71
75
|
|
|
72
|
-
#
|
|
76
|
+
# Build an unsaved +Environment+; call +.save+ to persist it.
|
|
77
|
+
#
|
|
78
|
+
# @param id [String] Stable, human-readable identifier for the
|
|
79
|
+
# environment (for example +"production"+).
|
|
80
|
+
# @param name [String] Display name shown in the Console.
|
|
81
|
+
# @param color [Color, String, nil] Accent color for the environment, as
|
|
82
|
+
# a +Color+ or a CSS hex string. Defaults to no color.
|
|
83
|
+
# @param classification [String] Whether the environment participates in
|
|
84
|
+
# the standard environment ordering. Defaults to
|
|
85
|
+
# +EnvironmentClassification::STANDARD+.
|
|
86
|
+
# @return [Environment] An unsaved environment bound to this client.
|
|
73
87
|
def new(id, name:, color: nil, classification: EnvironmentClassification::STANDARD)
|
|
74
88
|
Environment.new(self, id: id, name: name, color: color, classification: classification)
|
|
75
89
|
end
|
|
76
90
|
|
|
91
|
+
# List environments in the account.
|
|
92
|
+
#
|
|
93
|
+
# @param page_number [Integer, nil] 1-based page to fetch. Defaults to
|
|
94
|
+
# the first page.
|
|
95
|
+
# @param page_size [Integer, nil] Maximum number of environments per
|
|
96
|
+
# page. Defaults to the server's page size.
|
|
97
|
+
# @return [Array<Environment>] The environments on the requested page.
|
|
77
98
|
def list(page_number: nil, page_size: nil)
|
|
78
99
|
opts = {}
|
|
79
100
|
opts[:page_number] = page_number unless page_number.nil?
|
|
@@ -82,21 +103,32 @@ module Smplkit
|
|
|
82
103
|
(response.data || []).map { |r| from_resource(ApiSupport::ResourceShim.from_model(r)) }
|
|
83
104
|
end
|
|
84
105
|
|
|
106
|
+
# Fetch a single environment by id.
|
|
107
|
+
#
|
|
108
|
+
# @param id [String] Identifier of the environment to fetch.
|
|
109
|
+
# @return [Environment] The matching environment.
|
|
110
|
+
# @raise [Smplkit::NotFoundError] If no environment with that id exists.
|
|
85
111
|
def get(id)
|
|
86
112
|
response = ApiSupport::ErrorMapping.call { @api.get_environment(id) }
|
|
87
113
|
from_resource(ApiSupport::ResourceShim.from_model(response.data))
|
|
88
114
|
end
|
|
89
115
|
|
|
116
|
+
# Delete an environment by id.
|
|
117
|
+
#
|
|
118
|
+
# @param id [String] Identifier of the environment to delete.
|
|
119
|
+
# @return [void]
|
|
90
120
|
def delete(id)
|
|
91
121
|
ApiSupport::ErrorMapping.call { @api.delete_environment(id) }
|
|
92
122
|
nil
|
|
93
123
|
end
|
|
94
124
|
|
|
125
|
+
# @api private
|
|
95
126
|
def _create(env)
|
|
96
127
|
response = ApiSupport::ErrorMapping.call { @api.create_environment(body_for(env)) }
|
|
97
128
|
from_resource(ApiSupport::ResourceShim.from_model(response.data))
|
|
98
129
|
end
|
|
99
130
|
|
|
131
|
+
# @api private
|
|
100
132
|
def _update(env)
|
|
101
133
|
raise "cannot update an Environment with no id" if env.id.nil?
|
|
102
134
|
|
|
@@ -143,11 +175,22 @@ module Smplkit
|
|
|
143
175
|
@api = SmplkitGeneratedClient::App::ServicesApi.new(app_http)
|
|
144
176
|
end
|
|
145
177
|
|
|
146
|
-
#
|
|
178
|
+
# Build an unsaved +Service+; call +.save+ to persist it.
|
|
179
|
+
#
|
|
180
|
+
# @param id [String] Stable, human-readable identifier for the service.
|
|
181
|
+
# @param name [String] Display name shown in the Console.
|
|
182
|
+
# @return [Service] An unsaved service bound to this client.
|
|
147
183
|
def new(id, name:)
|
|
148
184
|
Service.new(self, id: id, name: name)
|
|
149
185
|
end
|
|
150
186
|
|
|
187
|
+
# List services in the account.
|
|
188
|
+
#
|
|
189
|
+
# @param page_number [Integer, nil] 1-based page to fetch. Defaults to
|
|
190
|
+
# the first page.
|
|
191
|
+
# @param page_size [Integer, nil] Maximum number of services per page.
|
|
192
|
+
# Defaults to the server's page size.
|
|
193
|
+
# @return [Array<Service>] The services on the requested page.
|
|
151
194
|
def list(page_number: nil, page_size: nil)
|
|
152
195
|
opts = {}
|
|
153
196
|
opts[:page_number] = page_number unless page_number.nil?
|
|
@@ -156,21 +199,32 @@ module Smplkit
|
|
|
156
199
|
(response.data || []).map { |r| from_resource(ApiSupport::ResourceShim.from_model(r)) }
|
|
157
200
|
end
|
|
158
201
|
|
|
202
|
+
# Fetch a single service by id.
|
|
203
|
+
#
|
|
204
|
+
# @param id [String] Identifier of the service to fetch.
|
|
205
|
+
# @return [Service] The matching service.
|
|
206
|
+
# @raise [Smplkit::NotFoundError] If no service with that id exists.
|
|
159
207
|
def get(id)
|
|
160
208
|
response = ApiSupport::ErrorMapping.call { @api.get_service(id) }
|
|
161
209
|
from_resource(ApiSupport::ResourceShim.from_model(response.data))
|
|
162
210
|
end
|
|
163
211
|
|
|
212
|
+
# Delete a service by id.
|
|
213
|
+
#
|
|
214
|
+
# @param id [String] Identifier of the service to delete.
|
|
215
|
+
# @return [void]
|
|
164
216
|
def delete(id)
|
|
165
217
|
ApiSupport::ErrorMapping.call { @api.delete_service(id) }
|
|
166
218
|
nil
|
|
167
219
|
end
|
|
168
220
|
|
|
221
|
+
# @api private
|
|
169
222
|
def _create(svc)
|
|
170
223
|
response = ApiSupport::ErrorMapping.call { @api.create_service(create_body_for(svc)) }
|
|
171
224
|
from_resource(ApiSupport::ResourceShim.from_model(response.data))
|
|
172
225
|
end
|
|
173
226
|
|
|
227
|
+
# @api private
|
|
174
228
|
def _update(svc)
|
|
175
229
|
raise "cannot update a Service with no id" if svc.id.nil?
|
|
176
230
|
|
|
@@ -220,10 +274,27 @@ module Smplkit
|
|
|
220
274
|
@api = SmplkitGeneratedClient::App::ContextTypesApi.new(app_http)
|
|
221
275
|
end
|
|
222
276
|
|
|
277
|
+
# Build an unsaved +ContextType+; call +.save+ to persist it.
|
|
278
|
+
#
|
|
279
|
+
# @param id [String] Stable, human-readable identifier for the context
|
|
280
|
+
# type (for example +"user"+).
|
|
281
|
+
# @param name [String, nil] Display name shown in the Console. Defaults
|
|
282
|
+
# to +id+ when omitted.
|
|
283
|
+
# @param attributes [Hash, nil] Known-attribute slots, keyed by attribute
|
|
284
|
+
# name, with a metadata dict per slot. Defaults to no declared
|
|
285
|
+
# attributes.
|
|
286
|
+
# @return [ContextType] An unsaved context type bound to this client.
|
|
223
287
|
def new(id, name: nil, attributes: nil)
|
|
224
288
|
ContextType.new(self, id: id, name: name || id, attributes: attributes || {})
|
|
225
289
|
end
|
|
226
290
|
|
|
291
|
+
# List context types in the account.
|
|
292
|
+
#
|
|
293
|
+
# @param page_number [Integer, nil] 1-based page to fetch. Defaults to
|
|
294
|
+
# the first page.
|
|
295
|
+
# @param page_size [Integer, nil] Maximum number of context types per
|
|
296
|
+
# page. Defaults to the server's page size.
|
|
297
|
+
# @return [Array<ContextType>] The context types on the requested page.
|
|
227
298
|
def list(page_number: nil, page_size: nil)
|
|
228
299
|
opts = {}
|
|
229
300
|
opts[:page_number] = page_number unless page_number.nil?
|
|
@@ -232,21 +303,32 @@ module Smplkit
|
|
|
232
303
|
(response.data || []).map { |r| from_resource(ApiSupport::ResourceShim.from_model(r)) }
|
|
233
304
|
end
|
|
234
305
|
|
|
306
|
+
# Fetch a single context type by id.
|
|
307
|
+
#
|
|
308
|
+
# @param id [String] Identifier of the context type to fetch.
|
|
309
|
+
# @return [ContextType] The matching context type.
|
|
310
|
+
# @raise [Smplkit::NotFoundError] If no context type with that id exists.
|
|
235
311
|
def get(id)
|
|
236
312
|
response = ApiSupport::ErrorMapping.call { @api.get_context_type(id) }
|
|
237
313
|
from_resource(ApiSupport::ResourceShim.from_model(response.data))
|
|
238
314
|
end
|
|
239
315
|
|
|
316
|
+
# Delete a context type by id.
|
|
317
|
+
#
|
|
318
|
+
# @param id [String] Identifier of the context type to delete.
|
|
319
|
+
# @return [void]
|
|
240
320
|
def delete(id)
|
|
241
321
|
ApiSupport::ErrorMapping.call { @api.delete_context_type(id) }
|
|
242
322
|
nil
|
|
243
323
|
end
|
|
244
324
|
|
|
325
|
+
# @api private
|
|
245
326
|
def _create(ct)
|
|
246
327
|
response = ApiSupport::ErrorMapping.call { @api.create_context_type(body_for(ct)) }
|
|
247
328
|
from_resource(ApiSupport::ResourceShim.from_model(response.data))
|
|
248
329
|
end
|
|
249
330
|
|
|
331
|
+
# @api private
|
|
250
332
|
def _update(ct)
|
|
251
333
|
raise "cannot update a ContextType with no id" if ct.id.nil?
|
|
252
334
|
|
|
@@ -289,7 +371,18 @@ module Smplkit
|
|
|
289
371
|
@buffer = buffer
|
|
290
372
|
end
|
|
291
373
|
|
|
292
|
-
# Buffer contexts for registration
|
|
374
|
+
# Buffer one or more contexts for registration.
|
|
375
|
+
#
|
|
376
|
+
# Buffered contexts are sent in batches: a background flush kicks in once
|
|
377
|
+
# enough have accumulated, and any remainder is sent on the next explicit
|
|
378
|
+
# flush. Pass +flush: true+ to send everything buffered right away.
|
|
379
|
+
#
|
|
380
|
+
# @param items [Context, Array<Context>] A single context or a list of
|
|
381
|
+
# contexts to register.
|
|
382
|
+
# @param flush [Boolean] When +true+, send all buffered contexts
|
|
383
|
+
# immediately rather than waiting for the batch threshold. Defaults to
|
|
384
|
+
# +false+.
|
|
385
|
+
# @return [void]
|
|
293
386
|
def register(items, flush: false)
|
|
294
387
|
batch = items.is_a?(Array) ? items : [items]
|
|
295
388
|
@buffer.observe(batch)
|
|
@@ -303,6 +396,8 @@ module Smplkit
|
|
|
303
396
|
end
|
|
304
397
|
|
|
305
398
|
# Send any pending observations to the server.
|
|
399
|
+
#
|
|
400
|
+
# @return [void]
|
|
306
401
|
def flush
|
|
307
402
|
batch = @buffer.drain
|
|
308
403
|
return if batch.empty?
|
|
@@ -312,11 +407,21 @@ module Smplkit
|
|
|
312
407
|
end
|
|
313
408
|
|
|
314
409
|
# Number of observations queued and awaiting flush.
|
|
410
|
+
#
|
|
411
|
+
# @return [Integer] The count of observations pending flush.
|
|
315
412
|
def pending_count
|
|
316
413
|
@buffer.pending_count
|
|
317
414
|
end
|
|
318
415
|
|
|
319
416
|
# List all contexts of a given type.
|
|
417
|
+
#
|
|
418
|
+
# @param type [String] Context type to list (for example +"user"+).
|
|
419
|
+
# @param page_number [Integer, nil] 1-based page to fetch. Defaults to
|
|
420
|
+
# the first page.
|
|
421
|
+
# @param page_size [Integer, nil] Maximum number of contexts per page.
|
|
422
|
+
# Defaults to the server's page size.
|
|
423
|
+
# @return [Array<Context>] The contexts of the given type on the
|
|
424
|
+
# requested page.
|
|
320
425
|
def list(type, page_number: nil, page_size: nil)
|
|
321
426
|
opts = { filter_context_type: type }
|
|
322
427
|
opts[:page_number] = page_number unless page_number.nil?
|
|
@@ -325,18 +430,38 @@ module Smplkit
|
|
|
325
430
|
(response.data || []).map { |r| context_from_resource(ApiSupport::ResourceShim.from_model(r)) }
|
|
326
431
|
end
|
|
327
432
|
|
|
433
|
+
# Fetch a single context, identified by composite id or by type and key.
|
|
434
|
+
#
|
|
435
|
+
# @param id_or_type [String] Either the composite context id +"type:key"+
|
|
436
|
+
# (when +key+ is omitted) or just the context type (when +key+ is
|
|
437
|
+
# supplied).
|
|
438
|
+
# @param key [String, nil] The context key. Provide it to use the
|
|
439
|
+
# two-argument form; omit it when +id_or_type+ already carries the
|
|
440
|
+
# composite id.
|
|
441
|
+
# @return [Context] The matching context.
|
|
442
|
+
# @raise [Smplkit::NotFoundError] If no context with that id exists.
|
|
328
443
|
def get(id_or_type, key = nil)
|
|
329
444
|
ctx_type, ctx_key = Platform.split_context_id(id_or_type, key)
|
|
330
445
|
response = ApiSupport::ErrorMapping.call { @api.get_context("#{ctx_type}:#{ctx_key}") }
|
|
331
446
|
context_from_resource(ApiSupport::ResourceShim.from_model(response.data))
|
|
332
447
|
end
|
|
333
448
|
|
|
449
|
+
# Delete a single context, identified by composite id or by type and key.
|
|
450
|
+
#
|
|
451
|
+
# @param id_or_type [String] Either the composite context id +"type:key"+
|
|
452
|
+
# (when +key+ is omitted) or just the context type (when +key+ is
|
|
453
|
+
# supplied).
|
|
454
|
+
# @param key [String, nil] The context key. Provide it to use the
|
|
455
|
+
# two-argument form; omit it when +id_or_type+ already carries the
|
|
456
|
+
# composite id.
|
|
457
|
+
# @return [void]
|
|
334
458
|
def delete(id_or_type, key = nil)
|
|
335
459
|
ctx_type, ctx_key = Platform.split_context_id(id_or_type, key)
|
|
336
460
|
ApiSupport::ErrorMapping.call { @api.delete_context("#{ctx_type}:#{ctx_key}") }
|
|
337
461
|
nil
|
|
338
462
|
end
|
|
339
463
|
|
|
464
|
+
# @api private
|
|
340
465
|
def _save_context(ctx)
|
|
341
466
|
body = ctx_to_resource(ctx)
|
|
342
467
|
response = ApiSupport::ErrorMapping.call { @api.update_context(ctx.id, body) }
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
module Smplkit
|
|
4
4
|
module Platform
|
|
5
5
|
# Accept Color, hex string, or nil; reject anything else.
|
|
6
|
+
#
|
|
7
|
+
# @api private
|
|
6
8
|
def self.coerce_color(value)
|
|
7
9
|
return value if value.nil? || value.is_a?(Color)
|
|
8
10
|
return Color.new(value) if value.is_a?(String)
|
|
@@ -15,6 +17,27 @@ module Smplkit
|
|
|
15
17
|
attr_accessor :id, :name, :classification, :created_at, :updated_at
|
|
16
18
|
attr_reader :color
|
|
17
19
|
|
|
20
|
+
# Create an environment instance.
|
|
21
|
+
#
|
|
22
|
+
# Prefer +client.platform.environments.new(...)+ to build an unsaved
|
|
23
|
+
# environment; this constructor is also used internally to wrap server
|
|
24
|
+
# responses.
|
|
25
|
+
#
|
|
26
|
+
# @param client [EnvironmentsClient, nil] Client used to persist and
|
|
27
|
+
# delete this environment. +nil+ produces a detached instance that
|
|
28
|
+
# cannot +save+.
|
|
29
|
+
# @param name [String] Display name shown in the Console.
|
|
30
|
+
# @param id [String, nil] Stable, human-readable identifier for the
|
|
31
|
+
# environment.
|
|
32
|
+
# @param color [Color, String, nil] Accent color, as a +Color+ or a CSS
|
|
33
|
+
# hex string. Defaults to no color.
|
|
34
|
+
# @param classification [String] Whether the environment participates in
|
|
35
|
+
# the standard environment ordering. Defaults to
|
|
36
|
+
# +EnvironmentClassification::STANDARD+.
|
|
37
|
+
# @param created_at [String, nil] When the environment was created. Set
|
|
38
|
+
# on instances returned by the server; leave +nil+ for unsaved ones.
|
|
39
|
+
# @param updated_at [String, nil] When the environment was last updated.
|
|
40
|
+
# Set on instances returned by the server; leave +nil+ for unsaved ones.
|
|
18
41
|
def initialize(client = nil, name:, id: nil, color: nil,
|
|
19
42
|
classification: EnvironmentClassification::STANDARD,
|
|
20
43
|
created_at: nil, updated_at: nil)
|
|
@@ -27,11 +50,20 @@ module Smplkit
|
|
|
27
50
|
@updated_at = updated_at
|
|
28
51
|
end
|
|
29
52
|
|
|
53
|
+
# Set the accent color, coercing the value to a +Color+.
|
|
54
|
+
#
|
|
55
|
+
# @param value [Color, String, nil] A +Color+, a CSS hex string, or +nil+
|
|
56
|
+
# to clear the color.
|
|
57
|
+
# @return [void]
|
|
30
58
|
def color=(value)
|
|
31
59
|
@color = Platform.coerce_color(value)
|
|
32
60
|
end
|
|
33
61
|
|
|
34
62
|
# Create or update this environment on the server.
|
|
63
|
+
#
|
|
64
|
+
# @return [Environment] +self+, updated with the server response.
|
|
65
|
+
# @raise [RuntimeError] If this environment was constructed without a
|
|
66
|
+
# client.
|
|
35
67
|
def save
|
|
36
68
|
raise "Environment was constructed without a client; cannot save" if @client.nil?
|
|
37
69
|
|
|
@@ -42,6 +74,10 @@ module Smplkit
|
|
|
42
74
|
alias save! save
|
|
43
75
|
|
|
44
76
|
# Delete this environment from the server.
|
|
77
|
+
#
|
|
78
|
+
# @return [void]
|
|
79
|
+
# @raise [RuntimeError] If this environment was constructed without a
|
|
80
|
+
# client or id.
|
|
45
81
|
def delete
|
|
46
82
|
raise "Environment was constructed without a client or id; cannot delete" if @client.nil? || @id.nil?
|
|
47
83
|
|
|
@@ -54,6 +90,7 @@ module Smplkit
|
|
|
54
90
|
end
|
|
55
91
|
alias inspect to_s
|
|
56
92
|
|
|
93
|
+
# @api private
|
|
57
94
|
def _apply(other)
|
|
58
95
|
@id = other.id
|
|
59
96
|
@name = other.name
|
|
@@ -68,6 +105,20 @@ module Smplkit
|
|
|
68
105
|
class Service
|
|
69
106
|
attr_accessor :id, :name, :created_at, :updated_at
|
|
70
107
|
|
|
108
|
+
# Create a service instance.
|
|
109
|
+
#
|
|
110
|
+
# Prefer +client.platform.services.new(...)+ to build an unsaved service;
|
|
111
|
+
# this constructor is also used internally to wrap server responses.
|
|
112
|
+
#
|
|
113
|
+
# @param client [ServicesClient, nil] Client used to persist and delete
|
|
114
|
+
# this service. +nil+ produces a detached instance that cannot +save+.
|
|
115
|
+
# @param name [String] Display name shown in the Console.
|
|
116
|
+
# @param id [String, nil] Stable, human-readable identifier for the
|
|
117
|
+
# service.
|
|
118
|
+
# @param created_at [String, nil] When the service was created. Set on
|
|
119
|
+
# instances returned by the server; leave +nil+ for unsaved ones.
|
|
120
|
+
# @param updated_at [String, nil] When the service was last updated. Set
|
|
121
|
+
# on instances returned by the server; leave +nil+ for unsaved ones.
|
|
71
122
|
def initialize(client = nil, name:, id: nil, created_at: nil, updated_at: nil)
|
|
72
123
|
@client = client
|
|
73
124
|
@id = id
|
|
@@ -77,6 +128,9 @@ module Smplkit
|
|
|
77
128
|
end
|
|
78
129
|
|
|
79
130
|
# Create or update this service on the server.
|
|
131
|
+
#
|
|
132
|
+
# @return [Service] +self+, updated with the server response.
|
|
133
|
+
# @raise [RuntimeError] If this service was constructed without a client.
|
|
80
134
|
def save
|
|
81
135
|
raise "Service was constructed without a client; cannot save" if @client.nil?
|
|
82
136
|
|
|
@@ -87,6 +141,10 @@ module Smplkit
|
|
|
87
141
|
alias save! save
|
|
88
142
|
|
|
89
143
|
# Delete this service from the server.
|
|
144
|
+
#
|
|
145
|
+
# @return [void]
|
|
146
|
+
# @raise [RuntimeError] If this service was constructed without a client
|
|
147
|
+
# or id.
|
|
90
148
|
def delete
|
|
91
149
|
raise "Service was constructed without a client or id; cannot delete" if @client.nil? || @id.nil?
|
|
92
150
|
|
|
@@ -99,6 +157,7 @@ module Smplkit
|
|
|
99
157
|
end
|
|
100
158
|
alias inspect to_s
|
|
101
159
|
|
|
160
|
+
# @api private
|
|
102
161
|
def _apply(other)
|
|
103
162
|
@id = other.id
|
|
104
163
|
@name = other.name
|
|
@@ -111,6 +170,25 @@ module Smplkit
|
|
|
111
170
|
class ContextType
|
|
112
171
|
attr_accessor :id, :name, :attributes, :created_at, :updated_at
|
|
113
172
|
|
|
173
|
+
# Create a context-type instance.
|
|
174
|
+
#
|
|
175
|
+
# Prefer +client.platform.context_types.new(...)+ to build an unsaved
|
|
176
|
+
# context type; this constructor is also used internally to wrap server
|
|
177
|
+
# responses.
|
|
178
|
+
#
|
|
179
|
+
# @param client [ContextTypesClient, nil] Client used to persist and
|
|
180
|
+
# delete this context type. +nil+ produces a detached instance that
|
|
181
|
+
# cannot +save+.
|
|
182
|
+
# @param name [String] Display name shown in the Console.
|
|
183
|
+
# @param id [String, nil] Stable, human-readable identifier for the
|
|
184
|
+
# context type.
|
|
185
|
+
# @param attributes [Hash, nil] Known-attribute slots, keyed by attribute
|
|
186
|
+
# name, with a metadata dict per slot. Defaults to no declared
|
|
187
|
+
# attributes.
|
|
188
|
+
# @param created_at [String, nil] When the context type was created. Set
|
|
189
|
+
# on instances returned by the server; leave +nil+ for unsaved ones.
|
|
190
|
+
# @param updated_at [String, nil] When the context type was last updated.
|
|
191
|
+
# Set on instances returned by the server; leave +nil+ for unsaved ones.
|
|
114
192
|
def initialize(client = nil, name:, id: nil, attributes: nil, created_at: nil, updated_at: nil)
|
|
115
193
|
@client = client
|
|
116
194
|
@id = id
|
|
@@ -120,22 +198,39 @@ module Smplkit
|
|
|
120
198
|
@updated_at = updated_at
|
|
121
199
|
end
|
|
122
200
|
|
|
123
|
-
# Add a known-attribute slot. Local; call +save+ to persist.
|
|
201
|
+
# Add a known-attribute slot. Local-only; call +save+ to persist.
|
|
202
|
+
#
|
|
203
|
+
# @param name [String] Attribute name to declare on this context type.
|
|
204
|
+
# @param metadata [Hash] Arbitrary metadata stored for the attribute slot.
|
|
205
|
+
# @return [void]
|
|
124
206
|
def add_attribute(name, **metadata)
|
|
125
207
|
@attributes[name] = stringify_meta(metadata)
|
|
126
208
|
end
|
|
127
209
|
|
|
128
|
-
# Remove a known-attribute slot. Local; call +save+ to persist.
|
|
210
|
+
# Remove a known-attribute slot. Local-only; call +save+ to persist.
|
|
211
|
+
#
|
|
212
|
+
# @param name [String] Attribute name to remove. A no-op if the attribute
|
|
213
|
+
# is not declared on this context type.
|
|
214
|
+
# @return [void]
|
|
129
215
|
def remove_attribute(name)
|
|
130
216
|
@attributes.delete(name)
|
|
131
217
|
end
|
|
132
218
|
|
|
133
|
-
# Replace a known-attribute slot's metadata. Local; call +save+.
|
|
219
|
+
# Replace a known-attribute slot's metadata. Local-only; call +save+.
|
|
220
|
+
#
|
|
221
|
+
# @param name [String] Attribute name whose metadata to replace.
|
|
222
|
+
# @param metadata [Hash] New metadata for the attribute slot, replacing
|
|
223
|
+
# any existing metadata.
|
|
224
|
+
# @return [void]
|
|
134
225
|
def update_attribute(name, **metadata)
|
|
135
226
|
@attributes[name] = stringify_meta(metadata)
|
|
136
227
|
end
|
|
137
228
|
|
|
138
229
|
# Create or update this context type on the server.
|
|
230
|
+
#
|
|
231
|
+
# @return [ContextType] +self+, updated with the server response.
|
|
232
|
+
# @raise [RuntimeError] If this context type was constructed without a
|
|
233
|
+
# client.
|
|
139
234
|
def save
|
|
140
235
|
raise "ContextType was constructed without a client; cannot save" if @client.nil?
|
|
141
236
|
|
|
@@ -146,6 +241,10 @@ module Smplkit
|
|
|
146
241
|
alias save! save
|
|
147
242
|
|
|
148
243
|
# Delete this context type from the server.
|
|
244
|
+
#
|
|
245
|
+
# @return [void]
|
|
246
|
+
# @raise [RuntimeError] If this context type was constructed without a
|
|
247
|
+
# client or id.
|
|
149
248
|
def delete
|
|
150
249
|
raise "ContextType was constructed without a client or id; cannot delete" if @client.nil? || @id.nil?
|
|
151
250
|
|
|
@@ -158,6 +257,7 @@ module Smplkit
|
|
|
158
257
|
end
|
|
159
258
|
alias inspect to_s
|
|
160
259
|
|
|
260
|
+
# @api private
|
|
161
261
|
def _apply(other)
|
|
162
262
|
@id = other.id
|
|
163
263
|
@name = other.name
|
|
@@ -31,6 +31,12 @@ module Smplkit
|
|
|
31
31
|
class Color
|
|
32
32
|
attr_reader :hex
|
|
33
33
|
|
|
34
|
+
# Build a +Color+ from a CSS hex string.
|
|
35
|
+
#
|
|
36
|
+
# @param hex [String] A CSS hex string like +"#RGB"+, +"#RRGGBB"+, or
|
|
37
|
+
# +"#RRGGBBAA"+. Normalized to lowercase.
|
|
38
|
+
# @raise [TypeError] If +hex+ is not a String.
|
|
39
|
+
# @raise [ArgumentError] If +hex+ is not a valid CSS hex string.
|
|
34
40
|
def initialize(hex)
|
|
35
41
|
raise TypeError, "Color hex must be a String, got #{hex.class}: #{hex.inspect}" unless hex.is_a?(String)
|
|
36
42
|
unless HEX_RE.match?(hex)
|
|
@@ -42,6 +48,14 @@ module Smplkit
|
|
|
42
48
|
freeze
|
|
43
49
|
end
|
|
44
50
|
|
|
51
|
+
# Construct a +Color+ from 0-255 RGB components.
|
|
52
|
+
#
|
|
53
|
+
# @param red [Integer] Red component, an integer in the range 0-255.
|
|
54
|
+
# @param green [Integer] Green component, an integer in the range 0-255.
|
|
55
|
+
# @param blue [Integer] Blue component, an integer in the range 0-255.
|
|
56
|
+
# @return [Color] A color with the equivalent hex value.
|
|
57
|
+
# @raise [TypeError] If any component is not an integer.
|
|
58
|
+
# @raise [ArgumentError] If any component is outside the range 0-255.
|
|
45
59
|
def self.rgb(red, green, blue)
|
|
46
60
|
[%w[red green blue], [red, green, blue]].transpose.each do |name, val|
|
|
47
61
|
unless val.is_a?(Integer) && !val.is_a?(TrueClass) && !val.is_a?(FalseClass)
|
data/lib/smplkit/transport.rb
CHANGED
|
@@ -12,6 +12,8 @@ module Smplkit
|
|
|
12
12
|
# connect lazily on first call) and shared by the top-level client.
|
|
13
13
|
#
|
|
14
14
|
# There is no audit transport here — +client.audit+ owns its own.
|
|
15
|
+
#
|
|
16
|
+
# @api private
|
|
15
17
|
module Transport
|
|
16
18
|
SDK_OWNED_HEADERS = %w[authorization content-type user-agent].freeze
|
|
17
19
|
|
|
@@ -23,7 +25,7 @@ module Smplkit
|
|
|
23
25
|
# transports need; this drops the runtime-only fields (environment,
|
|
24
26
|
# service, telemetry).
|
|
25
27
|
def to_transport_config(cfg, extra_headers = nil)
|
|
26
|
-
ConfigResolution::
|
|
28
|
+
ConfigResolution::ResolvedClientConfig.new(
|
|
27
29
|
api_key: cfg.api_key,
|
|
28
30
|
base_domain: cfg.base_domain,
|
|
29
31
|
scheme: cfg.scheme,
|
|
@@ -38,6 +40,8 @@ module Smplkit
|
|
|
38
40
|
# first call. +app_url+ is carried alongside so the account settings client
|
|
39
41
|
# and the WebSocket can reach the app service. +close+ tears down the
|
|
40
42
|
# underlying Faraday connection pools.
|
|
43
|
+
#
|
|
44
|
+
# @api private
|
|
41
45
|
ServiceTransports = Struct.new(
|
|
42
46
|
:app_url, :api_key, :app_http, :config_http, :flags_http, :logging_http, :jobs_http,
|
|
43
47
|
keyword_init: true
|
data/lib/smplkit/ws.rb
CHANGED
|
@@ -19,7 +19,7 @@ module Smplkit
|
|
|
19
19
|
# +Async+ reactor and the underlying +async-websocket+ I/O. Public
|
|
20
20
|
# methods are thread-safe and non-blocking.
|
|
21
21
|
#
|
|
22
|
-
# Gateway protocol
|
|
22
|
+
# Gateway protocol:
|
|
23
23
|
#
|
|
24
24
|
# - Connect to +wss://app.<base_domain>/api/ws/v1/events?api_key={key}+
|
|
25
25
|
# - Receive +{"type": "connected"}+ on success
|