cent 4.0.0 → 5.0.0

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.
@@ -0,0 +1,4226 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Code generated by gen/generate.rb from proto/api.proto. DO NOT EDIT.
4
+
5
+ module Cent
6
+ # Every API method, batch included, and whether only Centrifugo PRO has it.
7
+ #
8
+ # @api private
9
+ API_METHODS = {
10
+ "batch" => false,
11
+ "publish" => false,
12
+ "broadcast" => false,
13
+ "subscribe" => false,
14
+ "unsubscribe" => false,
15
+ "disconnect" => false,
16
+ "presence" => false,
17
+ "presence_stats" => false,
18
+ "history" => false,
19
+ "history_remove" => false,
20
+ "info" => false,
21
+ "refresh" => false,
22
+ "channels" => false,
23
+ "connections" => true,
24
+ "update_user_status" => true,
25
+ "get_user_status" => true,
26
+ "delete_user_status" => true,
27
+ "block_user" => true,
28
+ "unblock_user" => true,
29
+ "revoke_token" => true,
30
+ "invalidate_user_tokens" => true,
31
+ "device_register" => true,
32
+ "device_update" => true,
33
+ "device_remove" => true,
34
+ "device_list" => true,
35
+ "device_topic_list" => true,
36
+ "device_topic_update" => true,
37
+ "user_topic_list" => true,
38
+ "user_topic_update" => true,
39
+ "send_push_notification" => true,
40
+ "update_push_status" => true,
41
+ "cancel_push" => true,
42
+ "map_publish" => false,
43
+ "map_remove" => false,
44
+ "map_read_state" => false,
45
+ "map_read_stream" => false,
46
+ "map_stats" => false,
47
+ "map_clear" => false,
48
+ "shared_poll_publish" => false
49
+ }.freeze
50
+
51
+ # The fields each request - by its method - and each message in a request -
52
+ # by its name - must have a value in, and the messages in it to check:
53
+ # [field, required, the message's name or nil, a list]. Checked on the
54
+ # request's JSON, which leaves out a field at its zero value.
55
+ #
56
+ # @api private
57
+ REQUIRED = {
58
+ "publish" => [["channel", true, nil, false]].freeze,
59
+ "broadcast" => [["channels", true, nil, true]].freeze,
60
+ "subscribe" => [["channel", true, nil, false]].freeze,
61
+ "unsubscribe" => [["channel", true, nil, false]].freeze,
62
+ "disconnect" => [].freeze,
63
+ "presence" => [["channel", true, nil, false]].freeze,
64
+ "presence_stats" => [["channel", true, nil, false]].freeze,
65
+ "history" => [["channel", true, nil, false]].freeze,
66
+ "history_remove" => [["channel", true, nil, false]].freeze,
67
+ "info" => [].freeze,
68
+ "refresh" => [].freeze,
69
+ "channels" => [].freeze,
70
+ "connections" => [].freeze,
71
+ "update_user_status" => [["users", true, nil, true]].freeze,
72
+ "get_user_status" => [["users", true, nil, true]].freeze,
73
+ "delete_user_status" => [["users", true, nil, true]].freeze,
74
+ "block_user" => [["user", true, nil, false]].freeze,
75
+ "unblock_user" => [["user", true, nil, false]].freeze,
76
+ "revoke_token" => [["uid", true, nil, false]].freeze,
77
+ "invalidate_user_tokens" => [].freeze,
78
+ "device_register" => [
79
+ ["provider", true, nil, false],
80
+ ["token", true, nil, false],
81
+ ["platform", true, nil, false]
82
+ ].freeze,
83
+ "device_update" => [["topics_update", false, "DeviceTopicsUpdate", false]].freeze,
84
+ "device_remove" => [].freeze,
85
+ "device_list" => [].freeze,
86
+ "device_topic_list" => [].freeze,
87
+ "device_topic_update" => [["device_id", true, nil, false], ["op", true, nil, false]].freeze,
88
+ "user_topic_list" => [].freeze,
89
+ "user_topic_update" => [["op", true, nil, false]].freeze,
90
+ "send_push_notification" => [
91
+ ["recipient", true, nil, false],
92
+ ["notification", true, "PushNotification", false],
93
+ ["limit_strategy", false, "PushLimitStrategy", false]
94
+ ].freeze,
95
+ "update_push_status" => [
96
+ ["analytics_uid", true, nil, false],
97
+ ["status", true, nil, false],
98
+ ["device_id", true, nil, false]
99
+ ].freeze,
100
+ "cancel_push" => [["uid", true, nil, false]].freeze,
101
+ "map_publish" => [["channel", true, nil, false], ["key", true, nil, false]].freeze,
102
+ "map_remove" => [["channel", true, nil, false], ["key", true, nil, false]].freeze,
103
+ "map_read_state" => [["channel", true, nil, false]].freeze,
104
+ "map_read_stream" => [["channel", true, nil, false]].freeze,
105
+ "map_stats" => [["channel", true, nil, false]].freeze,
106
+ "map_clear" => [["channel", true, nil, false]].freeze,
107
+ "shared_poll_publish" => [
108
+ ["channel", true, nil, false],
109
+ ["key", true, nil, false],
110
+ ["version", true, nil, false]
111
+ ].freeze,
112
+ "DeviceTopicsUpdate" => [["op", true, nil, false]].freeze,
113
+ "PushNotification" => [
114
+ ["fcm", false, "FcmPushNotification", false],
115
+ ["hms", false, "HmsPushNotification", false],
116
+ ["apns", false, "ApnsPushNotification", false],
117
+ ["webpush", false, "WebPushPushNotification", false]
118
+ ].freeze,
119
+ "FcmPushNotification" => [["message", true, nil, false]].freeze,
120
+ "HmsPushNotification" => [["message", true, nil, false]].freeze,
121
+ "ApnsPushNotification" => [["payload", true, nil, false]].freeze,
122
+ "WebPushPushNotification" => [["payload", true, nil, false]].freeze,
123
+ "PushLimitStrategy" => [
124
+ ["rate_limit", false, "PushRateLimitStrategy", false],
125
+ ["time_limit", false, "PushTimeLimitStrategy", false]
126
+ ].freeze,
127
+ "PushRateLimitStrategy" => [["policies", false, "RateLimitPolicy", true]].freeze,
128
+ "RateLimitPolicy" => [["rate", true, nil, false], ["interval_ms", true, nil, false]].freeze,
129
+ "PushTimeLimitStrategy" => [
130
+ ["send_after_time", true, nil, false],
131
+ ["send_before_time", true, nil, false]
132
+ ].freeze
133
+ }.freeze
134
+
135
+ # The JSON of each API method's request, from its fields, as the methods of
136
+ # Client, Batch and Command take them.
137
+ #
138
+ # @api private
139
+ module Requests
140
+ module_function
141
+
142
+ def publish(
143
+ channel,
144
+ data,
145
+ b64data,
146
+ skip_history,
147
+ tags,
148
+ idempotency_key,
149
+ delta,
150
+ version,
151
+ version_epoch
152
+ )
153
+ w = {}
154
+ Wire.put(w, "channel", channel, "", :str)
155
+ Wire.put(w, "data", data, "", :json)
156
+ Wire.put(w, "b64data", b64data, "", :str)
157
+ Wire.put(w, "skip_history", skip_history, "", :bool)
158
+ Wire.put(w, "tags", tags, "", :str, :map)
159
+ Wire.put(w, "idempotency_key", idempotency_key, "", :str)
160
+ Wire.put(w, "delta", delta, "", :bool)
161
+ Wire.put(w, "version", version, "", :int)
162
+ Wire.put(w, "version_epoch", version_epoch, "", :str)
163
+ w
164
+ end
165
+
166
+ def broadcast(
167
+ channels,
168
+ data,
169
+ b64data,
170
+ skip_history,
171
+ tags,
172
+ idempotency_key,
173
+ delta,
174
+ version,
175
+ version_epoch
176
+ )
177
+ w = {}
178
+ Wire.put(w, "channels", channels, "", :str, :list)
179
+ Wire.put(w, "data", data, "", :json)
180
+ Wire.put(w, "b64data", b64data, "", :str)
181
+ Wire.put(w, "skip_history", skip_history, "", :bool)
182
+ Wire.put(w, "tags", tags, "", :str, :map)
183
+ Wire.put(w, "idempotency_key", idempotency_key, "", :str)
184
+ Wire.put(w, "delta", delta, "", :bool)
185
+ Wire.put(w, "version", version, "", :int)
186
+ Wire.put(w, "version_epoch", version_epoch, "", :str)
187
+ w
188
+ end
189
+
190
+ def subscribe(
191
+ channel,
192
+ user,
193
+ expire_at,
194
+ info,
195
+ b64info,
196
+ client,
197
+ data,
198
+ b64data,
199
+ recover_since,
200
+ override,
201
+ session,
202
+ label_filter,
203
+ all_users
204
+ )
205
+ w = {}
206
+ Wire.put(w, "channel", channel, "", :str)
207
+ Wire.put(w, "user", user, "", :str)
208
+ Wire.put(w, "expire_at", expire_at, "", :int)
209
+ Wire.put(w, "info", info, "", :json)
210
+ Wire.put(w, "b64info", b64info, "", :str)
211
+ Wire.put(w, "client", client, "", :str)
212
+ Wire.put(w, "data", data, "", :json)
213
+ Wire.put(w, "b64data", b64data, "", :str)
214
+ Wire.put(w, "recover_since", recover_since, "", StreamPosition)
215
+ Wire.put(w, "override", override, "", SubscribeOptionOverride)
216
+ Wire.put(w, "session", session, "", :str)
217
+ Wire.put(w, "label_filter", label_filter, "", FilterNode)
218
+ Wire.put(w, "all_users", all_users, "", :bool)
219
+ w
220
+ end
221
+
222
+ def unsubscribe(
223
+ channel,
224
+ user,
225
+ client,
226
+ session,
227
+ label_filter,
228
+ all_users
229
+ )
230
+ w = {}
231
+ Wire.put(w, "channel", channel, "", :str)
232
+ Wire.put(w, "user", user, "", :str)
233
+ Wire.put(w, "client", client, "", :str)
234
+ Wire.put(w, "session", session, "", :str)
235
+ Wire.put(w, "label_filter", label_filter, "", FilterNode)
236
+ Wire.put(w, "all_users", all_users, "", :bool)
237
+ w
238
+ end
239
+
240
+ def disconnect(
241
+ user,
242
+ disconnect,
243
+ client,
244
+ whitelist,
245
+ session,
246
+ label_filter,
247
+ all_users
248
+ )
249
+ w = {}
250
+ Wire.put(w, "user", user, "", :str)
251
+ Wire.put(w, "disconnect", disconnect, "", Disconnect)
252
+ Wire.put(w, "client", client, "", :str)
253
+ Wire.put(w, "whitelist", whitelist, "", :str, :list)
254
+ Wire.put(w, "session", session, "", :str)
255
+ Wire.put(w, "label_filter", label_filter, "", FilterNode)
256
+ Wire.put(w, "all_users", all_users, "", :bool)
257
+ w
258
+ end
259
+
260
+ def presence(channel)
261
+ w = {}
262
+ Wire.put(w, "channel", channel, "", :str)
263
+ w
264
+ end
265
+
266
+ def presence_stats(channel)
267
+ w = {}
268
+ Wire.put(w, "channel", channel, "", :str)
269
+ w
270
+ end
271
+
272
+ def history(
273
+ channel,
274
+ limit,
275
+ since,
276
+ reverse
277
+ )
278
+ w = {}
279
+ Wire.put(w, "channel", channel, "", :str)
280
+ Wire.put(w, "limit", limit, "", :int)
281
+ Wire.put(w, "since", since, "", StreamPosition)
282
+ Wire.put(w, "reverse", reverse, "", :bool)
283
+ w
284
+ end
285
+
286
+ def history_remove(channel)
287
+ w = {}
288
+ Wire.put(w, "channel", channel, "", :str)
289
+ w
290
+ end
291
+
292
+ def info
293
+ {}
294
+ end
295
+
296
+ def refresh(
297
+ user,
298
+ client,
299
+ expired,
300
+ expire_at,
301
+ info,
302
+ session,
303
+ label_filter,
304
+ all_users
305
+ )
306
+ w = {}
307
+ Wire.put(w, "user", user, "", :str)
308
+ Wire.put(w, "client", client, "", :str)
309
+ Wire.put(w, "expired", expired, "", :bool)
310
+ Wire.put(w, "expire_at", expire_at, "", :int)
311
+ Wire.put(w, "info", info, "", :json)
312
+ Wire.put(w, "session", session, "", :str)
313
+ Wire.put(w, "label_filter", label_filter, "", FilterNode)
314
+ Wire.put(w, "all_users", all_users, "", :bool)
315
+ w
316
+ end
317
+
318
+ def channels(pattern)
319
+ w = {}
320
+ Wire.put(w, "pattern", pattern, "", :str)
321
+ w
322
+ end
323
+
324
+ def connections(user, expression, label_filter)
325
+ w = {}
326
+ Wire.put(w, "user", user, "", :str)
327
+ Wire.put(w, "expression", expression, "", :str)
328
+ Wire.put(w, "label_filter", label_filter, "", FilterNode)
329
+ w
330
+ end
331
+
332
+ def update_user_status(users, state)
333
+ w = {}
334
+ Wire.put(w, "users", users, "", :str, :list)
335
+ Wire.put(w, "state", state, "", :str)
336
+ w
337
+ end
338
+
339
+ def get_user_status(users)
340
+ w = {}
341
+ Wire.put(w, "users", users, "", :str, :list)
342
+ w
343
+ end
344
+
345
+ def delete_user_status(users)
346
+ w = {}
347
+ Wire.put(w, "users", users, "", :str, :list)
348
+ w
349
+ end
350
+
351
+ def block_user(expire_at, user)
352
+ w = {}
353
+ Wire.put(w, "expire_at", expire_at, "", :int)
354
+ Wire.put(w, "user", user, "", :str)
355
+ w
356
+ end
357
+
358
+ def unblock_user(user)
359
+ w = {}
360
+ Wire.put(w, "user", user, "", :str)
361
+ w
362
+ end
363
+
364
+ def revoke_token(expire_at, uid)
365
+ w = {}
366
+ Wire.put(w, "expire_at", expire_at, "", :int)
367
+ Wire.put(w, "uid", uid, "", :str)
368
+ w
369
+ end
370
+
371
+ def invalidate_user_tokens(
372
+ expire_at,
373
+ user,
374
+ issued_before,
375
+ channel
376
+ )
377
+ w = {}
378
+ Wire.put(w, "expire_at", expire_at, "", :int)
379
+ Wire.put(w, "user", user, "", :str)
380
+ Wire.put(w, "issued_before", issued_before, "", :int)
381
+ Wire.put(w, "channel", channel, "", :str)
382
+ w
383
+ end
384
+
385
+ def device_register(
386
+ id,
387
+ provider,
388
+ token,
389
+ platform,
390
+ user,
391
+ meta,
392
+ topics,
393
+ timezone,
394
+ locale
395
+ )
396
+ w = {}
397
+ Wire.put(w, "id", id, "", :str)
398
+ Wire.put(w, "provider", provider, "", :str)
399
+ Wire.put(w, "token", token, "", :str)
400
+ Wire.put(w, "platform", platform, "", :str)
401
+ Wire.put(w, "user", user, "", :str)
402
+ Wire.put(w, "meta", meta, "", :str, :map)
403
+ Wire.put(w, "topics", topics, "", :str, :list)
404
+ Wire.put(w, "timezone", timezone, "", :str)
405
+ Wire.put(w, "locale", locale, "", :str)
406
+ w
407
+ end
408
+
409
+ def device_update(
410
+ ids,
411
+ users,
412
+ user_update,
413
+ meta_update,
414
+ topics_update,
415
+ timezone_update,
416
+ locale_update
417
+ )
418
+ w = {}
419
+ Wire.put(w, "ids", ids, "", :str, :list)
420
+ Wire.put(w, "users", users, "", :str, :list)
421
+ Wire.put(w, "user_update", user_update, "", DeviceUserUpdate, :presence)
422
+ Wire.put(w, "meta_update", meta_update, "", DeviceMetaUpdate, :presence)
423
+ Wire.put(w, "topics_update", topics_update, "", DeviceTopicsUpdate)
424
+ Wire.put(w, "timezone_update", timezone_update, "", DeviceTimezoneUpdate, :presence)
425
+ Wire.put(w, "locale_update", locale_update, "", DeviceLocaleUpdate, :presence)
426
+ w
427
+ end
428
+
429
+ def device_remove(ids, users)
430
+ w = {}
431
+ Wire.put(w, "ids", ids, "", :str, :list)
432
+ Wire.put(w, "users", users, "", :str, :list)
433
+ w
434
+ end
435
+
436
+ def device_list(
437
+ filter,
438
+ include_total_count,
439
+ include_meta,
440
+ include_topics,
441
+ include_webpush_keys,
442
+ cursor,
443
+ limit
444
+ )
445
+ w = {}
446
+ Wire.put(w, "filter", filter, "", DeviceFilter)
447
+ Wire.put(w, "include_total_count", include_total_count, "", :bool)
448
+ Wire.put(w, "include_meta", include_meta, "", :bool)
449
+ Wire.put(w, "include_topics", include_topics, "", :bool)
450
+ Wire.put(w, "include_webpush_keys", include_webpush_keys, "", :bool)
451
+ Wire.put(w, "cursor", cursor, "", :str)
452
+ Wire.put(w, "limit", limit, "", :int)
453
+ w
454
+ end
455
+
456
+ def device_topic_list(
457
+ filter,
458
+ include_total_count,
459
+ include_device,
460
+ cursor,
461
+ limit
462
+ )
463
+ w = {}
464
+ Wire.put(w, "filter", filter, "", DeviceTopicFilter)
465
+ Wire.put(w, "include_total_count", include_total_count, "", :bool)
466
+ Wire.put(w, "include_device", include_device, "", :bool)
467
+ Wire.put(w, "cursor", cursor, "", :str)
468
+ Wire.put(w, "limit", limit, "", :int)
469
+ w
470
+ end
471
+
472
+ def device_topic_update(
473
+ device_id,
474
+ op,
475
+ topics,
476
+ user
477
+ )
478
+ w = {}
479
+ Wire.put(w, "device_id", device_id, "", :str)
480
+ Wire.put(w, "op", op, "", :str)
481
+ Wire.put(w, "topics", topics, "", :str, :list)
482
+ Wire.put(w, "user", user, "", :str)
483
+ w
484
+ end
485
+
486
+ def user_topic_list(
487
+ filter,
488
+ include_total_count,
489
+ cursor,
490
+ limit
491
+ )
492
+ w = {}
493
+ Wire.put(w, "filter", filter, "", UserTopicFilter)
494
+ Wire.put(w, "include_total_count", include_total_count, "", :bool)
495
+ Wire.put(w, "cursor", cursor, "", :str)
496
+ Wire.put(w, "limit", limit, "", :int)
497
+ w
498
+ end
499
+
500
+ def user_topic_update(user, op, topics)
501
+ w = {}
502
+ Wire.put(w, "user", user, "", :str)
503
+ Wire.put(w, "op", op, "", :str)
504
+ Wire.put(w, "topics", topics, "", :str, :list)
505
+ w
506
+ end
507
+
508
+ def send_push_notification(
509
+ recipient,
510
+ notification,
511
+ uid,
512
+ send_at,
513
+ optimize_for_reliability,
514
+ limit_strategy,
515
+ analytics_uid,
516
+ localizations,
517
+ use_templating,
518
+ use_meta
519
+ )
520
+ w = {}
521
+ Wire.put(w, "recipient", recipient, "", PushRecipient)
522
+ Wire.put(w, "notification", notification, "", PushNotification)
523
+ Wire.put(w, "uid", uid, "", :str)
524
+ Wire.put(w, "send_at", send_at, "", :int)
525
+ Wire.put(w, "optimize_for_reliability", optimize_for_reliability, "", :bool)
526
+ Wire.put(w, "limit_strategy", limit_strategy, "", PushLimitStrategy)
527
+ Wire.put(w, "analytics_uid", analytics_uid, "", :str)
528
+ Wire.put(w, "localizations", localizations, "", PushLocalization, :map)
529
+ Wire.put(w, "use_templating", use_templating, "", :bool)
530
+ Wire.put(w, "use_meta", use_meta, "", :bool)
531
+ w
532
+ end
533
+
534
+ def update_push_status(
535
+ analytics_uid,
536
+ status,
537
+ device_id,
538
+ msg_id
539
+ )
540
+ w = {}
541
+ Wire.put(w, "analytics_uid", analytics_uid, "", :str)
542
+ Wire.put(w, "status", status, "", :str)
543
+ Wire.put(w, "device_id", device_id, "", :str)
544
+ Wire.put(w, "msg_id", msg_id, "", :str)
545
+ w
546
+ end
547
+
548
+ def cancel_push(uid)
549
+ w = {}
550
+ Wire.put(w, "uid", uid, "", :str)
551
+ w
552
+ end
553
+
554
+ def map_publish(
555
+ channel,
556
+ key,
557
+ data,
558
+ b64data,
559
+ stream_data,
560
+ b64stream_data,
561
+ tags,
562
+ idempotency_key,
563
+ delta,
564
+ version,
565
+ version_epoch,
566
+ score,
567
+ key_mode
568
+ )
569
+ w = {}
570
+ Wire.put(w, "channel", channel, "", :str)
571
+ Wire.put(w, "key", key, "", :str)
572
+ Wire.put(w, "data", data, "", :json)
573
+ Wire.put(w, "b64data", b64data, "", :str)
574
+ Wire.put(w, "stream_data", stream_data, "", :json)
575
+ Wire.put(w, "b64stream_data", b64stream_data, "", :str)
576
+ Wire.put(w, "tags", tags, "", :str, :map)
577
+ Wire.put(w, "idempotency_key", idempotency_key, "", :str)
578
+ Wire.put(w, "delta", delta, "", :bool)
579
+ Wire.put(w, "version", version, "", :int)
580
+ Wire.put(w, "version_epoch", version_epoch, "", :str)
581
+ Wire.put(w, "score", score, "", :int)
582
+ Wire.put(w, "key_mode", key_mode, "", :str)
583
+ w
584
+ end
585
+
586
+ def map_remove(channel, key, idempotency_key)
587
+ w = {}
588
+ Wire.put(w, "channel", channel, "", :str)
589
+ Wire.put(w, "key", key, "", :str)
590
+ Wire.put(w, "idempotency_key", idempotency_key, "", :str)
591
+ w
592
+ end
593
+
594
+ def map_read_state(
595
+ channel,
596
+ cursor,
597
+ limit,
598
+ key,
599
+ asc,
600
+ revision_offset,
601
+ revision_epoch
602
+ )
603
+ w = {}
604
+ Wire.put(w, "channel", channel, "", :str)
605
+ Wire.put(w, "cursor", cursor, "", :str)
606
+ Wire.put(w, "limit", limit, "", :int)
607
+ Wire.put(w, "key", key, "", :str)
608
+ Wire.put(w, "asc", asc, "", :bool)
609
+ Wire.put(w, "revision_offset", revision_offset, "", :int)
610
+ Wire.put(w, "revision_epoch", revision_epoch, "", :str)
611
+ w
612
+ end
613
+
614
+ def map_read_stream(
615
+ channel,
616
+ since_offset,
617
+ since_epoch,
618
+ limit,
619
+ reverse
620
+ )
621
+ w = {}
622
+ Wire.put(w, "channel", channel, "", :str)
623
+ Wire.put(w, "since_offset", since_offset, "", :int)
624
+ Wire.put(w, "since_epoch", since_epoch, "", :str)
625
+ Wire.put(w, "limit", limit, "", :int)
626
+ Wire.put(w, "reverse", reverse, "", :bool)
627
+ w
628
+ end
629
+
630
+ def map_stats(channel)
631
+ w = {}
632
+ Wire.put(w, "channel", channel, "", :str)
633
+ w
634
+ end
635
+
636
+ def map_clear(channel)
637
+ w = {}
638
+ Wire.put(w, "channel", channel, "", :str)
639
+ w
640
+ end
641
+
642
+ def shared_poll_publish(
643
+ channel,
644
+ key,
645
+ data,
646
+ b64data,
647
+ version,
648
+ epoch
649
+ )
650
+ w = {}
651
+ Wire.put(w, "channel", channel, "", :str)
652
+ Wire.put(w, "key", key, "", :str)
653
+ Wire.put(w, "data", data, "", :json)
654
+ Wire.put(w, "b64data", b64data, "", :str)
655
+ Wire.put(w, "version", version, "", :int)
656
+ Wire.put(w, "epoch", epoch, "", :str)
657
+ w
658
+ end
659
+ end
660
+
661
+ # The server API methods of Client, one per method of api.proto.
662
+ #
663
+ # @api private
664
+ module ClientMethods
665
+ # Publishes data into a channel.
666
+ #
667
+ # @param channel [String, nil] The name of the channel to publish into. Required.
668
+ # @param data [Object, nil] The payload to publish. Required unless b64data is set. In the
669
+ # HTTP API it is any JSON value; over GRPC it may be binary.
670
+ # @param b64data [String, nil] A base64-encoded binary payload, an alternative to `data` to
671
+ # send binary over the HTTP API. Centrifugo decodes it before publishing.
672
+ # @param skip_history [Boolean, nil] Skips adding this publication to the channel history.
673
+ # @param tags [Hash{String => String}] A map of arbitrary string keys and values attached to the
674
+ # publication and delivered to clients.
675
+ # @param idempotency_key [String, nil] Drops duplicate publications upon retries: a
676
+ # publication with a key already used in the channel is not published
677
+ # again, and the first one's result is returned. It acts per channel;
678
+ # results are kept for 5 minutes by default. The memory, Redis and
679
+ # PostgreSQL brokers keep keys; the NATS broker ignores them.
680
+ # @param delta [Boolean, nil] Tells Centrifugo to construct a delta update, if possible, when
681
+ # broadcasting the publication to subscribers.
682
+ # @param version [Integer, nil] When > 0, the version of the document being sent:
683
+ # publications with a version less than or equal to one already seen are
684
+ # ignored. Only works in channels with history enabled.
685
+ # @param version_epoch [String, nil] The epoch of version. When it changes, Centrifugo
686
+ # accepts the publication even if its version is lower than before.
687
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
688
+ # @return [PublishResult]
689
+ # @raise [Error]
690
+ def publish(
691
+ channel:,
692
+ data: nil,
693
+ b64data: nil,
694
+ skip_history: nil,
695
+ tags: nil,
696
+ idempotency_key: nil,
697
+ delta: nil,
698
+ version: nil,
699
+ version_epoch: nil,
700
+ timeout: nil
701
+ )
702
+ invoke("publish", PublishResult, timeout) do
703
+ Requests.publish(
704
+ channel,
705
+ data,
706
+ b64data,
707
+ skip_history,
708
+ tags,
709
+ idempotency_key,
710
+ delta,
711
+ version,
712
+ version_epoch
713
+ )
714
+ end
715
+ end
716
+
717
+ # Publishes the same data into many channels.
718
+ #
719
+ # Channels succeed or fail on their own. It returns when every channel got the
720
+ # publication. When Centrifugo carried the broadcast out and one or more
721
+ # channels failed - up to all of them - it raises BroadcastFailedChannelsError,
722
+ # whose result holds every channel's outcome. Any other error means it failed
723
+ # as a whole: no channel got a reply. After a timeout or a network error
724
+ # Centrifugo may still have published it.
725
+ #
726
+ # To go on despite some failed channels:
727
+ #
728
+ # begin
729
+ # client.broadcast(channels:, data:)
730
+ # rescue Cent::BroadcastFailedChannelsError => e
731
+ # logger.warn("broadcast failed in #{e.result.failed.map(&:channel)}")
732
+ # end
733
+ #
734
+ # Retry it with broadcast_with_retry, which sends again only the channels which
735
+ # may still succeed, with one idempotency_key.
736
+ #
737
+ # @param channels [Array<String>] The list of channels to publish into. Required.
738
+ # @param data [Object, nil] The payload to publish into each channel. Required unless
739
+ # b64data is set. In the HTTP API it is any JSON value; over GRPC it may
740
+ # be binary.
741
+ # @param b64data [String, nil] A base64-encoded binary payload, an alternative to `data` to
742
+ # send binary over the HTTP API. Centrifugo decodes it before publishing.
743
+ # @param skip_history [Boolean, nil] Skips adding the publications to the channels' history.
744
+ # @param tags [Hash{String => String}] A map of arbitrary string keys and values attached to each
745
+ # publication and delivered to clients.
746
+ # @param idempotency_key [String, nil] Drops duplicate publications upon retries. It acts per
747
+ # channel: a broadcast retried with the same key is not published again
748
+ # into the channels which already have it. Results are kept for 5 minutes
749
+ # by default. The memory, Redis and PostgreSQL brokers keep keys; the
750
+ # NATS broker ignores them.
751
+ # @param delta [Boolean, nil] Tells Centrifugo to construct a delta update, if possible, when
752
+ # broadcasting the publications to subscribers.
753
+ # @param version [Integer, nil] When > 0, the version of the document being sent:
754
+ # publications with a version less than or equal to one already seen are
755
+ # ignored. Only works in channels with history enabled.
756
+ # @param version_epoch [String, nil] The epoch of version. When it changes, Centrifugo
757
+ # accepts the publication even if its version is lower than before.
758
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
759
+ # @return [BroadcastResult]
760
+ # @raise [Error]
761
+ def broadcast(
762
+ channels:,
763
+ data: nil,
764
+ b64data: nil,
765
+ skip_history: nil,
766
+ tags: nil,
767
+ idempotency_key: nil,
768
+ delta: nil,
769
+ version: nil,
770
+ version_epoch: nil,
771
+ timeout: nil
772
+ )
773
+ send_broadcast(timeout) do
774
+ Requests.broadcast(
775
+ channels,
776
+ data,
777
+ b64data,
778
+ skip_history,
779
+ tags,
780
+ idempotency_key,
781
+ delta,
782
+ version,
783
+ version_epoch
784
+ )
785
+ end
786
+ end
787
+
788
+ # Broadcasts as broadcast does, and retries the channels which failed for a
789
+ # temporary reason - see Cent.retryable? - up to max_attempts (2 by default:
790
+ # one retry).
791
+ #
792
+ # - Only the channels which may still succeed are sent again; when only
793
+ # channels which failed for good are left, it stops.
794
+ # - Every attempt carries the same idempotency_key - made for the call when
795
+ # none is given - so that a channel which got the publication in an earlier
796
+ # attempt does not get it again. The memory, Redis and PostgreSQL brokers
797
+ # keep keys; the NATS broker ignores them, and a retry may publish again.
798
+ # - The result holds every channel's last outcome, and the key: retrying later
799
+ # with it publishes only into the channels which did not get it.
800
+ #
801
+ # timeout, when set, bounds the whole call, waits included. attempt_timeout is
802
+ # each attempt's own timeout, replacing request_timeout - longer or shorter -
803
+ # as a call's timeout does; timeout still ends an attempt sooner.
804
+ #
805
+ # The block, when given, is called after an attempt which failed in a way a
806
+ # retry may fix, except the last, with a BroadcastAttempt. It returns the
807
+ # seconds to wait before the next attempt, or nil for the default wait -
808
+ # Cent.exponential_backoff(0.1, 5.0) of the attempt - and may log or count
809
+ # meanwhile. To stop, it raises: its exception propagates, its cause the
810
+ # attempt's error. The wait never outlasts the call's timeout.
811
+ #
812
+ # client.broadcast_with_retry(channels:, data:, max_attempts: 5) do |attempt|
813
+ # logger.info("attempt #{attempt.attempt}: #{attempt.retry.size} channels to retry")
814
+ # nil
815
+ # end
816
+ #
817
+ # It raises as broadcast does.
818
+ #
819
+ # @param channels [Array<String>] The list of channels to publish into. Required.
820
+ # @param data [Object, nil] The payload to publish into each channel. Required unless
821
+ # b64data is set. In the HTTP API it is any JSON value; over GRPC it may
822
+ # be binary.
823
+ # @param b64data [String, nil] A base64-encoded binary payload, an alternative to `data` to
824
+ # send binary over the HTTP API. Centrifugo decodes it before publishing.
825
+ # @param skip_history [Boolean, nil] Skips adding the publications to the channels' history.
826
+ # @param tags [Hash{String => String}] A map of arbitrary string keys and values attached to each
827
+ # publication and delivered to clients.
828
+ # @param idempotency_key [String, nil] Drops duplicate publications upon retries. It acts per
829
+ # channel: a broadcast retried with the same key is not published again
830
+ # into the channels which already have it. Results are kept for 5 minutes
831
+ # by default. The memory, Redis and PostgreSQL brokers keep keys; the
832
+ # NATS broker ignores them.
833
+ # @param delta [Boolean, nil] Tells Centrifugo to construct a delta update, if possible, when
834
+ # broadcasting the publications to subscribers.
835
+ # @param version [Integer, nil] When > 0, the version of the document being sent:
836
+ # publications with a version less than or equal to one already seen are
837
+ # ignored. Only works in channels with history enabled.
838
+ # @param version_epoch [String, nil] The epoch of version. When it changes, Centrifugo
839
+ # accepts the publication even if its version is lower than before.
840
+ # @param max_attempts [Integer] Attempts at most, the first included.
841
+ # @param attempt_timeout [Numeric, nil] Seconds bounding each attempt, replacing request_timeout:
842
+ # request_timeout when nil.
843
+ # @param timeout [Numeric, nil] Seconds bounding the whole call, waits included: no
844
+ # bound but each attempt's when nil.
845
+ # @yieldparam attempt [BroadcastAttempt] a failed attempt which will be retried
846
+ # @yieldreturn [Numeric, nil] seconds to wait before the next attempt, nil for the default
847
+ # @return [BroadcastResult]
848
+ # @raise [Error]
849
+ def broadcast_with_retry(
850
+ channels:,
851
+ data: nil,
852
+ b64data: nil,
853
+ skip_history: nil,
854
+ tags: nil,
855
+ idempotency_key: nil,
856
+ delta: nil,
857
+ version: nil,
858
+ version_epoch: nil,
859
+ max_attempts: 2,
860
+ attempt_timeout: nil,
861
+ timeout: nil,
862
+ &on_attempt_error
863
+ )
864
+ retry_broadcast(max_attempts, attempt_timeout, timeout, on_attempt_error) do
865
+ Requests.broadcast(
866
+ channels,
867
+ data,
868
+ b64data,
869
+ skip_history,
870
+ tags,
871
+ idempotency_key,
872
+ delta,
873
+ version,
874
+ version_epoch
875
+ )
876
+ end
877
+ end
878
+
879
+ # Subscribes active sessions of a user to a channel
880
+ # (server-side subscription). It does not create a streaming subscription
881
+ # for the caller.
882
+ #
883
+ # @param channel [String, nil] The name of the channel to subscribe to. Required.
884
+ # @param user [String, nil] The ID of the user to subscribe. Required, unless all_users is
885
+ # used in Centrifugo PRO.
886
+ # @param expire_at [Integer, nil] The Unix time in seconds when the subscription expires.
887
+ # @param info [Object, nil] Custom channel info attached to the subscription, used in
888
+ # presence and join/leave messages.
889
+ # @param b64info [String, nil] Info as base64, for binary. Centrifugo decodes it.
890
+ # @param client [String, nil] Limits the call to the connection with this client ID. user is
891
+ # still required.
892
+ # @param data [Object, nil] Custom subscription data sent to the client in the Subscribe
893
+ # push.
894
+ # @param b64data [String, nil] Data as base64, for binary. Centrifugo decodes it.
895
+ # @param recover_since [StreamPosition, Hash, nil] The stream position to recover publications from.
896
+ # @param override [SubscribeOptionOverride, Hash, nil] Dynamically overrides some channel options set in the
897
+ # Centrifugo configuration.
898
+ # @param session [String, nil] Limits the call to the connection with this session ID. user
899
+ # is still required.
900
+ # @param label_filter [FilterNode, Hash, nil] Restricts the call to clients whose labels match this
901
+ # filter. Centrifugo PRO only.
902
+ # @param all_users [Boolean, nil] When user is empty, targets every connection on every node
903
+ # instead of the anonymous-only bucket. No effect when user is non-empty.
904
+ # Without label_filter it acts on every connection. Centrifugo PRO only.
905
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
906
+ # @return [SubscribeResult]
907
+ # @raise [Error]
908
+ def subscribe(
909
+ channel:,
910
+ user: nil,
911
+ expire_at: nil,
912
+ info: nil,
913
+ b64info: nil,
914
+ client: nil,
915
+ data: nil,
916
+ b64data: nil,
917
+ recover_since: nil,
918
+ override: nil,
919
+ session: nil,
920
+ label_filter: nil,
921
+ all_users: nil,
922
+ timeout: nil
923
+ )
924
+ invoke("subscribe", SubscribeResult, timeout) do
925
+ Requests.subscribe(
926
+ channel,
927
+ user,
928
+ expire_at,
929
+ info,
930
+ b64info,
931
+ client,
932
+ data,
933
+ b64data,
934
+ recover_since,
935
+ override,
936
+ session,
937
+ label_filter,
938
+ all_users
939
+ )
940
+ end
941
+ end
942
+
943
+ # Unsubscribes a user from a channel.
944
+ #
945
+ # @param channel [String, nil] The name of the channel to unsubscribe from. Required.
946
+ # @param user [String, nil] The ID of the user to unsubscribe. Required, unless all_users
947
+ # is used in Centrifugo PRO.
948
+ # @param client [String, nil] Limits the call to the connection with this client ID. user is
949
+ # still required.
950
+ # @param session [String, nil] Limits the call to the connection with this session ID. user
951
+ # is still required.
952
+ # @param label_filter [FilterNode, Hash, nil] Restricts the call to clients whose labels match this
953
+ # filter. Centrifugo PRO only.
954
+ # @param all_users [Boolean, nil] Works as SubscribeRequest.all_users. Centrifugo PRO only.
955
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
956
+ # @return [UnsubscribeResult]
957
+ # @raise [Error]
958
+ def unsubscribe(
959
+ channel:,
960
+ user: nil,
961
+ client: nil,
962
+ session: nil,
963
+ label_filter: nil,
964
+ all_users: nil,
965
+ timeout: nil
966
+ )
967
+ invoke("unsubscribe", UnsubscribeResult, timeout) do
968
+ Requests.unsubscribe(
969
+ channel,
970
+ user,
971
+ client,
972
+ session,
973
+ label_filter,
974
+ all_users
975
+ )
976
+ end
977
+ end
978
+
979
+ # Disconnects a user's connections.
980
+ #
981
+ # @param user [String, nil] The ID of the user to disconnect. Required, unless all_users is
982
+ # used in Centrifugo PRO.
983
+ # @param disconnect [Disconnect, Hash, nil] A custom disconnect code and reason. If not set, clients
984
+ # are disconnected with a force no-reconnect disconnect.
985
+ # @param client [String, nil] Limits the call to the connection with this client ID. user is
986
+ # still required.
987
+ # @param whitelist [Array<String>] A list of client IDs to keep connected.
988
+ # @param session [String, nil] Limits the call to the connection with this session ID. user
989
+ # is still required.
990
+ # @param label_filter [FilterNode, Hash, nil] Restricts the call to clients whose labels match this
991
+ # filter. Centrifugo PRO only.
992
+ # @param all_users [Boolean, nil] Works as SubscribeRequest.all_users. Centrifugo PRO only.
993
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
994
+ # @return [DisconnectResult]
995
+ # @raise [Error]
996
+ def disconnect(
997
+ user: nil,
998
+ disconnect: nil,
999
+ client: nil,
1000
+ whitelist: nil,
1001
+ session: nil,
1002
+ label_filter: nil,
1003
+ all_users: nil,
1004
+ timeout: nil
1005
+ )
1006
+ invoke("disconnect", DisconnectResult, timeout) do
1007
+ Requests.disconnect(
1008
+ user,
1009
+ disconnect,
1010
+ client,
1011
+ whitelist,
1012
+ session,
1013
+ label_filter,
1014
+ all_users
1015
+ )
1016
+ end
1017
+ end
1018
+
1019
+ # Returns the online presence of a channel: all clients
1020
+ # currently subscribed to it. Presence must be enabled for the channel.
1021
+ #
1022
+ # @param channel [String, nil] The name of the channel. Required.
1023
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1024
+ # @return [PresenceResult]
1025
+ # @raise [Error]
1026
+ def presence(channel:, timeout: nil)
1027
+ invoke("presence", PresenceResult, timeout) do
1028
+ Requests.presence(channel)
1029
+ end
1030
+ end
1031
+
1032
+ # Returns short presence information of a channel: the
1033
+ # number of clients and of unique users. Presence must be enabled for the
1034
+ # channel.
1035
+ #
1036
+ # @param channel [String, nil] The name of the channel. Required.
1037
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1038
+ # @return [PresenceStatsResult]
1039
+ # @raise [Error]
1040
+ def presence_stats(channel:, timeout: nil)
1041
+ invoke("presence_stats", PresenceStatsResult, timeout) do
1042
+ Requests.presence_stats(channel)
1043
+ end
1044
+ end
1045
+
1046
+ # Returns publications from the history of a channel.
1047
+ # History must be enabled for the channel.
1048
+ #
1049
+ # @param channel [String, nil] The name of the channel. Required.
1050
+ # @param limit [Integer, nil] The maximum number of publications to return; -1 returns all
1051
+ # the channel keeps. If not set, only the current stream position is
1052
+ # returned, without publications.
1053
+ # @param since [StreamPosition, Hash, nil] Returns publications after this stream position.
1054
+ # @param reverse [Boolean, nil] Iterates in reverse order, from latest to earliest.
1055
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1056
+ # @return [HistoryResult]
1057
+ # @raise [Error]
1058
+ def history(
1059
+ channel:,
1060
+ limit: nil,
1061
+ since: nil,
1062
+ reverse: nil,
1063
+ timeout: nil
1064
+ )
1065
+ invoke("history", HistoryResult, timeout) do
1066
+ Requests.history(channel, limit, since, reverse)
1067
+ end
1068
+ end
1069
+
1070
+ # Every publication of a channel's history, oldest first, a page of limit
1071
+ # at a time: from since when it is set, from the start of what the channel
1072
+ # keeps otherwise. limit is the page size, so it must be 1 or more, and
1073
+ # reverse is refused, before anything is sent: since reads forward only.
1074
+ # The iteration ends after a page shorter than limit. A publication made
1075
+ # while iterating may or may not be seen. An epoch which changed since a
1076
+ # page was read - the history was lost, with a Redis restart say - raises
1077
+ # UnrecoverablePositionError: reading again from the start is the only way
1078
+ # on. Each publication comes with its position, as a HistoryItem.
1079
+ #
1080
+ # Returns an Enumerator, or with a block, yields each item and returns nil. A
1081
+ # page is read when the iteration reaches it, and leaving the iteration early
1082
+ # reads no further page. An error raises from the iteration, after the items
1083
+ # before it. The iteration lasts as long as the caller's loop: page_timeout
1084
+ # bounds each page's request, as attempt_timeout bounds a retry's attempt.
1085
+ #
1086
+ # @param channel [String, nil] The name of the channel. Required.
1087
+ # @param limit [Integer, nil] The maximum number of publications to return; -1 returns all
1088
+ # the channel keeps. If not set, only the current stream position is
1089
+ # returned, without publications.
1090
+ # @param since [StreamPosition, Hash, nil] Returns publications after this stream position.
1091
+ # @param reverse [Boolean, nil] Iterates in reverse order, from latest to earliest.
1092
+ # @param page_timeout [Numeric, nil] Seconds bounding each page's request, replacing
1093
+ # request_timeout for it, longer or shorter: request_timeout when nil. Zero is refused.
1094
+ # @yieldparam item [HistoryItem]
1095
+ # @return [Enumerator<HistoryItem>, nil]
1096
+ # @raise [Error]
1097
+ def history_all(
1098
+ channel:,
1099
+ limit: nil,
1100
+ since: nil,
1101
+ reverse: nil,
1102
+ page_timeout: nil,
1103
+ &block
1104
+ )
1105
+ pages("history", page_timeout, block) do
1106
+ Requests.history(channel, limit, since, reverse)
1107
+ end
1108
+ end
1109
+
1110
+ # Removes publications from the history of a channel.
1111
+ # The current top stream position is kept, so clients do not get
1112
+ # disconnected because of insufficient state.
1113
+ #
1114
+ # @param channel [String, nil] The name of the channel. Required.
1115
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1116
+ # @return [HistoryRemoveResult]
1117
+ # @raise [Error]
1118
+ def history_remove(channel:, timeout: nil)
1119
+ invoke("history_remove", HistoryRemoveResult, timeout) do
1120
+ Requests.history_remove(channel)
1121
+ end
1122
+ end
1123
+
1124
+ # Returns information about the running Centrifugo nodes.
1125
+ #
1126
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1127
+ # @return [InfoResult]
1128
+ # @raise [Error]
1129
+ def info(timeout: nil)
1130
+ invoke("info", InfoResult, timeout) do
1131
+ Requests.info
1132
+ end
1133
+ end
1134
+
1135
+ # Refreshes a user's connections, mostly useful with
1136
+ # unidirectional transports. Without expire_at the connections become
1137
+ # non-expiring.
1138
+ #
1139
+ # @param user [String, nil] The ID of the user to refresh. Required, unless all_users is
1140
+ # used in Centrifugo PRO.
1141
+ # @param client [String, nil] Limits the call to the connection with this client ID. user is
1142
+ # still required.
1143
+ # @param expired [Boolean, nil] Marks the connections as expired and closes them with an
1144
+ # expired disconnect reason.
1145
+ # @param expire_at [Integer, nil] The Unix time in seconds when the connections expire.
1146
+ # @param info [Object, nil] Attaches or replaces the connection info.
1147
+ # @param session [String, nil] Limits the call to the connection with this session ID. user
1148
+ # is still required.
1149
+ # @param label_filter [FilterNode, Hash, nil] Restricts the call to clients whose labels match this
1150
+ # filter. Centrifugo PRO only.
1151
+ # @param all_users [Boolean, nil] Works as SubscribeRequest.all_users. Centrifugo PRO only.
1152
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1153
+ # @return [RefreshResult]
1154
+ # @raise [Error]
1155
+ def refresh(
1156
+ user: nil,
1157
+ client: nil,
1158
+ expired: nil,
1159
+ expire_at: nil,
1160
+ info: nil,
1161
+ session: nil,
1162
+ label_filter: nil,
1163
+ all_users: nil,
1164
+ timeout: nil
1165
+ )
1166
+ invoke("refresh", RefreshResult, timeout) do
1167
+ Requests.refresh(
1168
+ user,
1169
+ client,
1170
+ expired,
1171
+ expire_at,
1172
+ info,
1173
+ session,
1174
+ label_filter,
1175
+ all_users
1176
+ )
1177
+ end
1178
+ end
1179
+
1180
+ # Returns active channels (with one or more subscribers).
1181
+ # It can be heavy on large deployments: there is no pagination.
1182
+ #
1183
+ # @param pattern [String, nil] Filters channels by name, using gobwas/glob syntax.
1184
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1185
+ # @return [ChannelsResult]
1186
+ # @raise [Error]
1187
+ def channels(pattern: nil, timeout: nil)
1188
+ invoke("channels", ChannelsResult, timeout) do
1189
+ Requests.channels(pattern)
1190
+ end
1191
+ end
1192
+
1193
+ # Returns information about active connections, without
1194
+ # the need to enable presence. At least one of user, expression or
1195
+ # label_filter must be set. Centrifugo PRO only.
1196
+ #
1197
+ # @param user [String, nil] Returns only the connections of this user ID.
1198
+ # @param expression [String, nil] A CEL expression to filter connections.
1199
+ # @param label_filter [FilterNode, Hash, nil] Restricts the listing to clients whose labels match this
1200
+ # filter. Centrifugo PRO only.
1201
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1202
+ # @return [ConnectionsResult]
1203
+ # @raise [Error]
1204
+ def connections(
1205
+ user: nil,
1206
+ expression: nil,
1207
+ label_filter: nil,
1208
+ timeout: nil
1209
+ )
1210
+ invoke("connections", ConnectionsResult, timeout) do
1211
+ Requests.connections(user, expression, label_filter)
1212
+ end
1213
+ end
1214
+
1215
+ # Marks users as active and online now, and sets
1216
+ # their state when one is given. Centrifugo PRO only.
1217
+ #
1218
+ # @param users [Array<String>] The list of user IDs to update the status for. Required.
1219
+ # @param state [String, nil] An optional custom state to store in the user status. It can
1220
+ # be restricted by the user_status.state_regex option.
1221
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1222
+ # @return [UpdateUserStatusResult]
1223
+ # @raise [Error]
1224
+ def update_user_status(users:, state: nil, timeout: nil)
1225
+ invoke("update_user_status", UpdateUserStatusResult, timeout) do
1226
+ Requests.update_user_status(users, state)
1227
+ end
1228
+ end
1229
+
1230
+ # Returns the status of users. Centrifugo PRO only.
1231
+ #
1232
+ # @param users [Array<String>] The list of user IDs to get the status for. Required.
1233
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1234
+ # @return [GetUserStatusResult]
1235
+ # @raise [Error]
1236
+ def get_user_status(users:, timeout: nil)
1237
+ invoke("get_user_status", GetUserStatusResult, timeout) do
1238
+ Requests.get_user_status(users)
1239
+ end
1240
+ end
1241
+
1242
+ # Deletes the status of users. Centrifugo PRO only.
1243
+ #
1244
+ # @param users [Array<String>] The list of user IDs to delete the status for. Required.
1245
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1246
+ # @return [DeleteUserStatusResult]
1247
+ # @raise [Error]
1248
+ def delete_user_status(users:, timeout: nil)
1249
+ invoke("delete_user_status", DeleteUserStatusResult, timeout) do
1250
+ Requests.delete_user_status(users)
1251
+ end
1252
+ end
1253
+
1254
+ # Blocks a user: the user is disconnected and can not
1255
+ # connect again until unblocked or the block expires. Centrifugo PRO only.
1256
+ #
1257
+ # @param expire_at [Integer, nil] The Unix time in seconds when the block expires. Optional,
1258
+ # but a reasonably small value is recommended to keep the set of blocked
1259
+ # users small.
1260
+ # @param user [String, nil] The ID of the user to block. Required.
1261
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1262
+ # @return [BlockUserResult]
1263
+ # @raise [Error]
1264
+ def block_user(user:, expire_at: nil, timeout: nil)
1265
+ invoke("block_user", BlockUserResult, timeout) do
1266
+ Requests.block_user(expire_at, user)
1267
+ end
1268
+ end
1269
+
1270
+ # Unblocks a user. Centrifugo PRO only.
1271
+ #
1272
+ # @param user [String, nil] The ID of the user to unblock. Required.
1273
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1274
+ # @return [UnblockUserResult]
1275
+ # @raise [Error]
1276
+ def unblock_user(user:, timeout: nil)
1277
+ invoke("unblock_user", UnblockUserResult, timeout) do
1278
+ Requests.unblock_user(user)
1279
+ end
1280
+ end
1281
+
1282
+ # Revokes a token by its unique ID (jti claim of a JWT).
1283
+ # Clients using the token are disconnected shortly, and can not connect
1284
+ # with it again. Centrifugo PRO only.
1285
+ #
1286
+ # @param expire_at [Integer, nil] The Unix time in seconds when the revocation expires.
1287
+ # Optional, but a value matching the token expiration is recommended.
1288
+ # @param uid [String, nil] The unique ID of the token to revoke (jti claim). Required.
1289
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1290
+ # @return [RevokeTokenResult]
1291
+ # @raise [Error]
1292
+ def revoke_token(uid:, expire_at: nil, timeout: nil)
1293
+ invoke("revoke_token", RevokeTokenResult, timeout) do
1294
+ Requests.revoke_token(expire_at, uid)
1295
+ end
1296
+ end
1297
+
1298
+ # Revokes all tokens of a user issued before a
1299
+ # certain time (based on the iat claim of a JWT). Centrifugo PRO only.
1300
+ #
1301
+ # @param expire_at [Integer, nil] The Unix time in seconds when the invalidation expires.
1302
+ # Optional, but a value matching the token expiration is recommended.
1303
+ # @param user [String, nil] The ID of the user whose tokens to invalidate. Required. ""
1304
+ # invalidates the tokens of anonymous users.
1305
+ # @param issued_before [Integer, nil] The Unix time in seconds: tokens issued before it are
1306
+ # considered revoked. If not set, the current time is used.
1307
+ # @param channel [String, nil] Limits the invalidation to subscription tokens for this
1308
+ # channel.
1309
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1310
+ # @return [InvalidateUserTokensResult]
1311
+ # @raise [Error]
1312
+ def invalidate_user_tokens(
1313
+ user:,
1314
+ expire_at: nil,
1315
+ issued_before: nil,
1316
+ channel: nil,
1317
+ timeout: nil
1318
+ )
1319
+ invoke("invalidate_user_tokens", InvalidateUserTokensResult, timeout) do
1320
+ Requests.invalidate_user_tokens(expire_at, user, issued_before, channel)
1321
+ end
1322
+ end
1323
+
1324
+ # Registers a device for push notifications, or
1325
+ # updates a registered one. Centrifugo PRO only.
1326
+ #
1327
+ # @param id [String, nil] The device ID. Omit it on first registration: Centrifugo
1328
+ # generates one and returns it. Pass the stored value to update the
1329
+ # device.
1330
+ # @param provider [String, nil] The provider of the device token. Required. One of: fcm,
1331
+ # hms, apns, webpush.
1332
+ # @param token [String, nil] The push token of the device. For webpush, it is the browser
1333
+ # PushSubscription serialized as a JSON string. Required.
1334
+ # @param platform [String, nil] The device platform. Required. One of: ios, android, web.
1335
+ # @param user [String, nil] The user associated with the device.
1336
+ # @param meta [Hash{String => String}] Additional custom metadata of the device.
1337
+ # @param topics [Array<String>] The full list of the device's topic subscriptions, replacing
1338
+ # the previous one. The user's topics are attached automatically.
1339
+ # @param timezone [String, nil] The IANA time zone of the device user, for example
1340
+ # Europe/Nicosia.
1341
+ # @param locale [String, nil] The locale of the device user as an IETF BCP 47 language
1342
+ # tag, for example en-US.
1343
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1344
+ # @return [DeviceRegisterResult]
1345
+ # @raise [Error]
1346
+ def device_register(
1347
+ provider:,
1348
+ token:,
1349
+ platform:,
1350
+ id: nil,
1351
+ user: nil,
1352
+ meta: nil,
1353
+ topics: nil,
1354
+ timezone: nil,
1355
+ locale: nil,
1356
+ timeout: nil
1357
+ )
1358
+ invoke("device_register", DeviceRegisterResult, timeout) do
1359
+ Requests.device_register(
1360
+ id,
1361
+ provider,
1362
+ token,
1363
+ platform,
1364
+ user,
1365
+ meta,
1366
+ topics,
1367
+ timezone,
1368
+ locale
1369
+ )
1370
+ end
1371
+ end
1372
+
1373
+ # Updates registered devices, selected by ids and/or
1374
+ # users. Centrifugo PRO only.
1375
+ #
1376
+ # @param ids [Array<String>] Selects devices by ID.
1377
+ # @param users [Array<String>] Selects devices by user.
1378
+ # @param user_update [DeviceUserUpdate, Hash, nil] Changes the user ID of the devices. It does not re-sync
1379
+ # user-bound topics; use DeviceRegisterRequest to assign a device to
1380
+ # another user.
1381
+ # @param meta_update [DeviceMetaUpdate, Hash, nil] Updates the device meta.
1382
+ # @param topics_update [DeviceTopicsUpdate, Hash, nil] Updates the device topics.
1383
+ # @param timezone_update [DeviceTimezoneUpdate, Hash, nil] Updates the device timezone.
1384
+ # @param locale_update [DeviceLocaleUpdate, Hash, nil] Updates the device locale.
1385
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1386
+ # @return [DeviceUpdateResult]
1387
+ # @raise [Error]
1388
+ def device_update(
1389
+ ids: nil,
1390
+ users: nil,
1391
+ user_update: nil,
1392
+ meta_update: nil,
1393
+ topics_update: nil,
1394
+ timezone_update: nil,
1395
+ locale_update: nil,
1396
+ timeout: nil
1397
+ )
1398
+ invoke("device_update", DeviceUpdateResult, timeout) do
1399
+ Requests.device_update(
1400
+ ids,
1401
+ users,
1402
+ user_update,
1403
+ meta_update,
1404
+ topics_update,
1405
+ timezone_update,
1406
+ locale_update
1407
+ )
1408
+ end
1409
+ end
1410
+
1411
+ # Removes devices, selected by ids and/or users.
1412
+ # Centrifugo PRO only.
1413
+ #
1414
+ # @param ids [Array<String>] Selects devices to remove by ID.
1415
+ # @param users [Array<String>] Selects devices to remove by user.
1416
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1417
+ # @return [DeviceRemoveResult]
1418
+ # @raise [Error]
1419
+ def device_remove(ids: nil, users: nil, timeout: nil)
1420
+ invoke("device_remove", DeviceRemoveResult, timeout) do
1421
+ Requests.device_remove(ids, users)
1422
+ end
1423
+ end
1424
+
1425
+ # Returns a paginated list of registered devices.
1426
+ # Centrifugo PRO only.
1427
+ #
1428
+ # @param filter [DeviceFilter, Hash, nil] Selects the devices to list: all of them when unset.
1429
+ # @param include_total_count [Boolean, nil] Includes the total count for the filter in the
1430
+ # result.
1431
+ # @param include_meta [Boolean, nil] Includes meta of each device.
1432
+ # @param include_topics [Boolean, nil] Includes topics of each device.
1433
+ # @param include_webpush_keys [Boolean, nil] Includes webpush_keys of each device (webpush
1434
+ # only).
1435
+ # @param cursor [String, nil] The pagination cursor: next_cursor of the previous page,
1436
+ # empty for the first page.
1437
+ # @param limit [Integer, nil] The maximum number of devices to return.
1438
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1439
+ # @return [DeviceListResult]
1440
+ # @raise [Error]
1441
+ def device_list(
1442
+ filter: nil,
1443
+ include_total_count: nil,
1444
+ include_meta: nil,
1445
+ include_topics: nil,
1446
+ include_webpush_keys: nil,
1447
+ cursor: nil,
1448
+ limit: nil,
1449
+ timeout: nil
1450
+ )
1451
+ invoke("device_list", DeviceListResult, timeout) do
1452
+ Requests.device_list(
1453
+ filter,
1454
+ include_total_count,
1455
+ include_meta,
1456
+ include_topics,
1457
+ include_webpush_keys,
1458
+ cursor,
1459
+ limit
1460
+ )
1461
+ end
1462
+ end
1463
+
1464
+ # Every device the request selects, a page at a time: limit is the page
1465
+ # size, the server's default when unset. A device registered or removed
1466
+ # while iterating may or may not be seen.
1467
+ #
1468
+ # Returns an Enumerator, or with a block, yields each item and returns nil. A
1469
+ # page is read when the iteration reaches it, and leaving the iteration early
1470
+ # reads no further page. An error raises from the iteration, after the items
1471
+ # before it. The iteration lasts as long as the caller's loop: page_timeout
1472
+ # bounds each page's request, as attempt_timeout bounds a retry's attempt.
1473
+ #
1474
+ # Centrifugo PRO only.
1475
+ #
1476
+ # @param filter [DeviceFilter, Hash, nil] Selects the devices to list: all of them when unset.
1477
+ # @param include_total_count [Boolean, nil] Includes the total count for the filter in the
1478
+ # result.
1479
+ # @param include_meta [Boolean, nil] Includes meta of each device.
1480
+ # @param include_topics [Boolean, nil] Includes topics of each device.
1481
+ # @param include_webpush_keys [Boolean, nil] Includes webpush_keys of each device (webpush
1482
+ # only).
1483
+ # @param cursor [String, nil] The pagination cursor: next_cursor of the previous page,
1484
+ # empty for the first page.
1485
+ # @param limit [Integer, nil] The maximum number of devices to return.
1486
+ # @param page_timeout [Numeric, nil] Seconds bounding each page's request, replacing
1487
+ # request_timeout for it, longer or shorter: request_timeout when nil. Zero is refused.
1488
+ # @yieldparam item [Device]
1489
+ # @return [Enumerator<Device>, nil]
1490
+ # @raise [Error]
1491
+ def device_list_all(
1492
+ filter: nil,
1493
+ include_total_count: nil,
1494
+ include_meta: nil,
1495
+ include_topics: nil,
1496
+ include_webpush_keys: nil,
1497
+ cursor: nil,
1498
+ limit: nil,
1499
+ page_timeout: nil,
1500
+ &block
1501
+ )
1502
+ pages("device_list", page_timeout, block) do
1503
+ Requests.device_list(
1504
+ filter,
1505
+ include_total_count,
1506
+ include_meta,
1507
+ include_topics,
1508
+ include_webpush_keys,
1509
+ cursor,
1510
+ limit
1511
+ )
1512
+ end
1513
+ end
1514
+
1515
+ # Returns a paginated list of device topic
1516
+ # subscriptions. Centrifugo PRO only.
1517
+ #
1518
+ # @param filter [DeviceTopicFilter, Hash, nil] Selects the device topics to list.
1519
+ # @param include_total_count [Boolean, nil] Includes the total count for the filter in the
1520
+ # result.
1521
+ # @param include_device [Boolean, nil] Includes the Device of each item.
1522
+ # @param cursor [String, nil] The pagination cursor: next_cursor of the previous page,
1523
+ # empty for the first page.
1524
+ # @param limit [Integer, nil] The maximum number of items to return.
1525
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1526
+ # @return [DeviceTopicListResult]
1527
+ # @raise [Error]
1528
+ def device_topic_list(
1529
+ filter: nil,
1530
+ include_total_count: nil,
1531
+ include_device: nil,
1532
+ cursor: nil,
1533
+ limit: nil,
1534
+ timeout: nil
1535
+ )
1536
+ invoke("device_topic_list", DeviceTopicListResult, timeout) do
1537
+ Requests.device_topic_list(
1538
+ filter,
1539
+ include_total_count,
1540
+ include_device,
1541
+ cursor,
1542
+ limit
1543
+ )
1544
+ end
1545
+ end
1546
+
1547
+ # Every device topic the request selects, a page at a time, as
1548
+ # device_list_all reads devices.
1549
+ #
1550
+ # Returns an Enumerator, or with a block, yields each item and returns nil. A
1551
+ # page is read when the iteration reaches it, and leaving the iteration early
1552
+ # reads no further page. An error raises from the iteration, after the items
1553
+ # before it. The iteration lasts as long as the caller's loop: page_timeout
1554
+ # bounds each page's request, as attempt_timeout bounds a retry's attempt.
1555
+ #
1556
+ # Centrifugo PRO only.
1557
+ #
1558
+ # @param filter [DeviceTopicFilter, Hash, nil] Selects the device topics to list.
1559
+ # @param include_total_count [Boolean, nil] Includes the total count for the filter in the
1560
+ # result.
1561
+ # @param include_device [Boolean, nil] Includes the Device of each item.
1562
+ # @param cursor [String, nil] The pagination cursor: next_cursor of the previous page,
1563
+ # empty for the first page.
1564
+ # @param limit [Integer, nil] The maximum number of items to return.
1565
+ # @param page_timeout [Numeric, nil] Seconds bounding each page's request, replacing
1566
+ # request_timeout for it, longer or shorter: request_timeout when nil. Zero is refused.
1567
+ # @yieldparam item [DeviceTopic]
1568
+ # @return [Enumerator<DeviceTopic>, nil]
1569
+ # @raise [Error]
1570
+ def device_topic_list_all(
1571
+ filter: nil,
1572
+ include_total_count: nil,
1573
+ include_device: nil,
1574
+ cursor: nil,
1575
+ limit: nil,
1576
+ page_timeout: nil,
1577
+ &block
1578
+ )
1579
+ pages("device_topic_list", page_timeout, block) do
1580
+ Requests.device_topic_list(
1581
+ filter,
1582
+ include_total_count,
1583
+ include_device,
1584
+ cursor,
1585
+ limit
1586
+ )
1587
+ end
1588
+ end
1589
+
1590
+ # Changes the topics of a device. The device topic
1591
+ # list is what decides who gets a push sent to a topic.
1592
+ # Centrifugo PRO only.
1593
+ #
1594
+ # @param device_id [String, nil] The ID of the device. Required.
1595
+ # @param op [String, nil] The operation. Required. One of: add, remove, set.
1596
+ # @param topics [Array<String>] The topics for the operation.
1597
+ # @param user [String, nil] An optional ownership guard: the update is applied only if the
1598
+ # device currently belongs to this user. Otherwise the call fails with a
1599
+ # conflict error (or not found if there is no such device).
1600
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1601
+ # @return [DeviceTopicUpdateResult]
1602
+ # @raise [Error]
1603
+ def device_topic_update(
1604
+ device_id:,
1605
+ op:,
1606
+ topics: nil,
1607
+ user: nil,
1608
+ timeout: nil
1609
+ )
1610
+ invoke("device_topic_update", DeviceTopicUpdateResult, timeout) do
1611
+ Requests.device_topic_update(device_id, op, topics, user)
1612
+ end
1613
+ end
1614
+
1615
+ # Returns a paginated list of user topic
1616
+ # subscriptions. Centrifugo PRO only.
1617
+ #
1618
+ # @param filter [UserTopicFilter, Hash, nil] Selects the user topics to list.
1619
+ # @param include_total_count [Boolean, nil] Includes the total count for the filter in the
1620
+ # result.
1621
+ # @param cursor [String, nil] The pagination cursor: next_cursor of the previous page,
1622
+ # empty for the first page.
1623
+ # @param limit [Integer, nil] The maximum number of items to return.
1624
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1625
+ # @return [UserTopicListResult]
1626
+ # @raise [Error]
1627
+ def user_topic_list(
1628
+ filter: nil,
1629
+ include_total_count: nil,
1630
+ cursor: nil,
1631
+ limit: nil,
1632
+ timeout: nil
1633
+ )
1634
+ invoke("user_topic_list", UserTopicListResult, timeout) do
1635
+ Requests.user_topic_list(filter, include_total_count, cursor, limit)
1636
+ end
1637
+ end
1638
+
1639
+ # Every user topic the request selects, a page at a time, as
1640
+ # device_list_all reads devices.
1641
+ #
1642
+ # Returns an Enumerator, or with a block, yields each item and returns nil. A
1643
+ # page is read when the iteration reaches it, and leaving the iteration early
1644
+ # reads no further page. An error raises from the iteration, after the items
1645
+ # before it. The iteration lasts as long as the caller's loop: page_timeout
1646
+ # bounds each page's request, as attempt_timeout bounds a retry's attempt.
1647
+ #
1648
+ # Centrifugo PRO only.
1649
+ #
1650
+ # @param filter [UserTopicFilter, Hash, nil] Selects the user topics to list.
1651
+ # @param include_total_count [Boolean, nil] Includes the total count for the filter in the
1652
+ # result.
1653
+ # @param cursor [String, nil] The pagination cursor: next_cursor of the previous page,
1654
+ # empty for the first page.
1655
+ # @param limit [Integer, nil] The maximum number of items to return.
1656
+ # @param page_timeout [Numeric, nil] Seconds bounding each page's request, replacing
1657
+ # request_timeout for it, longer or shorter: request_timeout when nil. Zero is refused.
1658
+ # @yieldparam item [UserTopic]
1659
+ # @return [Enumerator<UserTopic>, nil]
1660
+ # @raise [Error]
1661
+ def user_topic_list_all(
1662
+ filter: nil,
1663
+ include_total_count: nil,
1664
+ cursor: nil,
1665
+ limit: nil,
1666
+ page_timeout: nil,
1667
+ &block
1668
+ )
1669
+ pages("user_topic_list", page_timeout, block) do
1670
+ Requests.user_topic_list(filter, include_total_count, cursor, limit)
1671
+ end
1672
+ end
1673
+
1674
+ # Changes the topics of a user. The change is also
1675
+ # applied to the user's registered devices. Centrifugo PRO only.
1676
+ #
1677
+ # @param user [String, nil] The user ID. Required. "" updates the global binding, which every
1678
+ # device - anonymous ones included - gets on its next device_register.
1679
+ # @param op [String, nil] The operation. Required. One of: add, remove, set.
1680
+ # @param topics [Array<String>] The topics for the operation.
1681
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1682
+ # @return [UserTopicUpdateResult]
1683
+ # @raise [Error]
1684
+ def user_topic_update(
1685
+ user:,
1686
+ op:,
1687
+ topics: nil,
1688
+ timeout: nil
1689
+ )
1690
+ invoke("user_topic_update", UserTopicUpdateResult, timeout) do
1691
+ Requests.user_topic_update(user, op, topics)
1692
+ end
1693
+ end
1694
+
1695
+ # Sends a push notification. The request is
1696
+ # queued and sent to the provider by Centrifugo workers.
1697
+ # Centrifugo PRO only.
1698
+ #
1699
+ # @param recipient [PushRecipient, Hash, nil] Who receives the notification. Required.
1700
+ # @param notification [PushNotification, Hash, nil] The notification to send. Required.
1701
+ # @param uid [String, nil] A unique identifier of the request, can be used to cancel the
1702
+ # push. UUID v4 is recommended; different requests must use different
1703
+ # uids.
1704
+ # @param send_at [Integer, nil] The Unix time in seconds when to send the notification. If
1705
+ # not set, the notification is sent immediately.
1706
+ # @param optimize_for_reliability [Boolean, nil] Makes processing heavier, but tolerates edge
1707
+ # cases, like not losing inflight pushes when the queue is briefly
1708
+ # unavailable.
1709
+ # @param limit_strategy [PushLimitStrategy, Hash, nil] Sets time constraints and rate limits. Only applies
1710
+ # with a filter recipient; devices are then processed one by one
1711
+ # instead of in batches. Needs notification.expire_at: a push the limits
1712
+ # hold back is not tried forever.
1713
+ # @param analytics_uid [String, nil] The identifier for push notification analytics. If
1714
+ # not set, uid is used.
1715
+ # @param localizations [Hash{String => PushLocalization, Hash}] Optional per language/locale localizations. Setting
1716
+ # them enables templating.
1717
+ # @param use_templating [Boolean, nil] Enables templating of the notification. Only works
1718
+ # with a filter recipient.
1719
+ # @param use_meta [Boolean, nil] Additionally loads device meta while sending, making it
1720
+ # available in templating.
1721
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1722
+ # @return [SendPushNotificationResult]
1723
+ # @raise [Error]
1724
+ def send_push_notification(
1725
+ recipient:,
1726
+ notification:,
1727
+ uid: nil,
1728
+ send_at: nil,
1729
+ optimize_for_reliability: nil,
1730
+ limit_strategy: nil,
1731
+ analytics_uid: nil,
1732
+ localizations: nil,
1733
+ use_templating: nil,
1734
+ use_meta: nil,
1735
+ timeout: nil
1736
+ )
1737
+ invoke("send_push_notification", SendPushNotificationResult, timeout) do
1738
+ Requests.send_push_notification(
1739
+ recipient,
1740
+ notification,
1741
+ uid,
1742
+ send_at,
1743
+ optimize_for_reliability,
1744
+ limit_strategy,
1745
+ analytics_uid,
1746
+ localizations,
1747
+ use_templating,
1748
+ use_meta
1749
+ )
1750
+ end
1751
+ end
1752
+
1753
+ # Saves the delivery or interaction status of a
1754
+ # push notification to analytics. Experimental. Centrifugo PRO only.
1755
+ #
1756
+ # @param analytics_uid [String, nil] The analytics_uid of the push notification (as in
1757
+ # SendPushNotificationRequest). Required.
1758
+ # @param status [String, nil] The status of the push notification. Required. One of:
1759
+ # delivered, interacted.
1760
+ # @param device_id [String, nil] The Centrifugo device ID. Required.
1761
+ # @param msg_id [String, nil] The message ID issued by the provider.
1762
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1763
+ # @return [UpdatePushStatusResult]
1764
+ # @raise [Error]
1765
+ def update_push_status(
1766
+ analytics_uid:,
1767
+ status:,
1768
+ device_id:,
1769
+ msg_id: nil,
1770
+ timeout: nil
1771
+ )
1772
+ invoke("update_push_status", UpdatePushStatusResult, timeout) do
1773
+ Requests.update_push_status(analytics_uid, status, device_id, msg_id)
1774
+ end
1775
+ end
1776
+
1777
+ # Cancels a delayed push notification (sent with
1778
+ # send_at). Centrifugo PRO only.
1779
+ #
1780
+ # @param uid [String, nil] The uid of the push notification to cancel. Required.
1781
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1782
+ # @return [CancelPushResult]
1783
+ # @raise [Error]
1784
+ def cancel_push(uid:, timeout: nil)
1785
+ invoke("cancel_push", CancelPushResult, timeout) do
1786
+ Requests.cancel_push(uid)
1787
+ end
1788
+ end
1789
+
1790
+ # Publishes or updates a key in a map channel.
1791
+ #
1792
+ # @param channel [String, nil] The name of the map channel. Required.
1793
+ # @param key [String, nil] The entry key. Required.
1794
+ # @param data [Object, nil] The entry data. In the HTTP API it is any JSON value; over GRPC
1795
+ # it may be binary.
1796
+ # @param b64data [String, nil] Data as base64, for binary over the HTTP API. Centrifugo
1797
+ # decodes it.
1798
+ # @param stream_data [Object, nil] Currently not used by the server API.
1799
+ # @param b64stream_data [String, nil] Currently not used by the server API.
1800
+ # @param tags [Hash{String => String}] Key-value metadata attached to the publication.
1801
+ # @param idempotency_key [String, nil] Drops duplicate publications upon retries: a
1802
+ # publication with a key already used in the channel is not applied
1803
+ # again, and its result has the first one's position, with suppressed
1804
+ # set and suppress_reason "idempotency". It acts per channel; keys are
1805
+ # kept for 5 minutes by default. Every map broker - memory, Redis and
1806
+ # PostgreSQL - keeps keys.
1807
+ # @param delta [Boolean, nil] Enables delta compression for this publication.
1808
+ # @param version [Integer, nil] A per-key version: publications with a version not higher
1809
+ # than the key's current one are suppressed.
1810
+ # @param version_epoch [String, nil] Scopes version. A different epoch resets version
1811
+ # comparison.
1812
+ # @param score [Integer, nil] Currently not used by the server API.
1813
+ # @param key_mode [String, nil] Makes the publish conditional: if_new writes only if the key
1814
+ # does not exist, if_exists only if it exists. Empty always writes.
1815
+ # One of: if_new, if_exists.
1816
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1817
+ # @return [MapPublishResult]
1818
+ # @raise [Error]
1819
+ def map_publish(
1820
+ channel:,
1821
+ key:,
1822
+ data: nil,
1823
+ b64data: nil,
1824
+ stream_data: nil,
1825
+ b64stream_data: nil,
1826
+ tags: nil,
1827
+ idempotency_key: nil,
1828
+ delta: nil,
1829
+ version: nil,
1830
+ version_epoch: nil,
1831
+ score: nil,
1832
+ key_mode: nil,
1833
+ timeout: nil
1834
+ )
1835
+ invoke("map_publish", MapPublishResult, timeout) do
1836
+ Requests.map_publish(
1837
+ channel,
1838
+ key,
1839
+ data,
1840
+ b64data,
1841
+ stream_data,
1842
+ b64stream_data,
1843
+ tags,
1844
+ idempotency_key,
1845
+ delta,
1846
+ version,
1847
+ version_epoch,
1848
+ score,
1849
+ key_mode
1850
+ )
1851
+ end
1852
+ end
1853
+
1854
+ # Removes a key from a map channel.
1855
+ #
1856
+ # @param channel [String, nil] The name of the map channel. Required.
1857
+ # @param key [String, nil] The key to remove. Required.
1858
+ # @param idempotency_key [String, nil] Drops duplicate removals upon retries, as it does for
1859
+ # MapPublishRequest: a removal with a key already used in the channel is
1860
+ # not applied again, and its result is suppressed with suppress_reason
1861
+ # "idempotency". Keys are kept for 5 minutes by default.
1862
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1863
+ # @return [MapRemoveResult]
1864
+ # @raise [Error]
1865
+ def map_remove(
1866
+ channel:,
1867
+ key:,
1868
+ idempotency_key: nil,
1869
+ timeout: nil
1870
+ )
1871
+ invoke("map_remove", MapRemoveResult, timeout) do
1872
+ Requests.map_remove(channel, key, idempotency_key)
1873
+ end
1874
+ end
1875
+
1876
+ # Reads the current state of a map channel, with
1877
+ # optional pagination.
1878
+ #
1879
+ # @param channel [String, nil] The name of the map channel. Required.
1880
+ # @param cursor [String, nil] The pagination cursor from the previous page. Empty starts
1881
+ # from the beginning.
1882
+ # @param limit [Integer, nil] The maximum number of entries per page: -1 means no limit, 0
1883
+ # returns only the stream position. Page sizes may exceed it with the
1884
+ # Redis map broker.
1885
+ # @param key [String, nil] Reads a single entry by exact key. cursor and limit are ignored
1886
+ # when it is set.
1887
+ # @param asc [Boolean, nil] Sorts ordered state by score ascending instead of descending.
1888
+ # Ignored for unordered channels.
1889
+ # @param revision_offset [Integer, nil] The offset of the position from a previous state
1890
+ # read, used with revision_epoch.
1891
+ # @param revision_epoch [String, nil] The epoch of the position from a previous state
1892
+ # read. If the epoch changed, the call fails with an unrecoverable
1893
+ # position error.
1894
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1895
+ # @return [MapReadStateResult]
1896
+ # @raise [Error]
1897
+ def map_read_state(
1898
+ channel:,
1899
+ cursor: nil,
1900
+ limit: nil,
1901
+ key: nil,
1902
+ asc: nil,
1903
+ revision_offset: nil,
1904
+ revision_epoch: nil,
1905
+ timeout: nil
1906
+ )
1907
+ invoke("map_read_state", MapReadStateResult, timeout) do
1908
+ Requests.map_read_state(
1909
+ channel,
1910
+ cursor,
1911
+ limit,
1912
+ key,
1913
+ asc,
1914
+ revision_offset,
1915
+ revision_epoch
1916
+ )
1917
+ end
1918
+ end
1919
+
1920
+ # Every entry of a map channel's state, a page at a time: limit is the page
1921
+ # size. Every page after the first is read at the first one's revision - its
1922
+ # position, as revision_offset and revision_epoch, unless the request sets
1923
+ # them - so that a state reset between pages raises
1924
+ # UnrecoverablePositionError instead of mixing two states: read again from
1925
+ # the first page then. Entries changed while iterating may be seen in either
1926
+ # version; for a consistent view, read the changes since the first page's
1927
+ # position with map_read_stream. Each entry comes with that position, as
1928
+ # a MapStateItem.
1929
+ #
1930
+ # Returns an Enumerator, or with a block, yields each item and returns nil. A
1931
+ # page is read when the iteration reaches it, and leaving the iteration early
1932
+ # reads no further page. An error raises from the iteration, after the items
1933
+ # before it. The iteration lasts as long as the caller's loop: page_timeout
1934
+ # bounds each page's request, as attempt_timeout bounds a retry's attempt.
1935
+ #
1936
+ # @param channel [String, nil] The name of the map channel. Required.
1937
+ # @param cursor [String, nil] The pagination cursor from the previous page. Empty starts
1938
+ # from the beginning.
1939
+ # @param limit [Integer, nil] The maximum number of entries per page: -1 means no limit, 0
1940
+ # returns only the stream position. Page sizes may exceed it with the
1941
+ # Redis map broker.
1942
+ # @param key [String, nil] Reads a single entry by exact key. cursor and limit are ignored
1943
+ # when it is set.
1944
+ # @param asc [Boolean, nil] Sorts ordered state by score ascending instead of descending.
1945
+ # Ignored for unordered channels.
1946
+ # @param revision_offset [Integer, nil] The offset of the position from a previous state
1947
+ # read, used with revision_epoch.
1948
+ # @param revision_epoch [String, nil] The epoch of the position from a previous state
1949
+ # read. If the epoch changed, the call fails with an unrecoverable
1950
+ # position error.
1951
+ # @param page_timeout [Numeric, nil] Seconds bounding each page's request, replacing
1952
+ # request_timeout for it, longer or shorter: request_timeout when nil. Zero is refused.
1953
+ # @yieldparam item [MapStateItem]
1954
+ # @return [Enumerator<MapStateItem>, nil]
1955
+ # @raise [Error]
1956
+ def map_read_state_all(
1957
+ channel:,
1958
+ cursor: nil,
1959
+ limit: nil,
1960
+ key: nil,
1961
+ asc: nil,
1962
+ revision_offset: nil,
1963
+ revision_epoch: nil,
1964
+ page_timeout: nil,
1965
+ &block
1966
+ )
1967
+ pages("map_read_state", page_timeout, block) do
1968
+ Requests.map_read_state(
1969
+ channel,
1970
+ cursor,
1971
+ limit,
1972
+ key,
1973
+ asc,
1974
+ revision_offset,
1975
+ revision_epoch
1976
+ )
1977
+ end
1978
+ end
1979
+
1980
+ # Reads the change stream of a map channel.
1981
+ #
1982
+ # @param channel [String, nil] The name of the map channel. Required.
1983
+ # @param since_offset [Integer, nil] Returns entries after this offset, used with
1984
+ # since_epoch.
1985
+ # @param since_epoch [String, nil] The epoch of the since position. It must match the
1986
+ # current stream epoch.
1987
+ # @param limit [Integer, nil] The maximum number of entries: -1 means no limit, 0 returns
1988
+ # only the stream position.
1989
+ # @param reverse [Boolean, nil] Returns entries newest first.
1990
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
1991
+ # @return [MapReadStreamResult]
1992
+ # @raise [Error]
1993
+ def map_read_stream(
1994
+ channel:,
1995
+ since_offset: nil,
1996
+ since_epoch: nil,
1997
+ limit: nil,
1998
+ reverse: nil,
1999
+ timeout: nil
2000
+ )
2001
+ invoke("map_read_stream", MapReadStreamResult, timeout) do
2002
+ Requests.map_read_stream(
2003
+ channel,
2004
+ since_offset,
2005
+ since_epoch,
2006
+ limit,
2007
+ reverse
2008
+ )
2009
+ end
2010
+ end
2011
+
2012
+ # Returns statistics about a map channel.
2013
+ #
2014
+ # @param channel [String, nil] The name of the map channel. Required.
2015
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
2016
+ # @return [MapStatsResult]
2017
+ # @raise [Error]
2018
+ def map_stats(channel:, timeout: nil)
2019
+ invoke("map_stats", MapStatsResult, timeout) do
2020
+ Requests.map_stats(channel)
2021
+ end
2022
+ end
2023
+
2024
+ # Removes all state and stream data of a map channel.
2025
+ #
2026
+ # @param channel [String, nil] The name of the map channel. Required.
2027
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
2028
+ # @return [MapClearResult]
2029
+ # @raise [Error]
2030
+ def map_clear(channel:, timeout: nil)
2031
+ invoke("map_clear", MapClearResult, timeout) do
2032
+ Requests.map_clear(channel)
2033
+ end
2034
+ end
2035
+
2036
+ # Pushes data for a key directly to clients of a
2037
+ # shared poll channel, without waiting for the next poll cycle. Requires
2038
+ # versioned mode and publish_enabled on the namespace.
2039
+ #
2040
+ # @param channel [String, nil] The name of the shared poll channel. Required.
2041
+ # @param key [String, nil] The item key. Required.
2042
+ # @param data [Object, nil] The item data, delivered to clients as is.
2043
+ # @param b64data [String, nil] Data as base64, for binary payloads. Centrifugo decodes it.
2044
+ # @param version [Integer, nil] The item version, must be >= 1. Required. A version not
2045
+ # higher than the current one within the same epoch is silently dropped.
2046
+ # @param epoch [String, nil] The channel-level publisher epoch. A change resets per-key
2047
+ # versions and unsubscribes current subscribers with insufficient state.
2048
+ # @param timeout [Numeric, nil] Seconds bounding the call, replacing request_timeout, longer or shorter: request_timeout when nil. Zero is refused, as a negative is.
2049
+ # @return [SharedPollPublishResult]
2050
+ # @raise [Error]
2051
+ def shared_poll_publish(
2052
+ channel:,
2053
+ key:,
2054
+ version:,
2055
+ data: nil,
2056
+ b64data: nil,
2057
+ epoch: nil,
2058
+ timeout: nil
2059
+ )
2060
+ invoke("shared_poll_publish", SharedPollPublishResult, timeout) do
2061
+ Requests.shared_poll_publish(
2062
+ channel,
2063
+ key,
2064
+ data,
2065
+ b64data,
2066
+ version,
2067
+ epoch
2068
+ )
2069
+ end
2070
+ end
2071
+ end
2072
+
2073
+ # The commands of Batch, one per method of api.proto.
2074
+ #
2075
+ # @api private
2076
+ module BatchMethods
2077
+ # Publishes data into a channel.
2078
+ #
2079
+ # Adds the command to the batch: its Pending holds the result once the batch
2080
+ # is sent.
2081
+ #
2082
+ # @param channel [String, nil] The name of the channel to publish into. Required.
2083
+ # @param data [Object, nil] The payload to publish. Required unless b64data is set. In the
2084
+ # HTTP API it is any JSON value; over GRPC it may be binary.
2085
+ # @param b64data [String, nil] A base64-encoded binary payload, an alternative to `data` to
2086
+ # send binary over the HTTP API. Centrifugo decodes it before publishing.
2087
+ # @param skip_history [Boolean, nil] Skips adding this publication to the channel history.
2088
+ # @param tags [Hash{String => String}] A map of arbitrary string keys and values attached to the
2089
+ # publication and delivered to clients.
2090
+ # @param idempotency_key [String, nil] Drops duplicate publications upon retries: a
2091
+ # publication with a key already used in the channel is not published
2092
+ # again, and the first one's result is returned. It acts per channel;
2093
+ # results are kept for 5 minutes by default. The memory, Redis and
2094
+ # PostgreSQL brokers keep keys; the NATS broker ignores them.
2095
+ # @param delta [Boolean, nil] Tells Centrifugo to construct a delta update, if possible, when
2096
+ # broadcasting the publication to subscribers.
2097
+ # @param version [Integer, nil] When > 0, the version of the document being sent:
2098
+ # publications with a version less than or equal to one already seen are
2099
+ # ignored. Only works in channels with history enabled.
2100
+ # @param version_epoch [String, nil] The epoch of version. When it changes, Centrifugo
2101
+ # accepts the publication even if its version is lower than before.
2102
+ # @return [Pending<PublishResult>]
2103
+ def publish(
2104
+ channel:,
2105
+ data: nil,
2106
+ b64data: nil,
2107
+ skip_history: nil,
2108
+ tags: nil,
2109
+ idempotency_key: nil,
2110
+ delta: nil,
2111
+ version: nil,
2112
+ version_epoch: nil
2113
+ )
2114
+ add("publish", PublishResult) do
2115
+ Requests.publish(
2116
+ channel,
2117
+ data,
2118
+ b64data,
2119
+ skip_history,
2120
+ tags,
2121
+ idempotency_key,
2122
+ delta,
2123
+ version,
2124
+ version_epoch
2125
+ )
2126
+ end
2127
+ end
2128
+
2129
+ # Publishes the same data into many channels.
2130
+ #
2131
+ # Adds the command to the batch: its Pending holds the result once the batch
2132
+ # is sent, and raises BroadcastFailedChannelsError when any channel failed.
2133
+ #
2134
+ # @param channels [Array<String>] The list of channels to publish into. Required.
2135
+ # @param data [Object, nil] The payload to publish into each channel. Required unless
2136
+ # b64data is set. In the HTTP API it is any JSON value; over GRPC it may
2137
+ # be binary.
2138
+ # @param b64data [String, nil] A base64-encoded binary payload, an alternative to `data` to
2139
+ # send binary over the HTTP API. Centrifugo decodes it before publishing.
2140
+ # @param skip_history [Boolean, nil] Skips adding the publications to the channels' history.
2141
+ # @param tags [Hash{String => String}] A map of arbitrary string keys and values attached to each
2142
+ # publication and delivered to clients.
2143
+ # @param idempotency_key [String, nil] Drops duplicate publications upon retries. It acts per
2144
+ # channel: a broadcast retried with the same key is not published again
2145
+ # into the channels which already have it. Results are kept for 5 minutes
2146
+ # by default. The memory, Redis and PostgreSQL brokers keep keys; the
2147
+ # NATS broker ignores them.
2148
+ # @param delta [Boolean, nil] Tells Centrifugo to construct a delta update, if possible, when
2149
+ # broadcasting the publications to subscribers.
2150
+ # @param version [Integer, nil] When > 0, the version of the document being sent:
2151
+ # publications with a version less than or equal to one already seen are
2152
+ # ignored. Only works in channels with history enabled.
2153
+ # @param version_epoch [String, nil] The epoch of version. When it changes, Centrifugo
2154
+ # accepts the publication even if its version is lower than before.
2155
+ # @return [Pending<BroadcastResult>]
2156
+ def broadcast(
2157
+ channels:,
2158
+ data: nil,
2159
+ b64data: nil,
2160
+ skip_history: nil,
2161
+ tags: nil,
2162
+ idempotency_key: nil,
2163
+ delta: nil,
2164
+ version: nil,
2165
+ version_epoch: nil
2166
+ )
2167
+ add_broadcast do
2168
+ Requests.broadcast(
2169
+ channels,
2170
+ data,
2171
+ b64data,
2172
+ skip_history,
2173
+ tags,
2174
+ idempotency_key,
2175
+ delta,
2176
+ version,
2177
+ version_epoch
2178
+ )
2179
+ end
2180
+ end
2181
+
2182
+ # Subscribes active sessions of a user to a channel
2183
+ # (server-side subscription). It does not create a streaming subscription
2184
+ # for the caller.
2185
+ #
2186
+ # Adds the command to the batch: its Pending holds the result once the batch
2187
+ # is sent.
2188
+ #
2189
+ # @param channel [String, nil] The name of the channel to subscribe to. Required.
2190
+ # @param user [String, nil] The ID of the user to subscribe. Required, unless all_users is
2191
+ # used in Centrifugo PRO.
2192
+ # @param expire_at [Integer, nil] The Unix time in seconds when the subscription expires.
2193
+ # @param info [Object, nil] Custom channel info attached to the subscription, used in
2194
+ # presence and join/leave messages.
2195
+ # @param b64info [String, nil] Info as base64, for binary. Centrifugo decodes it.
2196
+ # @param client [String, nil] Limits the call to the connection with this client ID. user is
2197
+ # still required.
2198
+ # @param data [Object, nil] Custom subscription data sent to the client in the Subscribe
2199
+ # push.
2200
+ # @param b64data [String, nil] Data as base64, for binary. Centrifugo decodes it.
2201
+ # @param recover_since [StreamPosition, Hash, nil] The stream position to recover publications from.
2202
+ # @param override [SubscribeOptionOverride, Hash, nil] Dynamically overrides some channel options set in the
2203
+ # Centrifugo configuration.
2204
+ # @param session [String, nil] Limits the call to the connection with this session ID. user
2205
+ # is still required.
2206
+ # @param label_filter [FilterNode, Hash, nil] Restricts the call to clients whose labels match this
2207
+ # filter. Centrifugo PRO only.
2208
+ # @param all_users [Boolean, nil] When user is empty, targets every connection on every node
2209
+ # instead of the anonymous-only bucket. No effect when user is non-empty.
2210
+ # Without label_filter it acts on every connection. Centrifugo PRO only.
2211
+ # @return [Pending<SubscribeResult>]
2212
+ def subscribe(
2213
+ channel:,
2214
+ user: nil,
2215
+ expire_at: nil,
2216
+ info: nil,
2217
+ b64info: nil,
2218
+ client: nil,
2219
+ data: nil,
2220
+ b64data: nil,
2221
+ recover_since: nil,
2222
+ override: nil,
2223
+ session: nil,
2224
+ label_filter: nil,
2225
+ all_users: nil
2226
+ )
2227
+ add("subscribe", SubscribeResult) do
2228
+ Requests.subscribe(
2229
+ channel,
2230
+ user,
2231
+ expire_at,
2232
+ info,
2233
+ b64info,
2234
+ client,
2235
+ data,
2236
+ b64data,
2237
+ recover_since,
2238
+ override,
2239
+ session,
2240
+ label_filter,
2241
+ all_users
2242
+ )
2243
+ end
2244
+ end
2245
+
2246
+ # Unsubscribes a user from a channel.
2247
+ #
2248
+ # Adds the command to the batch: its Pending holds the result once the batch
2249
+ # is sent.
2250
+ #
2251
+ # @param channel [String, nil] The name of the channel to unsubscribe from. Required.
2252
+ # @param user [String, nil] The ID of the user to unsubscribe. Required, unless all_users
2253
+ # is used in Centrifugo PRO.
2254
+ # @param client [String, nil] Limits the call to the connection with this client ID. user is
2255
+ # still required.
2256
+ # @param session [String, nil] Limits the call to the connection with this session ID. user
2257
+ # is still required.
2258
+ # @param label_filter [FilterNode, Hash, nil] Restricts the call to clients whose labels match this
2259
+ # filter. Centrifugo PRO only.
2260
+ # @param all_users [Boolean, nil] Works as SubscribeRequest.all_users. Centrifugo PRO only.
2261
+ # @return [Pending<UnsubscribeResult>]
2262
+ def unsubscribe(
2263
+ channel:,
2264
+ user: nil,
2265
+ client: nil,
2266
+ session: nil,
2267
+ label_filter: nil,
2268
+ all_users: nil
2269
+ )
2270
+ add("unsubscribe", UnsubscribeResult) do
2271
+ Requests.unsubscribe(
2272
+ channel,
2273
+ user,
2274
+ client,
2275
+ session,
2276
+ label_filter,
2277
+ all_users
2278
+ )
2279
+ end
2280
+ end
2281
+
2282
+ # Disconnects a user's connections.
2283
+ #
2284
+ # Adds the command to the batch: its Pending holds the result once the batch
2285
+ # is sent.
2286
+ #
2287
+ # @param user [String, nil] The ID of the user to disconnect. Required, unless all_users is
2288
+ # used in Centrifugo PRO.
2289
+ # @param disconnect [Disconnect, Hash, nil] A custom disconnect code and reason. If not set, clients
2290
+ # are disconnected with a force no-reconnect disconnect.
2291
+ # @param client [String, nil] Limits the call to the connection with this client ID. user is
2292
+ # still required.
2293
+ # @param whitelist [Array<String>] A list of client IDs to keep connected.
2294
+ # @param session [String, nil] Limits the call to the connection with this session ID. user
2295
+ # is still required.
2296
+ # @param label_filter [FilterNode, Hash, nil] Restricts the call to clients whose labels match this
2297
+ # filter. Centrifugo PRO only.
2298
+ # @param all_users [Boolean, nil] Works as SubscribeRequest.all_users. Centrifugo PRO only.
2299
+ # @return [Pending<DisconnectResult>]
2300
+ def disconnect(
2301
+ user: nil,
2302
+ disconnect: nil,
2303
+ client: nil,
2304
+ whitelist: nil,
2305
+ session: nil,
2306
+ label_filter: nil,
2307
+ all_users: nil
2308
+ )
2309
+ add("disconnect", DisconnectResult) do
2310
+ Requests.disconnect(
2311
+ user,
2312
+ disconnect,
2313
+ client,
2314
+ whitelist,
2315
+ session,
2316
+ label_filter,
2317
+ all_users
2318
+ )
2319
+ end
2320
+ end
2321
+
2322
+ # Returns the online presence of a channel: all clients
2323
+ # currently subscribed to it. Presence must be enabled for the channel.
2324
+ #
2325
+ # Adds the command to the batch: its Pending holds the result once the batch
2326
+ # is sent.
2327
+ #
2328
+ # @param channel [String, nil] The name of the channel. Required.
2329
+ # @return [Pending<PresenceResult>]
2330
+ def presence(channel:)
2331
+ add("presence", PresenceResult) do
2332
+ Requests.presence(channel)
2333
+ end
2334
+ end
2335
+
2336
+ # Returns short presence information of a channel: the
2337
+ # number of clients and of unique users. Presence must be enabled for the
2338
+ # channel.
2339
+ #
2340
+ # Adds the command to the batch: its Pending holds the result once the batch
2341
+ # is sent.
2342
+ #
2343
+ # @param channel [String, nil] The name of the channel. Required.
2344
+ # @return [Pending<PresenceStatsResult>]
2345
+ def presence_stats(channel:)
2346
+ add("presence_stats", PresenceStatsResult) do
2347
+ Requests.presence_stats(channel)
2348
+ end
2349
+ end
2350
+
2351
+ # Returns publications from the history of a channel.
2352
+ # History must be enabled for the channel.
2353
+ #
2354
+ # Adds the command to the batch: its Pending holds the result once the batch
2355
+ # is sent.
2356
+ #
2357
+ # @param channel [String, nil] The name of the channel. Required.
2358
+ # @param limit [Integer, nil] The maximum number of publications to return; -1 returns all
2359
+ # the channel keeps. If not set, only the current stream position is
2360
+ # returned, without publications.
2361
+ # @param since [StreamPosition, Hash, nil] Returns publications after this stream position.
2362
+ # @param reverse [Boolean, nil] Iterates in reverse order, from latest to earliest.
2363
+ # @return [Pending<HistoryResult>]
2364
+ def history(
2365
+ channel:,
2366
+ limit: nil,
2367
+ since: nil,
2368
+ reverse: nil
2369
+ )
2370
+ add("history", HistoryResult) do
2371
+ Requests.history(channel, limit, since, reverse)
2372
+ end
2373
+ end
2374
+
2375
+ # Removes publications from the history of a channel.
2376
+ # The current top stream position is kept, so clients do not get
2377
+ # disconnected because of insufficient state.
2378
+ #
2379
+ # Adds the command to the batch: its Pending holds the result once the batch
2380
+ # is sent.
2381
+ #
2382
+ # @param channel [String, nil] The name of the channel. Required.
2383
+ # @return [Pending<HistoryRemoveResult>]
2384
+ def history_remove(channel:)
2385
+ add("history_remove", HistoryRemoveResult) do
2386
+ Requests.history_remove(channel)
2387
+ end
2388
+ end
2389
+
2390
+ # Returns information about the running Centrifugo nodes.
2391
+ #
2392
+ # Adds the command to the batch: its Pending holds the result once the batch
2393
+ # is sent.
2394
+ #
2395
+ # @return [Pending<InfoResult>]
2396
+ def info
2397
+ add("info", InfoResult) do
2398
+ Requests.info
2399
+ end
2400
+ end
2401
+
2402
+ # Refreshes a user's connections, mostly useful with
2403
+ # unidirectional transports. Without expire_at the connections become
2404
+ # non-expiring.
2405
+ #
2406
+ # Adds the command to the batch: its Pending holds the result once the batch
2407
+ # is sent.
2408
+ #
2409
+ # @param user [String, nil] The ID of the user to refresh. Required, unless all_users is
2410
+ # used in Centrifugo PRO.
2411
+ # @param client [String, nil] Limits the call to the connection with this client ID. user is
2412
+ # still required.
2413
+ # @param expired [Boolean, nil] Marks the connections as expired and closes them with an
2414
+ # expired disconnect reason.
2415
+ # @param expire_at [Integer, nil] The Unix time in seconds when the connections expire.
2416
+ # @param info [Object, nil] Attaches or replaces the connection info.
2417
+ # @param session [String, nil] Limits the call to the connection with this session ID. user
2418
+ # is still required.
2419
+ # @param label_filter [FilterNode, Hash, nil] Restricts the call to clients whose labels match this
2420
+ # filter. Centrifugo PRO only.
2421
+ # @param all_users [Boolean, nil] Works as SubscribeRequest.all_users. Centrifugo PRO only.
2422
+ # @return [Pending<RefreshResult>]
2423
+ def refresh(
2424
+ user: nil,
2425
+ client: nil,
2426
+ expired: nil,
2427
+ expire_at: nil,
2428
+ info: nil,
2429
+ session: nil,
2430
+ label_filter: nil,
2431
+ all_users: nil
2432
+ )
2433
+ add("refresh", RefreshResult) do
2434
+ Requests.refresh(
2435
+ user,
2436
+ client,
2437
+ expired,
2438
+ expire_at,
2439
+ info,
2440
+ session,
2441
+ label_filter,
2442
+ all_users
2443
+ )
2444
+ end
2445
+ end
2446
+
2447
+ # Returns active channels (with one or more subscribers).
2448
+ # It can be heavy on large deployments: there is no pagination.
2449
+ #
2450
+ # Adds the command to the batch: its Pending holds the result once the batch
2451
+ # is sent.
2452
+ #
2453
+ # @param pattern [String, nil] Filters channels by name, using gobwas/glob syntax.
2454
+ # @return [Pending<ChannelsResult>]
2455
+ def channels(pattern: nil)
2456
+ add("channels", ChannelsResult) do
2457
+ Requests.channels(pattern)
2458
+ end
2459
+ end
2460
+
2461
+ # Returns information about active connections, without
2462
+ # the need to enable presence. At least one of user, expression or
2463
+ # label_filter must be set. Centrifugo PRO only.
2464
+ #
2465
+ # Adds the command to the batch: its Pending holds the result once the batch
2466
+ # is sent.
2467
+ #
2468
+ # @param user [String, nil] Returns only the connections of this user ID.
2469
+ # @param expression [String, nil] A CEL expression to filter connections.
2470
+ # @param label_filter [FilterNode, Hash, nil] Restricts the listing to clients whose labels match this
2471
+ # filter. Centrifugo PRO only.
2472
+ # @return [Pending<ConnectionsResult>]
2473
+ def connections(user: nil, expression: nil, label_filter: nil)
2474
+ add("connections", ConnectionsResult) do
2475
+ Requests.connections(user, expression, label_filter)
2476
+ end
2477
+ end
2478
+
2479
+ # Marks users as active and online now, and sets
2480
+ # their state when one is given. Centrifugo PRO only.
2481
+ #
2482
+ # Adds the command to the batch: its Pending holds the result once the batch
2483
+ # is sent.
2484
+ #
2485
+ # @param users [Array<String>] The list of user IDs to update the status for. Required.
2486
+ # @param state [String, nil] An optional custom state to store in the user status. It can
2487
+ # be restricted by the user_status.state_regex option.
2488
+ # @return [Pending<UpdateUserStatusResult>]
2489
+ def update_user_status(users:, state: nil)
2490
+ add("update_user_status", UpdateUserStatusResult) do
2491
+ Requests.update_user_status(users, state)
2492
+ end
2493
+ end
2494
+
2495
+ # Returns the status of users. Centrifugo PRO only.
2496
+ #
2497
+ # Adds the command to the batch: its Pending holds the result once the batch
2498
+ # is sent.
2499
+ #
2500
+ # @param users [Array<String>] The list of user IDs to get the status for. Required.
2501
+ # @return [Pending<GetUserStatusResult>]
2502
+ def get_user_status(users:)
2503
+ add("get_user_status", GetUserStatusResult) do
2504
+ Requests.get_user_status(users)
2505
+ end
2506
+ end
2507
+
2508
+ # Deletes the status of users. Centrifugo PRO only.
2509
+ #
2510
+ # Adds the command to the batch: its Pending holds the result once the batch
2511
+ # is sent.
2512
+ #
2513
+ # @param users [Array<String>] The list of user IDs to delete the status for. Required.
2514
+ # @return [Pending<DeleteUserStatusResult>]
2515
+ def delete_user_status(users:)
2516
+ add("delete_user_status", DeleteUserStatusResult) do
2517
+ Requests.delete_user_status(users)
2518
+ end
2519
+ end
2520
+
2521
+ # Blocks a user: the user is disconnected and can not
2522
+ # connect again until unblocked or the block expires. Centrifugo PRO only.
2523
+ #
2524
+ # Adds the command to the batch: its Pending holds the result once the batch
2525
+ # is sent.
2526
+ #
2527
+ # @param expire_at [Integer, nil] The Unix time in seconds when the block expires. Optional,
2528
+ # but a reasonably small value is recommended to keep the set of blocked
2529
+ # users small.
2530
+ # @param user [String, nil] The ID of the user to block. Required.
2531
+ # @return [Pending<BlockUserResult>]
2532
+ def block_user(user:, expire_at: nil)
2533
+ add("block_user", BlockUserResult) do
2534
+ Requests.block_user(expire_at, user)
2535
+ end
2536
+ end
2537
+
2538
+ # Unblocks a user. Centrifugo PRO only.
2539
+ #
2540
+ # Adds the command to the batch: its Pending holds the result once the batch
2541
+ # is sent.
2542
+ #
2543
+ # @param user [String, nil] The ID of the user to unblock. Required.
2544
+ # @return [Pending<UnblockUserResult>]
2545
+ def unblock_user(user:)
2546
+ add("unblock_user", UnblockUserResult) do
2547
+ Requests.unblock_user(user)
2548
+ end
2549
+ end
2550
+
2551
+ # Revokes a token by its unique ID (jti claim of a JWT).
2552
+ # Clients using the token are disconnected shortly, and can not connect
2553
+ # with it again. Centrifugo PRO only.
2554
+ #
2555
+ # Adds the command to the batch: its Pending holds the result once the batch
2556
+ # is sent.
2557
+ #
2558
+ # @param expire_at [Integer, nil] The Unix time in seconds when the revocation expires.
2559
+ # Optional, but a value matching the token expiration is recommended.
2560
+ # @param uid [String, nil] The unique ID of the token to revoke (jti claim). Required.
2561
+ # @return [Pending<RevokeTokenResult>]
2562
+ def revoke_token(uid:, expire_at: nil)
2563
+ add("revoke_token", RevokeTokenResult) do
2564
+ Requests.revoke_token(expire_at, uid)
2565
+ end
2566
+ end
2567
+
2568
+ # Revokes all tokens of a user issued before a
2569
+ # certain time (based on the iat claim of a JWT). Centrifugo PRO only.
2570
+ #
2571
+ # Adds the command to the batch: its Pending holds the result once the batch
2572
+ # is sent.
2573
+ #
2574
+ # @param expire_at [Integer, nil] The Unix time in seconds when the invalidation expires.
2575
+ # Optional, but a value matching the token expiration is recommended.
2576
+ # @param user [String, nil] The ID of the user whose tokens to invalidate. Required. ""
2577
+ # invalidates the tokens of anonymous users.
2578
+ # @param issued_before [Integer, nil] The Unix time in seconds: tokens issued before it are
2579
+ # considered revoked. If not set, the current time is used.
2580
+ # @param channel [String, nil] Limits the invalidation to subscription tokens for this
2581
+ # channel.
2582
+ # @return [Pending<InvalidateUserTokensResult>]
2583
+ def invalidate_user_tokens(
2584
+ user:,
2585
+ expire_at: nil,
2586
+ issued_before: nil,
2587
+ channel: nil
2588
+ )
2589
+ add("invalidate_user_tokens", InvalidateUserTokensResult) do
2590
+ Requests.invalidate_user_tokens(expire_at, user, issued_before, channel)
2591
+ end
2592
+ end
2593
+
2594
+ # Registers a device for push notifications, or
2595
+ # updates a registered one. Centrifugo PRO only.
2596
+ #
2597
+ # Adds the command to the batch: its Pending holds the result once the batch
2598
+ # is sent.
2599
+ #
2600
+ # @param id [String, nil] The device ID. Omit it on first registration: Centrifugo
2601
+ # generates one and returns it. Pass the stored value to update the
2602
+ # device.
2603
+ # @param provider [String, nil] The provider of the device token. Required. One of: fcm,
2604
+ # hms, apns, webpush.
2605
+ # @param token [String, nil] The push token of the device. For webpush, it is the browser
2606
+ # PushSubscription serialized as a JSON string. Required.
2607
+ # @param platform [String, nil] The device platform. Required. One of: ios, android, web.
2608
+ # @param user [String, nil] The user associated with the device.
2609
+ # @param meta [Hash{String => String}] Additional custom metadata of the device.
2610
+ # @param topics [Array<String>] The full list of the device's topic subscriptions, replacing
2611
+ # the previous one. The user's topics are attached automatically.
2612
+ # @param timezone [String, nil] The IANA time zone of the device user, for example
2613
+ # Europe/Nicosia.
2614
+ # @param locale [String, nil] The locale of the device user as an IETF BCP 47 language
2615
+ # tag, for example en-US.
2616
+ # @return [Pending<DeviceRegisterResult>]
2617
+ def device_register(
2618
+ provider:,
2619
+ token:,
2620
+ platform:,
2621
+ id: nil,
2622
+ user: nil,
2623
+ meta: nil,
2624
+ topics: nil,
2625
+ timezone: nil,
2626
+ locale: nil
2627
+ )
2628
+ add("device_register", DeviceRegisterResult) do
2629
+ Requests.device_register(
2630
+ id,
2631
+ provider,
2632
+ token,
2633
+ platform,
2634
+ user,
2635
+ meta,
2636
+ topics,
2637
+ timezone,
2638
+ locale
2639
+ )
2640
+ end
2641
+ end
2642
+
2643
+ # Updates registered devices, selected by ids and/or
2644
+ # users. Centrifugo PRO only.
2645
+ #
2646
+ # Adds the command to the batch: its Pending holds the result once the batch
2647
+ # is sent.
2648
+ #
2649
+ # @param ids [Array<String>] Selects devices by ID.
2650
+ # @param users [Array<String>] Selects devices by user.
2651
+ # @param user_update [DeviceUserUpdate, Hash, nil] Changes the user ID of the devices. It does not re-sync
2652
+ # user-bound topics; use DeviceRegisterRequest to assign a device to
2653
+ # another user.
2654
+ # @param meta_update [DeviceMetaUpdate, Hash, nil] Updates the device meta.
2655
+ # @param topics_update [DeviceTopicsUpdate, Hash, nil] Updates the device topics.
2656
+ # @param timezone_update [DeviceTimezoneUpdate, Hash, nil] Updates the device timezone.
2657
+ # @param locale_update [DeviceLocaleUpdate, Hash, nil] Updates the device locale.
2658
+ # @return [Pending<DeviceUpdateResult>]
2659
+ def device_update(
2660
+ ids: nil,
2661
+ users: nil,
2662
+ user_update: nil,
2663
+ meta_update: nil,
2664
+ topics_update: nil,
2665
+ timezone_update: nil,
2666
+ locale_update: nil
2667
+ )
2668
+ add("device_update", DeviceUpdateResult) do
2669
+ Requests.device_update(
2670
+ ids,
2671
+ users,
2672
+ user_update,
2673
+ meta_update,
2674
+ topics_update,
2675
+ timezone_update,
2676
+ locale_update
2677
+ )
2678
+ end
2679
+ end
2680
+
2681
+ # Removes devices, selected by ids and/or users.
2682
+ # Centrifugo PRO only.
2683
+ #
2684
+ # Adds the command to the batch: its Pending holds the result once the batch
2685
+ # is sent.
2686
+ #
2687
+ # @param ids [Array<String>] Selects devices to remove by ID.
2688
+ # @param users [Array<String>] Selects devices to remove by user.
2689
+ # @return [Pending<DeviceRemoveResult>]
2690
+ def device_remove(ids: nil, users: nil)
2691
+ add("device_remove", DeviceRemoveResult) do
2692
+ Requests.device_remove(ids, users)
2693
+ end
2694
+ end
2695
+
2696
+ # Returns a paginated list of registered devices.
2697
+ # Centrifugo PRO only.
2698
+ #
2699
+ # Adds the command to the batch: its Pending holds the result once the batch
2700
+ # is sent.
2701
+ #
2702
+ # @param filter [DeviceFilter, Hash, nil] Selects the devices to list: all of them when unset.
2703
+ # @param include_total_count [Boolean, nil] Includes the total count for the filter in the
2704
+ # result.
2705
+ # @param include_meta [Boolean, nil] Includes meta of each device.
2706
+ # @param include_topics [Boolean, nil] Includes topics of each device.
2707
+ # @param include_webpush_keys [Boolean, nil] Includes webpush_keys of each device (webpush
2708
+ # only).
2709
+ # @param cursor [String, nil] The pagination cursor: next_cursor of the previous page,
2710
+ # empty for the first page.
2711
+ # @param limit [Integer, nil] The maximum number of devices to return.
2712
+ # @return [Pending<DeviceListResult>]
2713
+ def device_list(
2714
+ filter: nil,
2715
+ include_total_count: nil,
2716
+ include_meta: nil,
2717
+ include_topics: nil,
2718
+ include_webpush_keys: nil,
2719
+ cursor: nil,
2720
+ limit: nil
2721
+ )
2722
+ add("device_list", DeviceListResult) do
2723
+ Requests.device_list(
2724
+ filter,
2725
+ include_total_count,
2726
+ include_meta,
2727
+ include_topics,
2728
+ include_webpush_keys,
2729
+ cursor,
2730
+ limit
2731
+ )
2732
+ end
2733
+ end
2734
+
2735
+ # Returns a paginated list of device topic
2736
+ # subscriptions. Centrifugo PRO only.
2737
+ #
2738
+ # Adds the command to the batch: its Pending holds the result once the batch
2739
+ # is sent.
2740
+ #
2741
+ # @param filter [DeviceTopicFilter, Hash, nil] Selects the device topics to list.
2742
+ # @param include_total_count [Boolean, nil] Includes the total count for the filter in the
2743
+ # result.
2744
+ # @param include_device [Boolean, nil] Includes the Device of each item.
2745
+ # @param cursor [String, nil] The pagination cursor: next_cursor of the previous page,
2746
+ # empty for the first page.
2747
+ # @param limit [Integer, nil] The maximum number of items to return.
2748
+ # @return [Pending<DeviceTopicListResult>]
2749
+ def device_topic_list(
2750
+ filter: nil,
2751
+ include_total_count: nil,
2752
+ include_device: nil,
2753
+ cursor: nil,
2754
+ limit: nil
2755
+ )
2756
+ add("device_topic_list", DeviceTopicListResult) do
2757
+ Requests.device_topic_list(
2758
+ filter,
2759
+ include_total_count,
2760
+ include_device,
2761
+ cursor,
2762
+ limit
2763
+ )
2764
+ end
2765
+ end
2766
+
2767
+ # Changes the topics of a device. The device topic
2768
+ # list is what decides who gets a push sent to a topic.
2769
+ # Centrifugo PRO only.
2770
+ #
2771
+ # Adds the command to the batch: its Pending holds the result once the batch
2772
+ # is sent.
2773
+ #
2774
+ # @param device_id [String, nil] The ID of the device. Required.
2775
+ # @param op [String, nil] The operation. Required. One of: add, remove, set.
2776
+ # @param topics [Array<String>] The topics for the operation.
2777
+ # @param user [String, nil] An optional ownership guard: the update is applied only if the
2778
+ # device currently belongs to this user. Otherwise the call fails with a
2779
+ # conflict error (or not found if there is no such device).
2780
+ # @return [Pending<DeviceTopicUpdateResult>]
2781
+ def device_topic_update(
2782
+ device_id:,
2783
+ op:,
2784
+ topics: nil,
2785
+ user: nil
2786
+ )
2787
+ add("device_topic_update", DeviceTopicUpdateResult) do
2788
+ Requests.device_topic_update(device_id, op, topics, user)
2789
+ end
2790
+ end
2791
+
2792
+ # Returns a paginated list of user topic
2793
+ # subscriptions. Centrifugo PRO only.
2794
+ #
2795
+ # Adds the command to the batch: its Pending holds the result once the batch
2796
+ # is sent.
2797
+ #
2798
+ # @param filter [UserTopicFilter, Hash, nil] Selects the user topics to list.
2799
+ # @param include_total_count [Boolean, nil] Includes the total count for the filter in the
2800
+ # result.
2801
+ # @param cursor [String, nil] The pagination cursor: next_cursor of the previous page,
2802
+ # empty for the first page.
2803
+ # @param limit [Integer, nil] The maximum number of items to return.
2804
+ # @return [Pending<UserTopicListResult>]
2805
+ def user_topic_list(
2806
+ filter: nil,
2807
+ include_total_count: nil,
2808
+ cursor: nil,
2809
+ limit: nil
2810
+ )
2811
+ add("user_topic_list", UserTopicListResult) do
2812
+ Requests.user_topic_list(filter, include_total_count, cursor, limit)
2813
+ end
2814
+ end
2815
+
2816
+ # Changes the topics of a user. The change is also
2817
+ # applied to the user's registered devices. Centrifugo PRO only.
2818
+ #
2819
+ # Adds the command to the batch: its Pending holds the result once the batch
2820
+ # is sent.
2821
+ #
2822
+ # @param user [String, nil] The user ID. Required. "" updates the global binding, which every
2823
+ # device - anonymous ones included - gets on its next device_register.
2824
+ # @param op [String, nil] The operation. Required. One of: add, remove, set.
2825
+ # @param topics [Array<String>] The topics for the operation.
2826
+ # @return [Pending<UserTopicUpdateResult>]
2827
+ def user_topic_update(user:, op:, topics: nil)
2828
+ add("user_topic_update", UserTopicUpdateResult) do
2829
+ Requests.user_topic_update(user, op, topics)
2830
+ end
2831
+ end
2832
+
2833
+ # Sends a push notification. The request is
2834
+ # queued and sent to the provider by Centrifugo workers.
2835
+ # Centrifugo PRO only.
2836
+ #
2837
+ # Adds the command to the batch: its Pending holds the result once the batch
2838
+ # is sent.
2839
+ #
2840
+ # @param recipient [PushRecipient, Hash, nil] Who receives the notification. Required.
2841
+ # @param notification [PushNotification, Hash, nil] The notification to send. Required.
2842
+ # @param uid [String, nil] A unique identifier of the request, can be used to cancel the
2843
+ # push. UUID v4 is recommended; different requests must use different
2844
+ # uids.
2845
+ # @param send_at [Integer, nil] The Unix time in seconds when to send the notification. If
2846
+ # not set, the notification is sent immediately.
2847
+ # @param optimize_for_reliability [Boolean, nil] Makes processing heavier, but tolerates edge
2848
+ # cases, like not losing inflight pushes when the queue is briefly
2849
+ # unavailable.
2850
+ # @param limit_strategy [PushLimitStrategy, Hash, nil] Sets time constraints and rate limits. Only applies
2851
+ # with a filter recipient; devices are then processed one by one
2852
+ # instead of in batches. Needs notification.expire_at: a push the limits
2853
+ # hold back is not tried forever.
2854
+ # @param analytics_uid [String, nil] The identifier for push notification analytics. If
2855
+ # not set, uid is used.
2856
+ # @param localizations [Hash{String => PushLocalization, Hash}] Optional per language/locale localizations. Setting
2857
+ # them enables templating.
2858
+ # @param use_templating [Boolean, nil] Enables templating of the notification. Only works
2859
+ # with a filter recipient.
2860
+ # @param use_meta [Boolean, nil] Additionally loads device meta while sending, making it
2861
+ # available in templating.
2862
+ # @return [Pending<SendPushNotificationResult>]
2863
+ def send_push_notification(
2864
+ recipient:,
2865
+ notification:,
2866
+ uid: nil,
2867
+ send_at: nil,
2868
+ optimize_for_reliability: nil,
2869
+ limit_strategy: nil,
2870
+ analytics_uid: nil,
2871
+ localizations: nil,
2872
+ use_templating: nil,
2873
+ use_meta: nil
2874
+ )
2875
+ add("send_push_notification", SendPushNotificationResult) do
2876
+ Requests.send_push_notification(
2877
+ recipient,
2878
+ notification,
2879
+ uid,
2880
+ send_at,
2881
+ optimize_for_reliability,
2882
+ limit_strategy,
2883
+ analytics_uid,
2884
+ localizations,
2885
+ use_templating,
2886
+ use_meta
2887
+ )
2888
+ end
2889
+ end
2890
+
2891
+ # Saves the delivery or interaction status of a
2892
+ # push notification to analytics. Experimental. Centrifugo PRO only.
2893
+ #
2894
+ # Adds the command to the batch: its Pending holds the result once the batch
2895
+ # is sent.
2896
+ #
2897
+ # @param analytics_uid [String, nil] The analytics_uid of the push notification (as in
2898
+ # SendPushNotificationRequest). Required.
2899
+ # @param status [String, nil] The status of the push notification. Required. One of:
2900
+ # delivered, interacted.
2901
+ # @param device_id [String, nil] The Centrifugo device ID. Required.
2902
+ # @param msg_id [String, nil] The message ID issued by the provider.
2903
+ # @return [Pending<UpdatePushStatusResult>]
2904
+ def update_push_status(
2905
+ analytics_uid:,
2906
+ status:,
2907
+ device_id:,
2908
+ msg_id: nil
2909
+ )
2910
+ add("update_push_status", UpdatePushStatusResult) do
2911
+ Requests.update_push_status(analytics_uid, status, device_id, msg_id)
2912
+ end
2913
+ end
2914
+
2915
+ # Cancels a delayed push notification (sent with
2916
+ # send_at). Centrifugo PRO only.
2917
+ #
2918
+ # Adds the command to the batch: its Pending holds the result once the batch
2919
+ # is sent.
2920
+ #
2921
+ # @param uid [String, nil] The uid of the push notification to cancel. Required.
2922
+ # @return [Pending<CancelPushResult>]
2923
+ def cancel_push(uid:)
2924
+ add("cancel_push", CancelPushResult) do
2925
+ Requests.cancel_push(uid)
2926
+ end
2927
+ end
2928
+
2929
+ # Publishes or updates a key in a map channel.
2930
+ #
2931
+ # Adds the command to the batch: its Pending holds the result once the batch
2932
+ # is sent.
2933
+ #
2934
+ # @param channel [String, nil] The name of the map channel. Required.
2935
+ # @param key [String, nil] The entry key. Required.
2936
+ # @param data [Object, nil] The entry data. In the HTTP API it is any JSON value; over GRPC
2937
+ # it may be binary.
2938
+ # @param b64data [String, nil] Data as base64, for binary over the HTTP API. Centrifugo
2939
+ # decodes it.
2940
+ # @param stream_data [Object, nil] Currently not used by the server API.
2941
+ # @param b64stream_data [String, nil] Currently not used by the server API.
2942
+ # @param tags [Hash{String => String}] Key-value metadata attached to the publication.
2943
+ # @param idempotency_key [String, nil] Drops duplicate publications upon retries: a
2944
+ # publication with a key already used in the channel is not applied
2945
+ # again, and its result has the first one's position, with suppressed
2946
+ # set and suppress_reason "idempotency". It acts per channel; keys are
2947
+ # kept for 5 minutes by default. Every map broker - memory, Redis and
2948
+ # PostgreSQL - keeps keys.
2949
+ # @param delta [Boolean, nil] Enables delta compression for this publication.
2950
+ # @param version [Integer, nil] A per-key version: publications with a version not higher
2951
+ # than the key's current one are suppressed.
2952
+ # @param version_epoch [String, nil] Scopes version. A different epoch resets version
2953
+ # comparison.
2954
+ # @param score [Integer, nil] Currently not used by the server API.
2955
+ # @param key_mode [String, nil] Makes the publish conditional: if_new writes only if the key
2956
+ # does not exist, if_exists only if it exists. Empty always writes.
2957
+ # One of: if_new, if_exists.
2958
+ # @return [Pending<MapPublishResult>]
2959
+ def map_publish(
2960
+ channel:,
2961
+ key:,
2962
+ data: nil,
2963
+ b64data: nil,
2964
+ stream_data: nil,
2965
+ b64stream_data: nil,
2966
+ tags: nil,
2967
+ idempotency_key: nil,
2968
+ delta: nil,
2969
+ version: nil,
2970
+ version_epoch: nil,
2971
+ score: nil,
2972
+ key_mode: nil
2973
+ )
2974
+ add("map_publish", MapPublishResult) do
2975
+ Requests.map_publish(
2976
+ channel,
2977
+ key,
2978
+ data,
2979
+ b64data,
2980
+ stream_data,
2981
+ b64stream_data,
2982
+ tags,
2983
+ idempotency_key,
2984
+ delta,
2985
+ version,
2986
+ version_epoch,
2987
+ score,
2988
+ key_mode
2989
+ )
2990
+ end
2991
+ end
2992
+
2993
+ # Removes a key from a map channel.
2994
+ #
2995
+ # Adds the command to the batch: its Pending holds the result once the batch
2996
+ # is sent.
2997
+ #
2998
+ # @param channel [String, nil] The name of the map channel. Required.
2999
+ # @param key [String, nil] The key to remove. Required.
3000
+ # @param idempotency_key [String, nil] Drops duplicate removals upon retries, as it does for
3001
+ # MapPublishRequest: a removal with a key already used in the channel is
3002
+ # not applied again, and its result is suppressed with suppress_reason
3003
+ # "idempotency". Keys are kept for 5 minutes by default.
3004
+ # @return [Pending<MapRemoveResult>]
3005
+ def map_remove(channel:, key:, idempotency_key: nil)
3006
+ add("map_remove", MapRemoveResult) do
3007
+ Requests.map_remove(channel, key, idempotency_key)
3008
+ end
3009
+ end
3010
+
3011
+ # Reads the current state of a map channel, with
3012
+ # optional pagination.
3013
+ #
3014
+ # Adds the command to the batch: its Pending holds the result once the batch
3015
+ # is sent.
3016
+ #
3017
+ # @param channel [String, nil] The name of the map channel. Required.
3018
+ # @param cursor [String, nil] The pagination cursor from the previous page. Empty starts
3019
+ # from the beginning.
3020
+ # @param limit [Integer, nil] The maximum number of entries per page: -1 means no limit, 0
3021
+ # returns only the stream position. Page sizes may exceed it with the
3022
+ # Redis map broker.
3023
+ # @param key [String, nil] Reads a single entry by exact key. cursor and limit are ignored
3024
+ # when it is set.
3025
+ # @param asc [Boolean, nil] Sorts ordered state by score ascending instead of descending.
3026
+ # Ignored for unordered channels.
3027
+ # @param revision_offset [Integer, nil] The offset of the position from a previous state
3028
+ # read, used with revision_epoch.
3029
+ # @param revision_epoch [String, nil] The epoch of the position from a previous state
3030
+ # read. If the epoch changed, the call fails with an unrecoverable
3031
+ # position error.
3032
+ # @return [Pending<MapReadStateResult>]
3033
+ def map_read_state(
3034
+ channel:,
3035
+ cursor: nil,
3036
+ limit: nil,
3037
+ key: nil,
3038
+ asc: nil,
3039
+ revision_offset: nil,
3040
+ revision_epoch: nil
3041
+ )
3042
+ add("map_read_state", MapReadStateResult) do
3043
+ Requests.map_read_state(
3044
+ channel,
3045
+ cursor,
3046
+ limit,
3047
+ key,
3048
+ asc,
3049
+ revision_offset,
3050
+ revision_epoch
3051
+ )
3052
+ end
3053
+ end
3054
+
3055
+ # Reads the change stream of a map channel.
3056
+ #
3057
+ # Adds the command to the batch: its Pending holds the result once the batch
3058
+ # is sent.
3059
+ #
3060
+ # @param channel [String, nil] The name of the map channel. Required.
3061
+ # @param since_offset [Integer, nil] Returns entries after this offset, used with
3062
+ # since_epoch.
3063
+ # @param since_epoch [String, nil] The epoch of the since position. It must match the
3064
+ # current stream epoch.
3065
+ # @param limit [Integer, nil] The maximum number of entries: -1 means no limit, 0 returns
3066
+ # only the stream position.
3067
+ # @param reverse [Boolean, nil] Returns entries newest first.
3068
+ # @return [Pending<MapReadStreamResult>]
3069
+ def map_read_stream(
3070
+ channel:,
3071
+ since_offset: nil,
3072
+ since_epoch: nil,
3073
+ limit: nil,
3074
+ reverse: nil
3075
+ )
3076
+ add("map_read_stream", MapReadStreamResult) do
3077
+ Requests.map_read_stream(
3078
+ channel,
3079
+ since_offset,
3080
+ since_epoch,
3081
+ limit,
3082
+ reverse
3083
+ )
3084
+ end
3085
+ end
3086
+
3087
+ # Returns statistics about a map channel.
3088
+ #
3089
+ # Adds the command to the batch: its Pending holds the result once the batch
3090
+ # is sent.
3091
+ #
3092
+ # @param channel [String, nil] The name of the map channel. Required.
3093
+ # @return [Pending<MapStatsResult>]
3094
+ def map_stats(channel:)
3095
+ add("map_stats", MapStatsResult) do
3096
+ Requests.map_stats(channel)
3097
+ end
3098
+ end
3099
+
3100
+ # Removes all state and stream data of a map channel.
3101
+ #
3102
+ # Adds the command to the batch: its Pending holds the result once the batch
3103
+ # is sent.
3104
+ #
3105
+ # @param channel [String, nil] The name of the map channel. Required.
3106
+ # @return [Pending<MapClearResult>]
3107
+ def map_clear(channel:)
3108
+ add("map_clear", MapClearResult) do
3109
+ Requests.map_clear(channel)
3110
+ end
3111
+ end
3112
+
3113
+ # Pushes data for a key directly to clients of a
3114
+ # shared poll channel, without waiting for the next poll cycle. Requires
3115
+ # versioned mode and publish_enabled on the namespace.
3116
+ #
3117
+ # Adds the command to the batch: its Pending holds the result once the batch
3118
+ # is sent.
3119
+ #
3120
+ # @param channel [String, nil] The name of the shared poll channel. Required.
3121
+ # @param key [String, nil] The item key. Required.
3122
+ # @param data [Object, nil] The item data, delivered to clients as is.
3123
+ # @param b64data [String, nil] Data as base64, for binary payloads. Centrifugo decodes it.
3124
+ # @param version [Integer, nil] The item version, must be >= 1. Required. A version not
3125
+ # higher than the current one within the same epoch is silently dropped.
3126
+ # @param epoch [String, nil] The channel-level publisher epoch. A change resets per-key
3127
+ # versions and unsubscribes current subscribers with insufficient state.
3128
+ # @return [Pending<SharedPollPublishResult>]
3129
+ def shared_poll_publish(
3130
+ channel:,
3131
+ key:,
3132
+ version:,
3133
+ data: nil,
3134
+ b64data: nil,
3135
+ epoch: nil
3136
+ )
3137
+ add("shared_poll_publish", SharedPollPublishResult) do
3138
+ Requests.shared_poll_publish(
3139
+ channel,
3140
+ key,
3141
+ data,
3142
+ b64data,
3143
+ version,
3144
+ epoch
3145
+ )
3146
+ end
3147
+ end
3148
+ end
3149
+
3150
+ # The commands of Command, one per method of api.proto.
3151
+ #
3152
+ # @api private
3153
+ module CommandMethods
3154
+ # Publishes data into a channel.
3155
+ #
3156
+ # The command making the call, checked as a Client checks it.
3157
+ #
3158
+ # @param channel [String, nil] The name of the channel to publish into. Required.
3159
+ # @param data [Object, nil] The payload to publish. Required unless b64data is set. In the
3160
+ # HTTP API it is any JSON value; over GRPC it may be binary.
3161
+ # @param b64data [String, nil] A base64-encoded binary payload, an alternative to `data` to
3162
+ # send binary over the HTTP API. Centrifugo decodes it before publishing.
3163
+ # @param skip_history [Boolean, nil] Skips adding this publication to the channel history.
3164
+ # @param tags [Hash{String => String}] A map of arbitrary string keys and values attached to the
3165
+ # publication and delivered to clients.
3166
+ # @param idempotency_key [String, nil] Drops duplicate publications upon retries: a
3167
+ # publication with a key already used in the channel is not published
3168
+ # again, and the first one's result is returned. It acts per channel;
3169
+ # results are kept for 5 minutes by default. The memory, Redis and
3170
+ # PostgreSQL brokers keep keys; the NATS broker ignores them.
3171
+ # @param delta [Boolean, nil] Tells Centrifugo to construct a delta update, if possible, when
3172
+ # broadcasting the publication to subscribers.
3173
+ # @param version [Integer, nil] When > 0, the version of the document being sent:
3174
+ # publications with a version less than or equal to one already seen are
3175
+ # ignored. Only works in channels with history enabled.
3176
+ # @param version_epoch [String, nil] The epoch of version. When it changes, Centrifugo
3177
+ # accepts the publication even if its version is lower than before.
3178
+ # @return [Command]
3179
+ # @raise [InvalidRequestError]
3180
+ def publish(
3181
+ channel:,
3182
+ data: nil,
3183
+ b64data: nil,
3184
+ skip_history: nil,
3185
+ tags: nil,
3186
+ idempotency_key: nil,
3187
+ delta: nil,
3188
+ version: nil,
3189
+ version_epoch: nil
3190
+ )
3191
+ build("publish") do
3192
+ Requests.publish(
3193
+ channel,
3194
+ data,
3195
+ b64data,
3196
+ skip_history,
3197
+ tags,
3198
+ idempotency_key,
3199
+ delta,
3200
+ version,
3201
+ version_epoch
3202
+ )
3203
+ end
3204
+ end
3205
+
3206
+ # Publishes the same data into many channels.
3207
+ #
3208
+ # The command making the call, checked as a Client checks it.
3209
+ #
3210
+ # @param channels [Array<String>] The list of channels to publish into. Required.
3211
+ # @param data [Object, nil] The payload to publish into each channel. Required unless
3212
+ # b64data is set. In the HTTP API it is any JSON value; over GRPC it may
3213
+ # be binary.
3214
+ # @param b64data [String, nil] A base64-encoded binary payload, an alternative to `data` to
3215
+ # send binary over the HTTP API. Centrifugo decodes it before publishing.
3216
+ # @param skip_history [Boolean, nil] Skips adding the publications to the channels' history.
3217
+ # @param tags [Hash{String => String}] A map of arbitrary string keys and values attached to each
3218
+ # publication and delivered to clients.
3219
+ # @param idempotency_key [String, nil] Drops duplicate publications upon retries. It acts per
3220
+ # channel: a broadcast retried with the same key is not published again
3221
+ # into the channels which already have it. Results are kept for 5 minutes
3222
+ # by default. The memory, Redis and PostgreSQL brokers keep keys; the
3223
+ # NATS broker ignores them.
3224
+ # @param delta [Boolean, nil] Tells Centrifugo to construct a delta update, if possible, when
3225
+ # broadcasting the publications to subscribers.
3226
+ # @param version [Integer, nil] When > 0, the version of the document being sent:
3227
+ # publications with a version less than or equal to one already seen are
3228
+ # ignored. Only works in channels with history enabled.
3229
+ # @param version_epoch [String, nil] The epoch of version. When it changes, Centrifugo
3230
+ # accepts the publication even if its version is lower than before.
3231
+ # @return [Command]
3232
+ # @raise [InvalidRequestError]
3233
+ def broadcast(
3234
+ channels:,
3235
+ data: nil,
3236
+ b64data: nil,
3237
+ skip_history: nil,
3238
+ tags: nil,
3239
+ idempotency_key: nil,
3240
+ delta: nil,
3241
+ version: nil,
3242
+ version_epoch: nil
3243
+ )
3244
+ build("broadcast") do
3245
+ Requests.broadcast(
3246
+ channels,
3247
+ data,
3248
+ b64data,
3249
+ skip_history,
3250
+ tags,
3251
+ idempotency_key,
3252
+ delta,
3253
+ version,
3254
+ version_epoch
3255
+ )
3256
+ end
3257
+ end
3258
+
3259
+ # Subscribes active sessions of a user to a channel
3260
+ # (server-side subscription). It does not create a streaming subscription
3261
+ # for the caller.
3262
+ #
3263
+ # The command making the call, checked as a Client checks it.
3264
+ #
3265
+ # @param channel [String, nil] The name of the channel to subscribe to. Required.
3266
+ # @param user [String, nil] The ID of the user to subscribe. Required, unless all_users is
3267
+ # used in Centrifugo PRO.
3268
+ # @param expire_at [Integer, nil] The Unix time in seconds when the subscription expires.
3269
+ # @param info [Object, nil] Custom channel info attached to the subscription, used in
3270
+ # presence and join/leave messages.
3271
+ # @param b64info [String, nil] Info as base64, for binary. Centrifugo decodes it.
3272
+ # @param client [String, nil] Limits the call to the connection with this client ID. user is
3273
+ # still required.
3274
+ # @param data [Object, nil] Custom subscription data sent to the client in the Subscribe
3275
+ # push.
3276
+ # @param b64data [String, nil] Data as base64, for binary. Centrifugo decodes it.
3277
+ # @param recover_since [StreamPosition, Hash, nil] The stream position to recover publications from.
3278
+ # @param override [SubscribeOptionOverride, Hash, nil] Dynamically overrides some channel options set in the
3279
+ # Centrifugo configuration.
3280
+ # @param session [String, nil] Limits the call to the connection with this session ID. user
3281
+ # is still required.
3282
+ # @param label_filter [FilterNode, Hash, nil] Restricts the call to clients whose labels match this
3283
+ # filter. Centrifugo PRO only.
3284
+ # @param all_users [Boolean, nil] When user is empty, targets every connection on every node
3285
+ # instead of the anonymous-only bucket. No effect when user is non-empty.
3286
+ # Without label_filter it acts on every connection. Centrifugo PRO only.
3287
+ # @return [Command]
3288
+ # @raise [InvalidRequestError]
3289
+ def subscribe(
3290
+ channel:,
3291
+ user: nil,
3292
+ expire_at: nil,
3293
+ info: nil,
3294
+ b64info: nil,
3295
+ client: nil,
3296
+ data: nil,
3297
+ b64data: nil,
3298
+ recover_since: nil,
3299
+ override: nil,
3300
+ session: nil,
3301
+ label_filter: nil,
3302
+ all_users: nil
3303
+ )
3304
+ build("subscribe") do
3305
+ Requests.subscribe(
3306
+ channel,
3307
+ user,
3308
+ expire_at,
3309
+ info,
3310
+ b64info,
3311
+ client,
3312
+ data,
3313
+ b64data,
3314
+ recover_since,
3315
+ override,
3316
+ session,
3317
+ label_filter,
3318
+ all_users
3319
+ )
3320
+ end
3321
+ end
3322
+
3323
+ # Unsubscribes a user from a channel.
3324
+ #
3325
+ # The command making the call, checked as a Client checks it.
3326
+ #
3327
+ # @param channel [String, nil] The name of the channel to unsubscribe from. Required.
3328
+ # @param user [String, nil] The ID of the user to unsubscribe. Required, unless all_users
3329
+ # is used in Centrifugo PRO.
3330
+ # @param client [String, nil] Limits the call to the connection with this client ID. user is
3331
+ # still required.
3332
+ # @param session [String, nil] Limits the call to the connection with this session ID. user
3333
+ # is still required.
3334
+ # @param label_filter [FilterNode, Hash, nil] Restricts the call to clients whose labels match this
3335
+ # filter. Centrifugo PRO only.
3336
+ # @param all_users [Boolean, nil] Works as SubscribeRequest.all_users. Centrifugo PRO only.
3337
+ # @return [Command]
3338
+ # @raise [InvalidRequestError]
3339
+ def unsubscribe(
3340
+ channel:,
3341
+ user: nil,
3342
+ client: nil,
3343
+ session: nil,
3344
+ label_filter: nil,
3345
+ all_users: nil
3346
+ )
3347
+ build("unsubscribe") do
3348
+ Requests.unsubscribe(
3349
+ channel,
3350
+ user,
3351
+ client,
3352
+ session,
3353
+ label_filter,
3354
+ all_users
3355
+ )
3356
+ end
3357
+ end
3358
+
3359
+ # Disconnects a user's connections.
3360
+ #
3361
+ # The command making the call, checked as a Client checks it.
3362
+ #
3363
+ # @param user [String, nil] The ID of the user to disconnect. Required, unless all_users is
3364
+ # used in Centrifugo PRO.
3365
+ # @param disconnect [Disconnect, Hash, nil] A custom disconnect code and reason. If not set, clients
3366
+ # are disconnected with a force no-reconnect disconnect.
3367
+ # @param client [String, nil] Limits the call to the connection with this client ID. user is
3368
+ # still required.
3369
+ # @param whitelist [Array<String>] A list of client IDs to keep connected.
3370
+ # @param session [String, nil] Limits the call to the connection with this session ID. user
3371
+ # is still required.
3372
+ # @param label_filter [FilterNode, Hash, nil] Restricts the call to clients whose labels match this
3373
+ # filter. Centrifugo PRO only.
3374
+ # @param all_users [Boolean, nil] Works as SubscribeRequest.all_users. Centrifugo PRO only.
3375
+ # @return [Command]
3376
+ # @raise [InvalidRequestError]
3377
+ def disconnect(
3378
+ user: nil,
3379
+ disconnect: nil,
3380
+ client: nil,
3381
+ whitelist: nil,
3382
+ session: nil,
3383
+ label_filter: nil,
3384
+ all_users: nil
3385
+ )
3386
+ build("disconnect") do
3387
+ Requests.disconnect(
3388
+ user,
3389
+ disconnect,
3390
+ client,
3391
+ whitelist,
3392
+ session,
3393
+ label_filter,
3394
+ all_users
3395
+ )
3396
+ end
3397
+ end
3398
+
3399
+ # Returns the online presence of a channel: all clients
3400
+ # currently subscribed to it. Presence must be enabled for the channel.
3401
+ #
3402
+ # The command making the call, checked as a Client checks it.
3403
+ #
3404
+ # @param channel [String, nil] The name of the channel. Required.
3405
+ # @return [Command]
3406
+ # @raise [InvalidRequestError]
3407
+ def presence(channel:)
3408
+ build("presence") do
3409
+ Requests.presence(channel)
3410
+ end
3411
+ end
3412
+
3413
+ # Returns short presence information of a channel: the
3414
+ # number of clients and of unique users. Presence must be enabled for the
3415
+ # channel.
3416
+ #
3417
+ # The command making the call, checked as a Client checks it.
3418
+ #
3419
+ # @param channel [String, nil] The name of the channel. Required.
3420
+ # @return [Command]
3421
+ # @raise [InvalidRequestError]
3422
+ def presence_stats(channel:)
3423
+ build("presence_stats") do
3424
+ Requests.presence_stats(channel)
3425
+ end
3426
+ end
3427
+
3428
+ # Returns publications from the history of a channel.
3429
+ # History must be enabled for the channel.
3430
+ #
3431
+ # The command making the call, checked as a Client checks it.
3432
+ #
3433
+ # @param channel [String, nil] The name of the channel. Required.
3434
+ # @param limit [Integer, nil] The maximum number of publications to return; -1 returns all
3435
+ # the channel keeps. If not set, only the current stream position is
3436
+ # returned, without publications.
3437
+ # @param since [StreamPosition, Hash, nil] Returns publications after this stream position.
3438
+ # @param reverse [Boolean, nil] Iterates in reverse order, from latest to earliest.
3439
+ # @return [Command]
3440
+ # @raise [InvalidRequestError]
3441
+ def history(
3442
+ channel:,
3443
+ limit: nil,
3444
+ since: nil,
3445
+ reverse: nil
3446
+ )
3447
+ build("history") do
3448
+ Requests.history(channel, limit, since, reverse)
3449
+ end
3450
+ end
3451
+
3452
+ # Removes publications from the history of a channel.
3453
+ # The current top stream position is kept, so clients do not get
3454
+ # disconnected because of insufficient state.
3455
+ #
3456
+ # The command making the call, checked as a Client checks it.
3457
+ #
3458
+ # @param channel [String, nil] The name of the channel. Required.
3459
+ # @return [Command]
3460
+ # @raise [InvalidRequestError]
3461
+ def history_remove(channel:)
3462
+ build("history_remove") do
3463
+ Requests.history_remove(channel)
3464
+ end
3465
+ end
3466
+
3467
+ # Returns information about the running Centrifugo nodes.
3468
+ #
3469
+ # The command making the call, checked as a Client checks it.
3470
+ #
3471
+ # @return [Command]
3472
+ # @raise [InvalidRequestError]
3473
+ def info
3474
+ build("info") do
3475
+ Requests.info
3476
+ end
3477
+ end
3478
+
3479
+ # Refreshes a user's connections, mostly useful with
3480
+ # unidirectional transports. Without expire_at the connections become
3481
+ # non-expiring.
3482
+ #
3483
+ # The command making the call, checked as a Client checks it.
3484
+ #
3485
+ # @param user [String, nil] The ID of the user to refresh. Required, unless all_users is
3486
+ # used in Centrifugo PRO.
3487
+ # @param client [String, nil] Limits the call to the connection with this client ID. user is
3488
+ # still required.
3489
+ # @param expired [Boolean, nil] Marks the connections as expired and closes them with an
3490
+ # expired disconnect reason.
3491
+ # @param expire_at [Integer, nil] The Unix time in seconds when the connections expire.
3492
+ # @param info [Object, nil] Attaches or replaces the connection info.
3493
+ # @param session [String, nil] Limits the call to the connection with this session ID. user
3494
+ # is still required.
3495
+ # @param label_filter [FilterNode, Hash, nil] Restricts the call to clients whose labels match this
3496
+ # filter. Centrifugo PRO only.
3497
+ # @param all_users [Boolean, nil] Works as SubscribeRequest.all_users. Centrifugo PRO only.
3498
+ # @return [Command]
3499
+ # @raise [InvalidRequestError]
3500
+ def refresh(
3501
+ user: nil,
3502
+ client: nil,
3503
+ expired: nil,
3504
+ expire_at: nil,
3505
+ info: nil,
3506
+ session: nil,
3507
+ label_filter: nil,
3508
+ all_users: nil
3509
+ )
3510
+ build("refresh") do
3511
+ Requests.refresh(
3512
+ user,
3513
+ client,
3514
+ expired,
3515
+ expire_at,
3516
+ info,
3517
+ session,
3518
+ label_filter,
3519
+ all_users
3520
+ )
3521
+ end
3522
+ end
3523
+
3524
+ # Returns active channels (with one or more subscribers).
3525
+ # It can be heavy on large deployments: there is no pagination.
3526
+ #
3527
+ # The command making the call, checked as a Client checks it.
3528
+ #
3529
+ # @param pattern [String, nil] Filters channels by name, using gobwas/glob syntax.
3530
+ # @return [Command]
3531
+ # @raise [InvalidRequestError]
3532
+ def channels(pattern: nil)
3533
+ build("channels") do
3534
+ Requests.channels(pattern)
3535
+ end
3536
+ end
3537
+
3538
+ # Returns information about active connections, without
3539
+ # the need to enable presence. At least one of user, expression or
3540
+ # label_filter must be set. Centrifugo PRO only.
3541
+ #
3542
+ # The command making the call, checked as a Client checks it.
3543
+ #
3544
+ # @param user [String, nil] Returns only the connections of this user ID.
3545
+ # @param expression [String, nil] A CEL expression to filter connections.
3546
+ # @param label_filter [FilterNode, Hash, nil] Restricts the listing to clients whose labels match this
3547
+ # filter. Centrifugo PRO only.
3548
+ # @return [Command]
3549
+ # @raise [InvalidRequestError]
3550
+ def connections(user: nil, expression: nil, label_filter: nil)
3551
+ build("connections") do
3552
+ Requests.connections(user, expression, label_filter)
3553
+ end
3554
+ end
3555
+
3556
+ # Marks users as active and online now, and sets
3557
+ # their state when one is given. Centrifugo PRO only.
3558
+ #
3559
+ # The command making the call, checked as a Client checks it.
3560
+ #
3561
+ # @param users [Array<String>] The list of user IDs to update the status for. Required.
3562
+ # @param state [String, nil] An optional custom state to store in the user status. It can
3563
+ # be restricted by the user_status.state_regex option.
3564
+ # @return [Command]
3565
+ # @raise [InvalidRequestError]
3566
+ def update_user_status(users:, state: nil)
3567
+ build("update_user_status") do
3568
+ Requests.update_user_status(users, state)
3569
+ end
3570
+ end
3571
+
3572
+ # Returns the status of users. Centrifugo PRO only.
3573
+ #
3574
+ # The command making the call, checked as a Client checks it.
3575
+ #
3576
+ # @param users [Array<String>] The list of user IDs to get the status for. Required.
3577
+ # @return [Command]
3578
+ # @raise [InvalidRequestError]
3579
+ def get_user_status(users:)
3580
+ build("get_user_status") do
3581
+ Requests.get_user_status(users)
3582
+ end
3583
+ end
3584
+
3585
+ # Deletes the status of users. Centrifugo PRO only.
3586
+ #
3587
+ # The command making the call, checked as a Client checks it.
3588
+ #
3589
+ # @param users [Array<String>] The list of user IDs to delete the status for. Required.
3590
+ # @return [Command]
3591
+ # @raise [InvalidRequestError]
3592
+ def delete_user_status(users:)
3593
+ build("delete_user_status") do
3594
+ Requests.delete_user_status(users)
3595
+ end
3596
+ end
3597
+
3598
+ # Blocks a user: the user is disconnected and can not
3599
+ # connect again until unblocked or the block expires. Centrifugo PRO only.
3600
+ #
3601
+ # The command making the call, checked as a Client checks it.
3602
+ #
3603
+ # @param expire_at [Integer, nil] The Unix time in seconds when the block expires. Optional,
3604
+ # but a reasonably small value is recommended to keep the set of blocked
3605
+ # users small.
3606
+ # @param user [String, nil] The ID of the user to block. Required.
3607
+ # @return [Command]
3608
+ # @raise [InvalidRequestError]
3609
+ def block_user(user:, expire_at: nil)
3610
+ build("block_user") do
3611
+ Requests.block_user(expire_at, user)
3612
+ end
3613
+ end
3614
+
3615
+ # Unblocks a user. Centrifugo PRO only.
3616
+ #
3617
+ # The command making the call, checked as a Client checks it.
3618
+ #
3619
+ # @param user [String, nil] The ID of the user to unblock. Required.
3620
+ # @return [Command]
3621
+ # @raise [InvalidRequestError]
3622
+ def unblock_user(user:)
3623
+ build("unblock_user") do
3624
+ Requests.unblock_user(user)
3625
+ end
3626
+ end
3627
+
3628
+ # Revokes a token by its unique ID (jti claim of a JWT).
3629
+ # Clients using the token are disconnected shortly, and can not connect
3630
+ # with it again. Centrifugo PRO only.
3631
+ #
3632
+ # The command making the call, checked as a Client checks it.
3633
+ #
3634
+ # @param expire_at [Integer, nil] The Unix time in seconds when the revocation expires.
3635
+ # Optional, but a value matching the token expiration is recommended.
3636
+ # @param uid [String, nil] The unique ID of the token to revoke (jti claim). Required.
3637
+ # @return [Command]
3638
+ # @raise [InvalidRequestError]
3639
+ def revoke_token(uid:, expire_at: nil)
3640
+ build("revoke_token") do
3641
+ Requests.revoke_token(expire_at, uid)
3642
+ end
3643
+ end
3644
+
3645
+ # Revokes all tokens of a user issued before a
3646
+ # certain time (based on the iat claim of a JWT). Centrifugo PRO only.
3647
+ #
3648
+ # The command making the call, checked as a Client checks it.
3649
+ #
3650
+ # @param expire_at [Integer, nil] The Unix time in seconds when the invalidation expires.
3651
+ # Optional, but a value matching the token expiration is recommended.
3652
+ # @param user [String, nil] The ID of the user whose tokens to invalidate. Required. ""
3653
+ # invalidates the tokens of anonymous users.
3654
+ # @param issued_before [Integer, nil] The Unix time in seconds: tokens issued before it are
3655
+ # considered revoked. If not set, the current time is used.
3656
+ # @param channel [String, nil] Limits the invalidation to subscription tokens for this
3657
+ # channel.
3658
+ # @return [Command]
3659
+ # @raise [InvalidRequestError]
3660
+ def invalidate_user_tokens(
3661
+ user:,
3662
+ expire_at: nil,
3663
+ issued_before: nil,
3664
+ channel: nil
3665
+ )
3666
+ build("invalidate_user_tokens") do
3667
+ Requests.invalidate_user_tokens(expire_at, user, issued_before, channel)
3668
+ end
3669
+ end
3670
+
3671
+ # Registers a device for push notifications, or
3672
+ # updates a registered one. Centrifugo PRO only.
3673
+ #
3674
+ # The command making the call, checked as a Client checks it.
3675
+ #
3676
+ # @param id [String, nil] The device ID. Omit it on first registration: Centrifugo
3677
+ # generates one and returns it. Pass the stored value to update the
3678
+ # device.
3679
+ # @param provider [String, nil] The provider of the device token. Required. One of: fcm,
3680
+ # hms, apns, webpush.
3681
+ # @param token [String, nil] The push token of the device. For webpush, it is the browser
3682
+ # PushSubscription serialized as a JSON string. Required.
3683
+ # @param platform [String, nil] The device platform. Required. One of: ios, android, web.
3684
+ # @param user [String, nil] The user associated with the device.
3685
+ # @param meta [Hash{String => String}] Additional custom metadata of the device.
3686
+ # @param topics [Array<String>] The full list of the device's topic subscriptions, replacing
3687
+ # the previous one. The user's topics are attached automatically.
3688
+ # @param timezone [String, nil] The IANA time zone of the device user, for example
3689
+ # Europe/Nicosia.
3690
+ # @param locale [String, nil] The locale of the device user as an IETF BCP 47 language
3691
+ # tag, for example en-US.
3692
+ # @return [Command]
3693
+ # @raise [InvalidRequestError]
3694
+ def device_register(
3695
+ provider:,
3696
+ token:,
3697
+ platform:,
3698
+ id: nil,
3699
+ user: nil,
3700
+ meta: nil,
3701
+ topics: nil,
3702
+ timezone: nil,
3703
+ locale: nil
3704
+ )
3705
+ build("device_register") do
3706
+ Requests.device_register(
3707
+ id,
3708
+ provider,
3709
+ token,
3710
+ platform,
3711
+ user,
3712
+ meta,
3713
+ topics,
3714
+ timezone,
3715
+ locale
3716
+ )
3717
+ end
3718
+ end
3719
+
3720
+ # Updates registered devices, selected by ids and/or
3721
+ # users. Centrifugo PRO only.
3722
+ #
3723
+ # The command making the call, checked as a Client checks it.
3724
+ #
3725
+ # @param ids [Array<String>] Selects devices by ID.
3726
+ # @param users [Array<String>] Selects devices by user.
3727
+ # @param user_update [DeviceUserUpdate, Hash, nil] Changes the user ID of the devices. It does not re-sync
3728
+ # user-bound topics; use DeviceRegisterRequest to assign a device to
3729
+ # another user.
3730
+ # @param meta_update [DeviceMetaUpdate, Hash, nil] Updates the device meta.
3731
+ # @param topics_update [DeviceTopicsUpdate, Hash, nil] Updates the device topics.
3732
+ # @param timezone_update [DeviceTimezoneUpdate, Hash, nil] Updates the device timezone.
3733
+ # @param locale_update [DeviceLocaleUpdate, Hash, nil] Updates the device locale.
3734
+ # @return [Command]
3735
+ # @raise [InvalidRequestError]
3736
+ def device_update(
3737
+ ids: nil,
3738
+ users: nil,
3739
+ user_update: nil,
3740
+ meta_update: nil,
3741
+ topics_update: nil,
3742
+ timezone_update: nil,
3743
+ locale_update: nil
3744
+ )
3745
+ build("device_update") do
3746
+ Requests.device_update(
3747
+ ids,
3748
+ users,
3749
+ user_update,
3750
+ meta_update,
3751
+ topics_update,
3752
+ timezone_update,
3753
+ locale_update
3754
+ )
3755
+ end
3756
+ end
3757
+
3758
+ # Removes devices, selected by ids and/or users.
3759
+ # Centrifugo PRO only.
3760
+ #
3761
+ # The command making the call, checked as a Client checks it.
3762
+ #
3763
+ # @param ids [Array<String>] Selects devices to remove by ID.
3764
+ # @param users [Array<String>] Selects devices to remove by user.
3765
+ # @return [Command]
3766
+ # @raise [InvalidRequestError]
3767
+ def device_remove(ids: nil, users: nil)
3768
+ build("device_remove") do
3769
+ Requests.device_remove(ids, users)
3770
+ end
3771
+ end
3772
+
3773
+ # Returns a paginated list of registered devices.
3774
+ # Centrifugo PRO only.
3775
+ #
3776
+ # The command making the call, checked as a Client checks it.
3777
+ #
3778
+ # @param filter [DeviceFilter, Hash, nil] Selects the devices to list: all of them when unset.
3779
+ # @param include_total_count [Boolean, nil] Includes the total count for the filter in the
3780
+ # result.
3781
+ # @param include_meta [Boolean, nil] Includes meta of each device.
3782
+ # @param include_topics [Boolean, nil] Includes topics of each device.
3783
+ # @param include_webpush_keys [Boolean, nil] Includes webpush_keys of each device (webpush
3784
+ # only).
3785
+ # @param cursor [String, nil] The pagination cursor: next_cursor of the previous page,
3786
+ # empty for the first page.
3787
+ # @param limit [Integer, nil] The maximum number of devices to return.
3788
+ # @return [Command]
3789
+ # @raise [InvalidRequestError]
3790
+ def device_list(
3791
+ filter: nil,
3792
+ include_total_count: nil,
3793
+ include_meta: nil,
3794
+ include_topics: nil,
3795
+ include_webpush_keys: nil,
3796
+ cursor: nil,
3797
+ limit: nil
3798
+ )
3799
+ build("device_list") do
3800
+ Requests.device_list(
3801
+ filter,
3802
+ include_total_count,
3803
+ include_meta,
3804
+ include_topics,
3805
+ include_webpush_keys,
3806
+ cursor,
3807
+ limit
3808
+ )
3809
+ end
3810
+ end
3811
+
3812
+ # Returns a paginated list of device topic
3813
+ # subscriptions. Centrifugo PRO only.
3814
+ #
3815
+ # The command making the call, checked as a Client checks it.
3816
+ #
3817
+ # @param filter [DeviceTopicFilter, Hash, nil] Selects the device topics to list.
3818
+ # @param include_total_count [Boolean, nil] Includes the total count for the filter in the
3819
+ # result.
3820
+ # @param include_device [Boolean, nil] Includes the Device of each item.
3821
+ # @param cursor [String, nil] The pagination cursor: next_cursor of the previous page,
3822
+ # empty for the first page.
3823
+ # @param limit [Integer, nil] The maximum number of items to return.
3824
+ # @return [Command]
3825
+ # @raise [InvalidRequestError]
3826
+ def device_topic_list(
3827
+ filter: nil,
3828
+ include_total_count: nil,
3829
+ include_device: nil,
3830
+ cursor: nil,
3831
+ limit: nil
3832
+ )
3833
+ build("device_topic_list") do
3834
+ Requests.device_topic_list(
3835
+ filter,
3836
+ include_total_count,
3837
+ include_device,
3838
+ cursor,
3839
+ limit
3840
+ )
3841
+ end
3842
+ end
3843
+
3844
+ # Changes the topics of a device. The device topic
3845
+ # list is what decides who gets a push sent to a topic.
3846
+ # Centrifugo PRO only.
3847
+ #
3848
+ # The command making the call, checked as a Client checks it.
3849
+ #
3850
+ # @param device_id [String, nil] The ID of the device. Required.
3851
+ # @param op [String, nil] The operation. Required. One of: add, remove, set.
3852
+ # @param topics [Array<String>] The topics for the operation.
3853
+ # @param user [String, nil] An optional ownership guard: the update is applied only if the
3854
+ # device currently belongs to this user. Otherwise the call fails with a
3855
+ # conflict error (or not found if there is no such device).
3856
+ # @return [Command]
3857
+ # @raise [InvalidRequestError]
3858
+ def device_topic_update(
3859
+ device_id:,
3860
+ op:,
3861
+ topics: nil,
3862
+ user: nil
3863
+ )
3864
+ build("device_topic_update") do
3865
+ Requests.device_topic_update(device_id, op, topics, user)
3866
+ end
3867
+ end
3868
+
3869
+ # Returns a paginated list of user topic
3870
+ # subscriptions. Centrifugo PRO only.
3871
+ #
3872
+ # The command making the call, checked as a Client checks it.
3873
+ #
3874
+ # @param filter [UserTopicFilter, Hash, nil] Selects the user topics to list.
3875
+ # @param include_total_count [Boolean, nil] Includes the total count for the filter in the
3876
+ # result.
3877
+ # @param cursor [String, nil] The pagination cursor: next_cursor of the previous page,
3878
+ # empty for the first page.
3879
+ # @param limit [Integer, nil] The maximum number of items to return.
3880
+ # @return [Command]
3881
+ # @raise [InvalidRequestError]
3882
+ def user_topic_list(
3883
+ filter: nil,
3884
+ include_total_count: nil,
3885
+ cursor: nil,
3886
+ limit: nil
3887
+ )
3888
+ build("user_topic_list") do
3889
+ Requests.user_topic_list(filter, include_total_count, cursor, limit)
3890
+ end
3891
+ end
3892
+
3893
+ # Changes the topics of a user. The change is also
3894
+ # applied to the user's registered devices. Centrifugo PRO only.
3895
+ #
3896
+ # The command making the call, checked as a Client checks it.
3897
+ #
3898
+ # @param user [String, nil] The user ID. Required. "" updates the global binding, which every
3899
+ # device - anonymous ones included - gets on its next device_register.
3900
+ # @param op [String, nil] The operation. Required. One of: add, remove, set.
3901
+ # @param topics [Array<String>] The topics for the operation.
3902
+ # @return [Command]
3903
+ # @raise [InvalidRequestError]
3904
+ def user_topic_update(user:, op:, topics: nil)
3905
+ build("user_topic_update") do
3906
+ Requests.user_topic_update(user, op, topics)
3907
+ end
3908
+ end
3909
+
3910
+ # Sends a push notification. The request is
3911
+ # queued and sent to the provider by Centrifugo workers.
3912
+ # Centrifugo PRO only.
3913
+ #
3914
+ # The command making the call, checked as a Client checks it.
3915
+ #
3916
+ # @param recipient [PushRecipient, Hash, nil] Who receives the notification. Required.
3917
+ # @param notification [PushNotification, Hash, nil] The notification to send. Required.
3918
+ # @param uid [String, nil] A unique identifier of the request, can be used to cancel the
3919
+ # push. UUID v4 is recommended; different requests must use different
3920
+ # uids.
3921
+ # @param send_at [Integer, nil] The Unix time in seconds when to send the notification. If
3922
+ # not set, the notification is sent immediately.
3923
+ # @param optimize_for_reliability [Boolean, nil] Makes processing heavier, but tolerates edge
3924
+ # cases, like not losing inflight pushes when the queue is briefly
3925
+ # unavailable.
3926
+ # @param limit_strategy [PushLimitStrategy, Hash, nil] Sets time constraints and rate limits. Only applies
3927
+ # with a filter recipient; devices are then processed one by one
3928
+ # instead of in batches. Needs notification.expire_at: a push the limits
3929
+ # hold back is not tried forever.
3930
+ # @param analytics_uid [String, nil] The identifier for push notification analytics. If
3931
+ # not set, uid is used.
3932
+ # @param localizations [Hash{String => PushLocalization, Hash}] Optional per language/locale localizations. Setting
3933
+ # them enables templating.
3934
+ # @param use_templating [Boolean, nil] Enables templating of the notification. Only works
3935
+ # with a filter recipient.
3936
+ # @param use_meta [Boolean, nil] Additionally loads device meta while sending, making it
3937
+ # available in templating.
3938
+ # @return [Command]
3939
+ # @raise [InvalidRequestError]
3940
+ def send_push_notification(
3941
+ recipient:,
3942
+ notification:,
3943
+ uid: nil,
3944
+ send_at: nil,
3945
+ optimize_for_reliability: nil,
3946
+ limit_strategy: nil,
3947
+ analytics_uid: nil,
3948
+ localizations: nil,
3949
+ use_templating: nil,
3950
+ use_meta: nil
3951
+ )
3952
+ build("send_push_notification") do
3953
+ Requests.send_push_notification(
3954
+ recipient,
3955
+ notification,
3956
+ uid,
3957
+ send_at,
3958
+ optimize_for_reliability,
3959
+ limit_strategy,
3960
+ analytics_uid,
3961
+ localizations,
3962
+ use_templating,
3963
+ use_meta
3964
+ )
3965
+ end
3966
+ end
3967
+
3968
+ # Saves the delivery or interaction status of a
3969
+ # push notification to analytics. Experimental. Centrifugo PRO only.
3970
+ #
3971
+ # The command making the call, checked as a Client checks it.
3972
+ #
3973
+ # @param analytics_uid [String, nil] The analytics_uid of the push notification (as in
3974
+ # SendPushNotificationRequest). Required.
3975
+ # @param status [String, nil] The status of the push notification. Required. One of:
3976
+ # delivered, interacted.
3977
+ # @param device_id [String, nil] The Centrifugo device ID. Required.
3978
+ # @param msg_id [String, nil] The message ID issued by the provider.
3979
+ # @return [Command]
3980
+ # @raise [InvalidRequestError]
3981
+ def update_push_status(
3982
+ analytics_uid:,
3983
+ status:,
3984
+ device_id:,
3985
+ msg_id: nil
3986
+ )
3987
+ build("update_push_status") do
3988
+ Requests.update_push_status(analytics_uid, status, device_id, msg_id)
3989
+ end
3990
+ end
3991
+
3992
+ # Cancels a delayed push notification (sent with
3993
+ # send_at). Centrifugo PRO only.
3994
+ #
3995
+ # The command making the call, checked as a Client checks it.
3996
+ #
3997
+ # @param uid [String, nil] The uid of the push notification to cancel. Required.
3998
+ # @return [Command]
3999
+ # @raise [InvalidRequestError]
4000
+ def cancel_push(uid:)
4001
+ build("cancel_push") do
4002
+ Requests.cancel_push(uid)
4003
+ end
4004
+ end
4005
+
4006
+ # Publishes or updates a key in a map channel.
4007
+ #
4008
+ # The command making the call, checked as a Client checks it.
4009
+ #
4010
+ # @param channel [String, nil] The name of the map channel. Required.
4011
+ # @param key [String, nil] The entry key. Required.
4012
+ # @param data [Object, nil] The entry data. In the HTTP API it is any JSON value; over GRPC
4013
+ # it may be binary.
4014
+ # @param b64data [String, nil] Data as base64, for binary over the HTTP API. Centrifugo
4015
+ # decodes it.
4016
+ # @param stream_data [Object, nil] Currently not used by the server API.
4017
+ # @param b64stream_data [String, nil] Currently not used by the server API.
4018
+ # @param tags [Hash{String => String}] Key-value metadata attached to the publication.
4019
+ # @param idempotency_key [String, nil] Drops duplicate publications upon retries: a
4020
+ # publication with a key already used in the channel is not applied
4021
+ # again, and its result has the first one's position, with suppressed
4022
+ # set and suppress_reason "idempotency". It acts per channel; keys are
4023
+ # kept for 5 minutes by default. Every map broker - memory, Redis and
4024
+ # PostgreSQL - keeps keys.
4025
+ # @param delta [Boolean, nil] Enables delta compression for this publication.
4026
+ # @param version [Integer, nil] A per-key version: publications with a version not higher
4027
+ # than the key's current one are suppressed.
4028
+ # @param version_epoch [String, nil] Scopes version. A different epoch resets version
4029
+ # comparison.
4030
+ # @param score [Integer, nil] Currently not used by the server API.
4031
+ # @param key_mode [String, nil] Makes the publish conditional: if_new writes only if the key
4032
+ # does not exist, if_exists only if it exists. Empty always writes.
4033
+ # One of: if_new, if_exists.
4034
+ # @return [Command]
4035
+ # @raise [InvalidRequestError]
4036
+ def map_publish(
4037
+ channel:,
4038
+ key:,
4039
+ data: nil,
4040
+ b64data: nil,
4041
+ stream_data: nil,
4042
+ b64stream_data: nil,
4043
+ tags: nil,
4044
+ idempotency_key: nil,
4045
+ delta: nil,
4046
+ version: nil,
4047
+ version_epoch: nil,
4048
+ score: nil,
4049
+ key_mode: nil
4050
+ )
4051
+ build("map_publish") do
4052
+ Requests.map_publish(
4053
+ channel,
4054
+ key,
4055
+ data,
4056
+ b64data,
4057
+ stream_data,
4058
+ b64stream_data,
4059
+ tags,
4060
+ idempotency_key,
4061
+ delta,
4062
+ version,
4063
+ version_epoch,
4064
+ score,
4065
+ key_mode
4066
+ )
4067
+ end
4068
+ end
4069
+
4070
+ # Removes a key from a map channel.
4071
+ #
4072
+ # The command making the call, checked as a Client checks it.
4073
+ #
4074
+ # @param channel [String, nil] The name of the map channel. Required.
4075
+ # @param key [String, nil] The key to remove. Required.
4076
+ # @param idempotency_key [String, nil] Drops duplicate removals upon retries, as it does for
4077
+ # MapPublishRequest: a removal with a key already used in the channel is
4078
+ # not applied again, and its result is suppressed with suppress_reason
4079
+ # "idempotency". Keys are kept for 5 minutes by default.
4080
+ # @return [Command]
4081
+ # @raise [InvalidRequestError]
4082
+ def map_remove(channel:, key:, idempotency_key: nil)
4083
+ build("map_remove") do
4084
+ Requests.map_remove(channel, key, idempotency_key)
4085
+ end
4086
+ end
4087
+
4088
+ # Reads the current state of a map channel, with
4089
+ # optional pagination.
4090
+ #
4091
+ # The command making the call, checked as a Client checks it.
4092
+ #
4093
+ # @param channel [String, nil] The name of the map channel. Required.
4094
+ # @param cursor [String, nil] The pagination cursor from the previous page. Empty starts
4095
+ # from the beginning.
4096
+ # @param limit [Integer, nil] The maximum number of entries per page: -1 means no limit, 0
4097
+ # returns only the stream position. Page sizes may exceed it with the
4098
+ # Redis map broker.
4099
+ # @param key [String, nil] Reads a single entry by exact key. cursor and limit are ignored
4100
+ # when it is set.
4101
+ # @param asc [Boolean, nil] Sorts ordered state by score ascending instead of descending.
4102
+ # Ignored for unordered channels.
4103
+ # @param revision_offset [Integer, nil] The offset of the position from a previous state
4104
+ # read, used with revision_epoch.
4105
+ # @param revision_epoch [String, nil] The epoch of the position from a previous state
4106
+ # read. If the epoch changed, the call fails with an unrecoverable
4107
+ # position error.
4108
+ # @return [Command]
4109
+ # @raise [InvalidRequestError]
4110
+ def map_read_state(
4111
+ channel:,
4112
+ cursor: nil,
4113
+ limit: nil,
4114
+ key: nil,
4115
+ asc: nil,
4116
+ revision_offset: nil,
4117
+ revision_epoch: nil
4118
+ )
4119
+ build("map_read_state") do
4120
+ Requests.map_read_state(
4121
+ channel,
4122
+ cursor,
4123
+ limit,
4124
+ key,
4125
+ asc,
4126
+ revision_offset,
4127
+ revision_epoch
4128
+ )
4129
+ end
4130
+ end
4131
+
4132
+ # Reads the change stream of a map channel.
4133
+ #
4134
+ # The command making the call, checked as a Client checks it.
4135
+ #
4136
+ # @param channel [String, nil] The name of the map channel. Required.
4137
+ # @param since_offset [Integer, nil] Returns entries after this offset, used with
4138
+ # since_epoch.
4139
+ # @param since_epoch [String, nil] The epoch of the since position. It must match the
4140
+ # current stream epoch.
4141
+ # @param limit [Integer, nil] The maximum number of entries: -1 means no limit, 0 returns
4142
+ # only the stream position.
4143
+ # @param reverse [Boolean, nil] Returns entries newest first.
4144
+ # @return [Command]
4145
+ # @raise [InvalidRequestError]
4146
+ def map_read_stream(
4147
+ channel:,
4148
+ since_offset: nil,
4149
+ since_epoch: nil,
4150
+ limit: nil,
4151
+ reverse: nil
4152
+ )
4153
+ build("map_read_stream") do
4154
+ Requests.map_read_stream(
4155
+ channel,
4156
+ since_offset,
4157
+ since_epoch,
4158
+ limit,
4159
+ reverse
4160
+ )
4161
+ end
4162
+ end
4163
+
4164
+ # Returns statistics about a map channel.
4165
+ #
4166
+ # The command making the call, checked as a Client checks it.
4167
+ #
4168
+ # @param channel [String, nil] The name of the map channel. Required.
4169
+ # @return [Command]
4170
+ # @raise [InvalidRequestError]
4171
+ def map_stats(channel:)
4172
+ build("map_stats") do
4173
+ Requests.map_stats(channel)
4174
+ end
4175
+ end
4176
+
4177
+ # Removes all state and stream data of a map channel.
4178
+ #
4179
+ # The command making the call, checked as a Client checks it.
4180
+ #
4181
+ # @param channel [String, nil] The name of the map channel. Required.
4182
+ # @return [Command]
4183
+ # @raise [InvalidRequestError]
4184
+ def map_clear(channel:)
4185
+ build("map_clear") do
4186
+ Requests.map_clear(channel)
4187
+ end
4188
+ end
4189
+
4190
+ # Pushes data for a key directly to clients of a
4191
+ # shared poll channel, without waiting for the next poll cycle. Requires
4192
+ # versioned mode and publish_enabled on the namespace.
4193
+ #
4194
+ # The command making the call, checked as a Client checks it.
4195
+ #
4196
+ # @param channel [String, nil] The name of the shared poll channel. Required.
4197
+ # @param key [String, nil] The item key. Required.
4198
+ # @param data [Object, nil] The item data, delivered to clients as is.
4199
+ # @param b64data [String, nil] Data as base64, for binary payloads. Centrifugo decodes it.
4200
+ # @param version [Integer, nil] The item version, must be >= 1. Required. A version not
4201
+ # higher than the current one within the same epoch is silently dropped.
4202
+ # @param epoch [String, nil] The channel-level publisher epoch. A change resets per-key
4203
+ # versions and unsubscribes current subscribers with insufficient state.
4204
+ # @return [Command]
4205
+ # @raise [InvalidRequestError]
4206
+ def shared_poll_publish(
4207
+ channel:,
4208
+ key:,
4209
+ version:,
4210
+ data: nil,
4211
+ b64data: nil,
4212
+ epoch: nil
4213
+ )
4214
+ build("shared_poll_publish") do
4215
+ Requests.shared_poll_publish(
4216
+ channel,
4217
+ key,
4218
+ data,
4219
+ b64data,
4220
+ version,
4221
+ epoch
4222
+ )
4223
+ end
4224
+ end
4225
+ end
4226
+ end