stream-chat-ruby 2.22.0 → 2.23.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.
@@ -22,7 +22,6 @@ module StreamChat
22
22
 
23
23
  class Client
24
24
  extend T::Sig
25
- T::Configuration.default_checked_level = :never
26
25
  # For now we disable runtime type checks.
27
26
  # We will enable it with a major bump in the future,
28
27
  # but for now, let's just run a static type check.
@@ -30,13 +29,13 @@ module StreamChat
30
29
  DEFAULT_BASE_URL = 'https://chat.stream-io-api.com'
31
30
  DEFAULT_TIMEOUT = 6.0
32
31
 
33
- sig { returns(String) }
32
+ T::Sig::WithoutRuntime.sig { returns(String) }
34
33
  attr_reader :api_key
35
34
 
36
- sig { returns(String) }
35
+ T::Sig::WithoutRuntime.sig { returns(String) }
37
36
  attr_reader :api_secret
38
37
 
39
- sig { returns(Faraday::Connection) }
38
+ T::Sig::WithoutRuntime.sig { returns(Faraday::Connection) }
40
39
  attr_reader :conn
41
40
 
42
41
  # initializes a Stream Chat API Client
@@ -49,7 +48,7 @@ module StreamChat
49
48
  # @example initialized the client with a timeout setting
50
49
  # StreamChat::Client.new('my_key', 'my_secret', 3.0)
51
50
  #
52
- sig { params(api_key: String, api_secret: String, timeout: T.nilable(T.any(Float, String)), options: T.untyped).void }
51
+ T::Sig::WithoutRuntime.sig { params(api_key: String, api_secret: String, timeout: T.nilable(T.any(Float, String)), options: T.untyped).void }
53
52
  def initialize(api_key, api_secret, timeout = nil, **options)
54
53
  raise ArgumentError, 'api_key and api_secret are required' if api_key.to_s.empty? || api_secret.to_s.empty?
55
54
 
@@ -74,23 +73,29 @@ module StreamChat
74
73
  # environmental variables. STREAM_CHAT_TIMEOUT and STREAM_CHAT_URL
75
74
  # variables are optional.
76
75
  # @param [StringKeyHash] options extra options
77
- sig { params(options: T.untyped).returns(Client) }
76
+ T::Sig::WithoutRuntime.sig { params(options: T.untyped).returns(Client) }
78
77
  def self.from_env(**options)
79
- Client.new(T.must(ENV['STREAM_KEY']),
80
- T.must(ENV['STREAM_SECRET']),
81
- ENV['STREAM_CHAT_TIMEOUT'],
82
- **{ base_url: ENV['STREAM_CHAT_URL'] }.merge(options))
78
+ Client.new(ENV.fetch('STREAM_KEY'),
79
+ ENV.fetch('STREAM_SECRET'),
80
+ ENV.fetch('STREAM_CHAT_TIMEOUT', DEFAULT_TIMEOUT),
81
+ **{ base_url: ENV.fetch('STREAM_CHAT_URL', DEFAULT_BASE_URL) }.merge(options))
83
82
  end
84
83
 
85
84
  # Sets the underlying Faraday http client.
86
85
  #
87
86
  # @param [client] an instance of Faraday::Connection
88
- sig { params(client: Faraday::Connection).void }
87
+ T::Sig::WithoutRuntime.sig { params(client: Faraday::Connection).void }
89
88
  def set_http_client(client)
90
89
  @conn = client
91
90
  end
92
91
 
93
- sig { params(user_id: String, exp: T.nilable(Integer), iat: T.nilable(Integer)).returns(String) }
92
+ # Creates a JWT for a user.
93
+ #
94
+ # Stream uses JWT (JSON Web Tokens) to authenticate chat users, enabling them to login.
95
+ # Knowing whether a user is authorized to perform certain actions is managed
96
+ # separately via a role based permissions system.
97
+ # You can set an `exp` (expires at) or `iat` (issued at) claim as well.
98
+ T::Sig::WithoutRuntime.sig { params(user_id: String, exp: T.nilable(Integer), iat: T.nilable(Integer)).returns(String) }
94
99
  def create_token(user_id, exp = nil, iat = nil)
95
100
  payload = { user_id: user_id }
96
101
  payload['exp'] = exp unless exp.nil?
@@ -98,29 +103,42 @@ module StreamChat
98
103
  JWT.encode(payload, @api_secret, 'HS256')
99
104
  end
100
105
 
101
- sig { params(settings: T.untyped).returns(StreamChat::StreamResponse) }
106
+ # Updates application settings.
107
+ T::Sig::WithoutRuntime.sig { params(settings: T.untyped).returns(StreamChat::StreamResponse) }
102
108
  def update_app_settings(**settings)
103
109
  patch('app', data: settings)
104
110
  end
105
111
 
106
- sig { returns(StreamChat::StreamResponse) }
112
+ # Returns application settings.
113
+ T::Sig::WithoutRuntime.sig { returns(StreamChat::StreamResponse) }
107
114
  def get_app_settings
108
115
  get('app')
109
116
  end
110
117
 
111
- sig { params(id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
118
+ # Flags a message.
119
+ #
120
+ # Any user is allowed to flag a message. This triggers the message.flagged
121
+ # webhook event and adds the message to the inbox of your
122
+ # Stream Dashboard Chat Moderation view.
123
+ T::Sig::WithoutRuntime.sig { params(id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
112
124
  def flag_message(id, **options)
113
125
  payload = { target_message_id: id }.merge(options)
114
126
  post('moderation/flag', data: payload)
115
127
  end
116
128
 
117
- sig { params(id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
129
+ # Unflags a message.
130
+ T::Sig::WithoutRuntime.sig { params(id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
118
131
  def unflag_message(id, **options)
119
132
  payload = { target_message_id: id }.merge(options)
120
133
  post('moderation/unflag', data: payload)
121
134
  end
122
135
 
123
- sig { params(filter_conditions: StringKeyHash, options: T.untyped).returns(StreamChat::StreamResponse) }
136
+ # Queries message flags.
137
+ #
138
+ # If you prefer to build your own in app moderation dashboard, rather than use the Stream
139
+ # dashboard, then the query message flags endpoint lets you get flagged messages. Similar
140
+ # to other queries in Stream Chat, you can filter the flags using query operators.
141
+ T::Sig::WithoutRuntime.sig { params(filter_conditions: StringKeyHash, options: T.untyped).returns(StreamChat::StreamResponse) }
124
142
  def query_message_flags(filter_conditions, **options)
125
143
  params = options.merge({
126
144
  filter_conditions: filter_conditions
@@ -128,25 +146,29 @@ module StreamChat
128
146
  get('moderation/flags/message', params: { payload: params.to_json })
129
147
  end
130
148
 
131
- sig { params(id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
149
+ # Flags a user.
150
+ T::Sig::WithoutRuntime.sig { params(id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
132
151
  def flag_user(id, **options)
133
152
  payload = { target_user_id: id }.merge(options)
134
153
  post('moderation/flag', data: payload)
135
154
  end
136
155
 
137
- sig { params(id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
156
+ # Unflags a user.
157
+ T::Sig::WithoutRuntime.sig { params(id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
138
158
  def unflag_user(id, **options)
139
159
  payload = { target_user_id: id }.merge(options)
140
160
  post('moderation/unflag', data: payload)
141
161
  end
142
162
 
143
- sig { params(options: T.untyped).returns(StreamChat::StreamResponse) }
163
+ # Queries flag reports.
164
+ T::Sig::WithoutRuntime.sig { params(options: T.untyped).returns(StreamChat::StreamResponse) }
144
165
  def query_flag_reports(**options)
145
166
  data = { filter_conditions: options }
146
167
  post('moderation/reports', data: data)
147
168
  end
148
169
 
149
- sig { params(report_id: String, review_result: String, user_id: String, details: T.untyped).returns(StreamChat::StreamResponse) }
170
+ # Sends a flag report review.
171
+ T::Sig::WithoutRuntime.sig { params(report_id: String, review_result: String, user_id: String, details: T.untyped).returns(StreamChat::StreamResponse) }
150
172
  def review_flag_report(report_id, review_result, user_id, **details)
151
173
  data = {
152
174
  review_result: review_result,
@@ -156,12 +178,17 @@ module StreamChat
156
178
  patch("moderation/reports/#{report_id}", data: data)
157
179
  end
158
180
 
159
- sig { params(id: String).returns(StreamChat::StreamResponse) }
181
+ # Returns a message.
182
+ T::Sig::WithoutRuntime.sig { params(id: String).returns(StreamChat::StreamResponse) }
160
183
  def get_message(id)
161
184
  get("messages/#{id}")
162
185
  end
163
186
 
164
- sig { params(filter_conditions: StringKeyHash, query: T.any(String, StringKeyHash), sort: T.nilable(T::Hash[String, Integer]), options: T.untyped).returns(StreamChat::StreamResponse) }
187
+ # Searches for messages.
188
+ #
189
+ # You can enable and/or disable the search indexing on a per channel basis
190
+ # type through the Stream Dashboard.
191
+ T::Sig::WithoutRuntime.sig { params(filter_conditions: StringKeyHash, query: T.any(String, StringKeyHash), sort: T.nilable(T::Hash[String, Integer]), options: T.untyped).returns(StreamChat::StreamResponse) }
165
192
  def search(filter_conditions, query, sort: nil, **options)
166
193
  offset = T.cast(options[:offset], T.nilable(Integer))
167
194
  next_value = options[:next]
@@ -179,21 +206,22 @@ module StreamChat
179
206
  get('search', params: { payload: options.merge(to_merge).to_json })
180
207
  end
181
208
 
182
- # <b>DEPRECATED:</b> Please use <tt>upsert_users</tt> instead.
183
- sig { params(users: T::Array[StringKeyHash]).returns(StreamChat::StreamResponse) }
209
+ # @deprecated Use {#upsert_users} instead.
210
+ T::Sig::WithoutRuntime.sig { params(users: T::Array[StringKeyHash]).returns(StreamChat::StreamResponse) }
184
211
  def update_users(users)
185
212
  warn '[DEPRECATION] `update_users` is deprecated. Please use `upsert_users` instead.'
186
213
  upsert_users(users)
187
214
  end
188
215
 
189
- # <b>DEPRECATED:</b> Please use <tt>upsert_user</tt> instead.
190
- sig { params(user: StringKeyHash).returns(StreamChat::StreamResponse) }
216
+ # @deprecated Use {#upsert_user} instead.
217
+ T::Sig::WithoutRuntime.sig { params(user: StringKeyHash).returns(StreamChat::StreamResponse) }
191
218
  def update_user(user)
192
219
  warn '[DEPRECATION] `update_user` is deprecated. Please use `upsert_user` instead.'
193
220
  upsert_user(user)
194
221
  end
195
222
 
196
- sig { params(users: T::Array[StringKeyHash]).returns(StreamChat::StreamResponse) }
223
+ # Creates or updates users.
224
+ T::Sig::WithoutRuntime.sig { params(users: T::Array[StringKeyHash]).returns(StreamChat::StreamResponse) }
197
225
  def upsert_users(users)
198
226
  payload = {}
199
227
  users.each do |user|
@@ -205,84 +233,116 @@ module StreamChat
205
233
  post('users', data: { users: payload })
206
234
  end
207
235
 
208
- sig { params(user: StringKeyHash).returns(StreamChat::StreamResponse) }
236
+ # Creates or updates a user.
237
+ T::Sig::WithoutRuntime.sig { params(user: StringKeyHash).returns(StreamChat::StreamResponse) }
209
238
  def upsert_user(user)
210
239
  upsert_users([user])
211
240
  end
212
241
 
213
- sig { params(updates: T::Array[StringKeyHash]).returns(StreamChat::StreamResponse) }
242
+ # Updates multiple users partially.
243
+ T::Sig::WithoutRuntime.sig { params(updates: T::Array[StringKeyHash]).returns(StreamChat::StreamResponse) }
214
244
  def update_users_partial(updates)
215
245
  patch('users', data: { users: updates })
216
246
  end
217
247
 
218
- sig { params(update: StringKeyHash).returns(StreamChat::StreamResponse) }
248
+ # Updates a single user partially.
249
+ T::Sig::WithoutRuntime.sig { params(update: StringKeyHash).returns(StreamChat::StreamResponse) }
219
250
  def update_user_partial(update)
220
251
  update_users_partial([update])
221
252
  end
222
253
 
223
- sig { params(user_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
254
+ # Deletes a user synchronously.
255
+ T::Sig::WithoutRuntime.sig { params(user_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
224
256
  def delete_user(user_id, **options)
225
257
  delete("users/#{user_id}", params: options)
226
258
  end
227
259
 
228
- sig { params(user_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
260
+ # Deactivates a user.
261
+ # Deactivated users cannot connect to Stream Chat, and can't send or receive messages.
262
+ # To reactivate a user, use `reactivate_user` method.
263
+ T::Sig::WithoutRuntime.sig { params(user_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
229
264
  def deactivate_user(user_id, **options)
230
265
  post("users/#{user_id}/deactivate", params: options)
231
266
  end
232
267
 
233
- sig { params(user_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
268
+ # Reactivates a deactivated user. Use deactivate_user to deactivate a user.
269
+ T::Sig::WithoutRuntime.sig { params(user_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
234
270
  def reactivate_user(user_id, **options)
235
271
  post("users/#{user_id}/reactivate", params: options)
236
272
  end
237
273
 
238
- sig { params(user_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
274
+ # Exports a user. It exports a user and returns an object
275
+ # containing all of it's data.
276
+ T::Sig::WithoutRuntime.sig { params(user_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
239
277
  def export_user(user_id, **options)
240
278
  get("users/#{user_id}/export", params: options)
241
279
  end
242
280
 
243
- sig { params(target_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
281
+ # Bans a user. Users can be banned from an app entirely or from a channel.
282
+ # When a user is banned, they will not be allowed to post messages until the
283
+ # ban is removed or expired but will be able to connect to Chat and to channels as before.
284
+ # To unban a user, use `unban_user` method.
285
+ T::Sig::WithoutRuntime.sig { params(target_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
244
286
  def ban_user(target_id, **options)
245
287
  payload = { target_user_id: target_id }.merge(options)
246
288
  post('moderation/ban', data: payload)
247
289
  end
248
290
 
249
- sig { params(target_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
291
+ # Unbans a user.
292
+ # To ban a user, use `ban_user` method.
293
+ T::Sig::WithoutRuntime.sig { params(target_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
250
294
  def unban_user(target_id, **options)
251
295
  params = { target_user_id: target_id }.merge(options)
252
296
  delete('moderation/ban', params: params)
253
297
  end
254
298
 
255
- sig { params(target_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
299
+ # Shadow ban a user.
300
+ # When a user is shadow banned, they will still be allowed to post messages,
301
+ # but any message sent during the will only be visible to the messages author
302
+ # and invisible to other users of the App.
303
+ # To remove a shadow ban, use `remove_shadow_ban` method.
304
+ T::Sig::WithoutRuntime.sig { params(target_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
256
305
  def shadow_ban(target_id, **options)
257
306
  payload = { target_user_id: target_id, shadow: true }.merge(options)
258
307
  post('moderation/ban', data: payload)
259
308
  end
260
309
 
261
- sig { params(target_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
310
+ # Removes a shadow ban of a user.
311
+ # To shadow ban a user, use `shadow_ban` method.
312
+ T::Sig::WithoutRuntime.sig { params(target_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
262
313
  def remove_shadow_ban(target_id, **options)
263
314
  params = { target_user_id: target_id, shadow: true }.merge(options)
264
315
  delete('moderation/ban', params: params)
265
316
  end
266
317
 
267
- sig { params(target_id: String, user_id: String).returns(StreamChat::StreamResponse) }
318
+ # Mutes a user.
319
+ T::Sig::WithoutRuntime.sig { params(target_id: String, user_id: String).returns(StreamChat::StreamResponse) }
268
320
  def mute_user(target_id, user_id)
269
321
  payload = { target_id: target_id, user_id: user_id }
270
322
  post('moderation/mute', data: payload)
271
323
  end
272
324
 
273
- sig { params(target_id: String, user_id: String).returns(StreamChat::StreamResponse) }
325
+ # Unmutes a user.
326
+ T::Sig::WithoutRuntime.sig { params(target_id: String, user_id: String).returns(StreamChat::StreamResponse) }
274
327
  def unmute_user(target_id, user_id)
275
328
  payload = { target_id: target_id, user_id: user_id }
276
329
  post('moderation/unmute', data: payload)
277
330
  end
278
331
 
279
- sig { params(user_id: String).returns(StreamChat::StreamResponse) }
332
+ # Marks all messages as read for a user.
333
+ T::Sig::WithoutRuntime.sig { params(user_id: String).returns(StreamChat::StreamResponse) }
280
334
  def mark_all_read(user_id)
281
335
  payload = { user: { id: user_id } }
282
336
  post('channels/read', data: payload)
283
337
  end
284
338
 
285
- sig { params(message_id: String, user_id: String, expiration: T.nilable(String)).returns(StreamChat::StreamResponse) }
339
+ # Pins a message.
340
+ #
341
+ # Pinned messages allow users to highlight important messages, make announcements, or temporarily
342
+ # promote content. Pinning a message is, by default, restricted to certain user roles,
343
+ # but this is flexible. Each channel can have multiple pinned messages and these can be created
344
+ # or updated with or without an expiration.
345
+ T::Sig::WithoutRuntime.sig { params(message_id: String, user_id: String, expiration: T.nilable(String)).returns(StreamChat::StreamResponse) }
286
346
  def pin_message(message_id, user_id, expiration: nil)
287
347
  updates = {
288
348
  set: {
@@ -293,7 +353,8 @@ module StreamChat
293
353
  update_message_partial(message_id, updates, user_id: user_id)
294
354
  end
295
355
 
296
- sig { params(message_id: String, user_id: String).returns(StreamChat::StreamResponse) }
356
+ # Unpins a message.
357
+ T::Sig::WithoutRuntime.sig { params(message_id: String, user_id: String).returns(StreamChat::StreamResponse) }
297
358
  def unpin_message(message_id, user_id)
298
359
  updates = {
299
360
  set: {
@@ -303,26 +364,39 @@ module StreamChat
303
364
  update_message_partial(message_id, updates, user_id: user_id)
304
365
  end
305
366
 
306
- sig { params(message: StringKeyHash).returns(StreamChat::StreamResponse) }
367
+ # Updates a message. Fully overwrites a message.
368
+ # For partial update, use `update_message_partial` method.
369
+ T::Sig::WithoutRuntime.sig { params(message: StringKeyHash).returns(StreamChat::StreamResponse) }
307
370
  def update_message(message)
308
371
  raise ArgumentError, 'message must have an id' unless message.key? 'id'
309
372
 
310
373
  post("messages/#{message['id']}", data: { message: message })
311
374
  end
312
375
 
313
- sig { params(message_id: String, updates: StringKeyHash, user_id: T.nilable(String), options: T.untyped).returns(StreamChat::StreamResponse) }
376
+ # Updates a message partially.
377
+ # A partial update can be used to set and unset specific fields when
378
+ # it is necessary to retain additional data fields on the object. AKA a patch style update.
379
+ T::Sig::WithoutRuntime.sig { params(message_id: String, updates: StringKeyHash, user_id: T.nilable(String), options: T.untyped).returns(StreamChat::StreamResponse) }
314
380
  def update_message_partial(message_id, updates, user_id: nil, **options)
315
381
  params = updates.merge(options)
316
382
  params['user'] = { id: user_id } if user_id
317
383
  put("messages/#{message_id}", data: params)
318
384
  end
319
385
 
320
- sig { params(message_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
386
+ # Deletes a message.
387
+ T::Sig::WithoutRuntime.sig { params(message_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
321
388
  def delete_message(message_id, **options)
322
389
  delete("messages/#{message_id}", params: options)
323
390
  end
324
391
 
325
- sig { params(filter_conditions: StringKeyHash, sort: T.nilable(T::Hash[String, Integer]), options: T.untyped).returns(StreamChat::StreamResponse) }
392
+ # Queries banned users.
393
+ #
394
+ # Banned users can be retrieved in different ways:
395
+ # 1) Using the dedicated query bans endpoint
396
+ # 2) User Search: you can add the banned:true condition to your search. Please note that
397
+ # this will only return users that were banned at the app-level and not the ones
398
+ # that were banned only on channels.
399
+ T::Sig::WithoutRuntime.sig { params(filter_conditions: StringKeyHash, sort: T.nilable(T::Hash[String, Integer]), options: T.untyped).returns(StreamChat::StreamResponse) }
326
400
  def query_banned_users(filter_conditions, sort: nil, **options)
327
401
  params = options.merge({
328
402
  filter_conditions: filter_conditions,
@@ -331,7 +405,9 @@ module StreamChat
331
405
  get('query_banned_users', params: { payload: params.to_json })
332
406
  end
333
407
 
334
- sig { params(filter_conditions: StringKeyHash, sort: T.nilable(T::Hash[String, Integer]), options: T.untyped).returns(StreamChat::StreamResponse) }
408
+ # Allows you to search for users and see if they are online/offline.
409
+ # You can filter and sort on the custom fields you've set for your user, the user id, and when the user was last active.
410
+ T::Sig::WithoutRuntime.sig { params(filter_conditions: StringKeyHash, sort: T.nilable(T::Hash[String, Integer]), options: T.untyped).returns(StreamChat::StreamResponse) }
335
411
  def query_users(filter_conditions, sort: nil, **options)
336
412
  params = options.merge({
337
413
  filter_conditions: filter_conditions,
@@ -340,7 +416,13 @@ module StreamChat
340
416
  get('users', params: { payload: params.to_json })
341
417
  end
342
418
 
343
- sig { params(filter_conditions: StringKeyHash, sort: T.nilable(T::Hash[String, Integer]), options: T.untyped).returns(StreamChat::StreamResponse) }
419
+ # Queries channels.
420
+ #
421
+ # You can query channels based on built-in fields as well as any custom field you add to channels.
422
+ # Multiple filters can be combined using AND, OR logical operators, each filter can use its
423
+ # comparison (equality, inequality, greater than, greater or equal, etc.).
424
+ # You can find the complete list of supported operators in the query syntax section of the docs.
425
+ T::Sig::WithoutRuntime.sig { params(filter_conditions: StringKeyHash, sort: T.nilable(T::Hash[String, Integer]), options: T.untyped).returns(StreamChat::StreamResponse) }
344
426
  def query_channels(filter_conditions, sort: nil, **options)
345
427
  data = { state: true, watch: false, presence: false }
346
428
  data = data.merge(options).merge({
@@ -350,28 +432,33 @@ module StreamChat
350
432
  post('channels', data: data)
351
433
  end
352
434
 
353
- sig { params(data: StringKeyHash).returns(StreamChat::StreamResponse) }
435
+ # Creates a new channel type.
436
+ T::Sig::WithoutRuntime.sig { params(data: StringKeyHash).returns(StreamChat::StreamResponse) }
354
437
  def create_channel_type(data)
355
438
  data['commands'] = ['all'] unless data.key?('commands') || data['commands'].nil? || data['commands'].empty?
356
439
  post('channeltypes', data: data)
357
440
  end
358
441
 
359
- sig { params(channel_type: String).returns(StreamChat::StreamResponse) }
442
+ # Returns a channel types.
443
+ T::Sig::WithoutRuntime.sig { params(channel_type: String).returns(StreamChat::StreamResponse) }
360
444
  def get_channel_type(channel_type)
361
445
  get("channeltypes/#{channel_type}")
362
446
  end
363
447
 
364
- sig { returns(StreamChat::StreamResponse) }
448
+ # Returns a list of channel types.
449
+ T::Sig::WithoutRuntime.sig { returns(StreamChat::StreamResponse) }
365
450
  def list_channel_types
366
451
  get('channeltypes')
367
452
  end
368
453
 
369
- sig { params(channel_type: String, options: T.untyped).returns(StreamChat::StreamResponse) }
454
+ # Updates a channel type.
455
+ T::Sig::WithoutRuntime.sig { params(channel_type: String, options: T.untyped).returns(StreamChat::StreamResponse) }
370
456
  def update_channel_type(channel_type, **options)
371
457
  put("channeltypes/#{channel_type}", data: options)
372
458
  end
373
459
 
374
- sig { params(channel_type: String).returns(StreamChat::StreamResponse) }
460
+ # Deletes a channel type.
461
+ T::Sig::WithoutRuntime.sig { params(channel_type: String).returns(StreamChat::StreamResponse) }
375
462
  def delete_channel_type(channel_type)
376
463
  delete("channeltypes/#{channel_type}")
377
464
  end
@@ -384,12 +471,13 @@ module StreamChat
384
471
  #
385
472
  # @return [StreamChat::Channel]
386
473
  #
387
- sig { params(channel_type: String, channel_id: T.nilable(String), data: T.nilable(StringKeyHash)).returns(StreamChat::Channel) }
474
+ T::Sig::WithoutRuntime.sig { params(channel_type: String, channel_id: T.nilable(String), data: T.nilable(StringKeyHash)).returns(StreamChat::Channel) }
388
475
  def channel(channel_type, channel_id: nil, data: nil)
389
476
  StreamChat::Channel.new(self, channel_type, channel_id, data)
390
477
  end
391
478
 
392
- sig { params(device_id: String, push_provider: String, user_id: String, push_provider_name: T.nilable(String)).returns(StreamChat::StreamResponse) }
479
+ # Adds a device to a user.
480
+ T::Sig::WithoutRuntime.sig { params(device_id: String, push_provider: String, user_id: String, push_provider_name: T.nilable(String)).returns(StreamChat::StreamResponse) }
393
481
  def add_device(device_id, push_provider, user_id, push_provider_name = nil)
394
482
  post('devices', data: {
395
483
  id: device_id,
@@ -399,17 +487,21 @@ module StreamChat
399
487
  })
400
488
  end
401
489
 
402
- sig { params(device_id: String, user_id: String).returns(StreamChat::StreamResponse) }
490
+ # Delete a device.
491
+ T::Sig::WithoutRuntime.sig { params(device_id: String, user_id: String).returns(StreamChat::StreamResponse) }
403
492
  def delete_device(device_id, user_id)
404
493
  delete('devices', params: { id: device_id, user_id: user_id })
405
494
  end
406
495
 
407
- sig { params(user_id: String).returns(StreamChat::StreamResponse) }
496
+ # Returns a list of devices.
497
+ T::Sig::WithoutRuntime.sig { params(user_id: String).returns(StreamChat::StreamResponse) }
408
498
  def get_devices(user_id)
409
499
  get('devices', params: { user_id: user_id })
410
500
  end
411
501
 
412
- sig { params(server_side: T::Boolean, android: T::Boolean, ios: T::Boolean, web: T::Boolean, endpoints: T::Array[String]).returns(StreamChat::StreamResponse) }
502
+ # Get rate limit quotas and usage.
503
+ # If no params are toggled, all limits for all endpoints are returned.
504
+ T::Sig::WithoutRuntime.sig { params(server_side: T::Boolean, android: T::Boolean, ios: T::Boolean, web: T::Boolean, endpoints: T::Array[String]).returns(StreamChat::StreamResponse) }
413
505
  def get_rate_limits(server_side: false, android: false, ios: false, web: false, endpoints: [])
414
506
  params = {}
415
507
  params['server_side'] = server_side if server_side
@@ -421,94 +513,154 @@ module StreamChat
421
513
  get('rate_limits', params: params)
422
514
  end
423
515
 
424
- sig { params(request_body: String, x_signature: String).returns(T::Boolean) }
516
+ # Verify the signature added to a webhook event.
517
+ T::Sig::WithoutRuntime.sig { params(request_body: String, x_signature: String).returns(T::Boolean) }
425
518
  def verify_webhook(request_body, x_signature)
426
519
  signature = OpenSSL::HMAC.hexdigest('SHA256', @api_secret, request_body)
427
520
  signature == x_signature
428
521
  end
429
522
 
430
- sig { params(user_id: String, event: StringKeyHash).returns(StreamChat::StreamResponse) }
523
+ # Allows you to send custom events to a connected user.
524
+ T::Sig::WithoutRuntime.sig { params(user_id: String, event: StringKeyHash).returns(StreamChat::StreamResponse) }
431
525
  def send_user_event(user_id, event)
432
526
  post("users/#{user_id}/event", data: event)
433
527
  end
434
528
 
435
- sig { params(message_id: String, language: String).returns(StreamChat::StreamResponse) }
529
+ # Translates an existing message to another language. The source language
530
+ # is inferred from the user language or detected automatically by analyzing its text.
531
+ # If possible it is recommended to store the user language. See the documentation.
532
+ T::Sig::WithoutRuntime.sig { params(message_id: String, language: String).returns(StreamChat::StreamResponse) }
436
533
  def translate_message(message_id, language)
437
534
  post("messages/#{message_id}/translate", data: { language: language })
438
535
  end
439
536
 
440
- sig { params(message_id: String, data: StringKeyHash).returns(StreamChat::StreamResponse) }
537
+ # Runs a message command action.
538
+ T::Sig::WithoutRuntime.sig { params(message_id: String, data: StringKeyHash).returns(StreamChat::StreamResponse) }
441
539
  def run_message_action(message_id, data)
442
540
  post("messages/#{message_id}/action", data: data)
443
541
  end
444
542
 
445
- sig { params(user: StringKeyHash).returns(StreamChat::StreamResponse) }
543
+ # Creates a guest user.
544
+ #
545
+ # Guest sessions can be created client-side and do not require any server-side authentication.
546
+ # Support and livestreams are common use cases for guests users because really
547
+ # often you want a visitor to be able to use chat on your application without (or before)
548
+ # they have a regular user account.
549
+ T::Sig::WithoutRuntime.sig { params(user: StringKeyHash).returns(StreamChat::StreamResponse) }
446
550
  def create_guest(user)
447
551
  post('guests', data: user)
448
552
  end
449
553
 
450
- sig { returns(StreamChat::StreamResponse) }
554
+ # Returns all blocklists.
555
+ #
556
+ # A Block List is a list of words that you can use to moderate chat messages. Stream Chat
557
+ # comes with a built-in Block List called profanity_en_2020_v1 which contains over a thousand
558
+ # of the most common profane words.
559
+ # You can manage your own block lists via the Stream dashboard or APIs to a manage
560
+ # blocklists and configure your channel types to use them.
561
+ T::Sig::WithoutRuntime.sig { returns(StreamChat::StreamResponse) }
451
562
  def list_blocklists
452
563
  get('blocklists')
453
564
  end
454
565
 
455
- sig { params(name: String).returns(StreamChat::StreamResponse) }
566
+ # Returns a blocklist.
567
+ #
568
+ # A Block List is a list of words that you can use to moderate chat messages. Stream Chat
569
+ # comes with a built-in Block List called profanity_en_2020_v1 which contains over a thousand
570
+ # of the most common profane words.
571
+ # You can manage your own block lists via the Stream dashboard or APIs to a manage
572
+ # blocklists and configure your channel types to use them.
573
+ T::Sig::WithoutRuntime.sig { params(name: String).returns(StreamChat::StreamResponse) }
456
574
  def get_blocklist(name)
457
575
  get("blocklists/#{name}")
458
576
  end
459
577
 
460
- sig { params(name: String, words: StringKeyHash).returns(StreamChat::StreamResponse) }
578
+ # Creates a blocklist.
579
+ #
580
+ # A Block List is a list of words that you can use to moderate chat messages. Stream Chat
581
+ # comes with a built-in Block List called profanity_en_2020_v1 which contains over a thousand
582
+ # of the most common profane words.
583
+ # You can manage your own block lists via the Stream dashboard or APIs to a manage
584
+ # blocklists and configure your channel types to use them.
585
+ T::Sig::WithoutRuntime.sig { params(name: String, words: StringKeyHash).returns(StreamChat::StreamResponse) }
461
586
  def create_blocklist(name, words)
462
587
  post('blocklists', data: { name: name, words: words })
463
588
  end
464
589
 
465
- sig { params(name: String, words: StringKeyHash).returns(StreamChat::StreamResponse) }
590
+ # Updates a blocklist.
591
+ #
592
+ # A Block List is a list of words that you can use to moderate chat messages. Stream Chat
593
+ # comes with a built-in Block List called profanity_en_2020_v1 which contains over a thousand
594
+ # of the most common profane words.
595
+ # You can manage your own block lists via the Stream dashboard or APIs to a manage
596
+ # blocklists and configure your channel types to use them.
597
+ T::Sig::WithoutRuntime.sig { params(name: String, words: StringKeyHash).returns(StreamChat::StreamResponse) }
466
598
  def update_blocklist(name, words)
467
599
  put("blocklists/#{name}", data: { words: words })
468
600
  end
469
601
 
470
- sig { params(name: String).returns(StreamChat::StreamResponse) }
602
+ # Deletes a blocklist.
603
+ #
604
+ # A Block List is a list of words that you can use to moderate chat messages. Stream Chat
605
+ # comes with a built-in Block List called profanity_en_2020_v1 which contains over a thousand
606
+ # of the most common profane words.
607
+ # You can manage your own block lists via the Stream dashboard or APIs to a manage
608
+ # blocklists and configure your channel types to use them.
609
+ T::Sig::WithoutRuntime.sig { params(name: String).returns(StreamChat::StreamResponse) }
471
610
  def delete_blocklist(name)
472
611
  delete("blocklists/#{name}")
473
612
  end
474
613
 
475
- sig { params(channels: StringKeyHash, options: T.untyped).returns(StreamChat::StreamResponse) }
614
+ # Requests a channel export.
615
+ #
616
+ # Channel exports are created asynchronously, you can use the Task ID returned by
617
+ # the APIs to keep track of the status and to download the final result when it is ready.
618
+ # Use `get_task` to check the status of the export.
619
+ T::Sig::WithoutRuntime.sig { params(channels: StringKeyHash, options: T.untyped).returns(StreamChat::StreamResponse) }
476
620
  def export_channels(*channels, **options)
477
621
  post('export_channels', data: { channels: channels, **options })
478
622
  end
479
623
 
480
- sig { params(task_id: String).returns(StreamChat::StreamResponse) }
624
+ # Returns the status of a channel export. It contains the URL to the JSON file.
625
+ T::Sig::WithoutRuntime.sig { params(task_id: String).returns(StreamChat::StreamResponse) }
481
626
  def get_export_channel_status(task_id)
482
627
  get("export_channels/#{task_id}")
483
628
  end
484
629
 
485
- sig { params(task_id: String).returns(StreamChat::StreamResponse) }
630
+ # Returns the status of a task.
631
+ T::Sig::WithoutRuntime.sig { params(task_id: String).returns(StreamChat::StreamResponse) }
486
632
  def get_task(task_id)
487
633
  get("tasks/#{task_id}")
488
634
  end
489
635
 
490
- sig { params(user_ids: T::Array[String], user: String, messages: T.nilable(StringKeyHash), conversations: T.nilable(String)).returns(StreamChat::StreamResponse) }
636
+ # Delete users asynchronously. Use `get_task` to check the status of the task.
637
+ T::Sig::WithoutRuntime.sig { params(user_ids: T::Array[String], user: String, messages: T.nilable(StringKeyHash), conversations: T.nilable(String)).returns(StreamChat::StreamResponse) }
491
638
  def delete_users(user_ids, user: SOFT_DELETE, messages: nil, conversations: nil)
492
639
  post('users/delete', data: { user_ids: user_ids, user: user, messages: messages, conversations: conversations })
493
640
  end
494
641
 
495
- sig { params(cids: T::Array[String], hard_delete: T::Boolean).returns(StreamChat::StreamResponse) }
642
+ # Deletes multiple channels. This is an asynchronous operation and the returned value is a task Id.
643
+ # You can use `get_task` method to check the status of the task.
644
+ T::Sig::WithoutRuntime.sig { params(cids: T::Array[String], hard_delete: T::Boolean).returns(StreamChat::StreamResponse) }
496
645
  def delete_channels(cids, hard_delete: false)
497
646
  post('channels/delete', data: { cids: cids, hard_delete: hard_delete })
498
647
  end
499
648
 
500
- sig { params(before: T.any(DateTime, String)).returns(StreamChat::StreamResponse) }
649
+ # Revoke tokens for an application issued since the given date.
650
+ T::Sig::WithoutRuntime.sig { params(before: T.any(DateTime, String)).returns(StreamChat::StreamResponse) }
501
651
  def revoke_tokens(before)
502
652
  before = T.cast(before, DateTime).rfc3339 if before.instance_of?(DateTime)
503
653
  update_app_settings({ 'revoke_tokens_issued_before' => before })
504
654
  end
505
655
 
506
- sig { params(user_id: String, before: T.any(DateTime, String)).returns(StreamChat::StreamResponse) }
656
+ # Revoke tokens for a user issued since the given date.
657
+ T::Sig::WithoutRuntime.sig { params(user_id: String, before: T.any(DateTime, String)).returns(StreamChat::StreamResponse) }
507
658
  def revoke_user_token(user_id, before)
508
659
  revoke_users_token([user_id], before)
509
660
  end
510
661
 
511
- sig { params(user_ids: T::Array[String], before: T.any(DateTime, String)).returns(StreamChat::StreamResponse) }
662
+ # Revoke tokens for users issued since.
663
+ T::Sig::WithoutRuntime.sig { params(user_ids: T::Array[String], before: T.any(DateTime, String)).returns(StreamChat::StreamResponse) }
512
664
  def revoke_users_token(user_ids, before)
513
665
  before = T.cast(before, DateTime).rfc3339 if before.instance_of?(DateTime)
514
666
 
@@ -524,32 +676,36 @@ module StreamChat
524
676
  update_users_partial(updates)
525
677
  end
526
678
 
527
- sig { params(relative_url: String, params: T.nilable(StringKeyHash), data: T.nilable(StringKeyHash)).returns(StreamChat::StreamResponse) }
679
+ T::Sig::WithoutRuntime.sig { params(relative_url: String, params: T.nilable(StringKeyHash), data: T.nilable(StringKeyHash)).returns(StreamChat::StreamResponse) }
528
680
  def put(relative_url, params: nil, data: nil)
529
681
  make_http_request(:put, relative_url, params: params, data: data)
530
682
  end
531
683
 
532
- sig { params(relative_url: String, params: T.nilable(StringKeyHash), data: T.nilable(StringKeyHash)).returns(StreamChat::StreamResponse) }
684
+ T::Sig::WithoutRuntime.sig { params(relative_url: String, params: T.nilable(StringKeyHash), data: T.nilable(StringKeyHash)).returns(StreamChat::StreamResponse) }
533
685
  def post(relative_url, params: nil, data: nil)
534
686
  make_http_request(:post, relative_url, params: params, data: data)
535
687
  end
536
688
 
537
- sig { params(relative_url: String, params: T.nilable(StringKeyHash)).returns(StreamChat::StreamResponse) }
689
+ T::Sig::WithoutRuntime.sig { params(relative_url: String, params: T.nilable(StringKeyHash)).returns(StreamChat::StreamResponse) }
538
690
  def get(relative_url, params: nil)
539
691
  make_http_request(:get, relative_url, params: params)
540
692
  end
541
693
 
542
- sig { params(relative_url: String, params: T.nilable(StringKeyHash)).returns(StreamChat::StreamResponse) }
694
+ T::Sig::WithoutRuntime.sig { params(relative_url: String, params: T.nilable(StringKeyHash)).returns(StreamChat::StreamResponse) }
543
695
  def delete(relative_url, params: nil)
544
696
  make_http_request(:delete, relative_url, params: params)
545
697
  end
546
698
 
547
- sig { params(relative_url: String, params: T.nilable(StringKeyHash), data: T.nilable(StringKeyHash)).returns(StreamChat::StreamResponse) }
699
+ T::Sig::WithoutRuntime.sig { params(relative_url: String, params: T.nilable(StringKeyHash), data: T.nilable(StringKeyHash)).returns(StreamChat::StreamResponse) }
548
700
  def patch(relative_url, params: nil, data: nil)
549
701
  make_http_request(:patch, relative_url, params: params, data: data)
550
702
  end
551
703
 
552
- sig { params(relative_url: String, file_url: String, user: StringKeyHash, content_type: T.nilable(String)).returns(StreamChat::StreamResponse) }
704
+ # Uploads a file.
705
+ #
706
+ # This functionality defaults to using the Stream CDN. If you would like, you can
707
+ # easily change the logic to upload to your own CDN of choice.
708
+ T::Sig::WithoutRuntime.sig { params(relative_url: String, file_url: String, user: StringKeyHash, content_type: T.nilable(String)).returns(StreamChat::StreamResponse) }
553
709
  def send_file(relative_url, file_url, user, content_type = nil)
554
710
  url = [@base_url, relative_url].join('/')
555
711
 
@@ -568,109 +724,245 @@ module StreamChat
568
724
  parse_response(response)
569
725
  end
570
726
 
571
- sig { params(push_data: StringKeyHash).returns(StreamChat::StreamResponse) }
727
+ # Check push notification settings.
728
+ T::Sig::WithoutRuntime.sig { params(push_data: StringKeyHash).returns(StreamChat::StreamResponse) }
572
729
  def check_push(push_data)
573
730
  post('check_push', data: push_data)
574
731
  end
575
732
 
576
- sig { params(sqs_key: T.nilable(String), sqs_secret: T.nilable(String), sqs_url: T.nilable(String)).returns(StreamChat::StreamResponse) }
733
+ # Check SQS Push settings
734
+ #
735
+ # When no parameters are given, the current SQS app settings are used.
736
+ T::Sig::WithoutRuntime.sig { params(sqs_key: T.nilable(String), sqs_secret: T.nilable(String), sqs_url: T.nilable(String)).returns(StreamChat::StreamResponse) }
577
737
  def check_sqs(sqs_key = nil, sqs_secret = nil, sqs_url = nil)
578
738
  post('check_sqs', data: { sqs_key: sqs_key, sqs_secret: sqs_secret, sqs_url: sqs_url })
579
739
  end
580
740
 
581
- sig { params(command: StringKeyHash).returns(StreamChat::StreamResponse) }
741
+ # Creates a new command.
742
+ T::Sig::WithoutRuntime.sig { params(command: StringKeyHash).returns(StreamChat::StreamResponse) }
582
743
  def create_command(command)
583
744
  post('commands', data: command)
584
745
  end
585
746
 
586
- sig { params(name: String).returns(StreamChat::StreamResponse) }
747
+ # Gets a comamnd.
748
+ T::Sig::WithoutRuntime.sig { params(name: String).returns(StreamChat::StreamResponse) }
587
749
  def get_command(name)
588
750
  get("commands/#{name}")
589
751
  end
590
752
 
591
- sig { params(name: String, command: StringKeyHash).returns(StreamChat::StreamResponse) }
753
+ # Updates a command.
754
+ T::Sig::WithoutRuntime.sig { params(name: String, command: StringKeyHash).returns(StreamChat::StreamResponse) }
592
755
  def update_command(name, command)
593
756
  put("commands/#{name}", data: command)
594
757
  end
595
758
 
596
- sig { params(name: String).returns(StreamChat::StreamResponse) }
759
+ # Deletes a command.
760
+ T::Sig::WithoutRuntime.sig { params(name: String).returns(StreamChat::StreamResponse) }
597
761
  def delete_command(name)
598
762
  delete("commands/#{name}")
599
763
  end
600
764
 
601
- sig { returns(StreamChat::StreamResponse) }
765
+ # Lists all commands.
766
+ T::Sig::WithoutRuntime.sig { returns(StreamChat::StreamResponse) }
602
767
  def list_commands
603
768
  get('commands')
604
769
  end
605
770
 
606
- sig { returns(StreamChat::StreamResponse) }
771
+ # Lists all permissions.
772
+ T::Sig::WithoutRuntime.sig { returns(StreamChat::StreamResponse) }
607
773
  def list_permissions
608
774
  get('permissions')
609
775
  end
610
776
 
611
- sig { params(id: String).returns(StreamChat::StreamResponse) }
777
+ # Gets a permission.
778
+ T::Sig::WithoutRuntime.sig { params(id: String).returns(StreamChat::StreamResponse) }
612
779
  def get_permission(id)
613
780
  get("permissions/#{id}")
614
781
  end
615
782
 
616
- sig { params(permission: StringKeyHash).returns(StreamChat::StreamResponse) }
783
+ # Creates a new permission.
784
+ T::Sig::WithoutRuntime.sig { params(permission: StringKeyHash).returns(StreamChat::StreamResponse) }
617
785
  def create_permission(permission)
618
786
  post('permissions', data: permission)
619
787
  end
620
788
 
621
- sig { params(id: String, permission: StringKeyHash).returns(StreamChat::StreamResponse) }
789
+ # Updates a permission.
790
+ T::Sig::WithoutRuntime.sig { params(id: String, permission: StringKeyHash).returns(StreamChat::StreamResponse) }
622
791
  def update_permission(id, permission)
623
792
  put("permissions/#{id}", data: permission)
624
793
  end
625
794
 
626
- sig { params(id: String).returns(StreamChat::StreamResponse) }
795
+ # Deletes a permission by id.
796
+ T::Sig::WithoutRuntime.sig { params(id: String).returns(StreamChat::StreamResponse) }
627
797
  def delete_permission(id)
628
798
  delete("permissions/#{id}")
629
799
  end
630
800
 
631
- sig { params(name: String).returns(StreamChat::StreamResponse) }
801
+ # Create a new role.
802
+ T::Sig::WithoutRuntime.sig { params(name: String).returns(StreamChat::StreamResponse) }
632
803
  def create_role(name)
633
804
  post('roles', data: { name: name })
634
805
  end
635
806
 
636
- sig { params(name: String).returns(StreamChat::StreamResponse) }
807
+ # Delete a role by name.
808
+ T::Sig::WithoutRuntime.sig { params(name: String).returns(StreamChat::StreamResponse) }
637
809
  def delete_role(name)
638
810
  delete("roles/#{name}")
639
811
  end
640
812
 
641
- sig { returns(StreamChat::StreamResponse) }
813
+ # List all roles.
814
+ T::Sig::WithoutRuntime.sig { returns(StreamChat::StreamResponse) }
642
815
  def list_roles
643
816
  get('roles')
644
817
  end
645
818
 
646
- sig { params(push_provider: StringKeyHash).returns(StreamChat::StreamResponse) }
819
+ # Create or update a push provider.
820
+ T::Sig::WithoutRuntime.sig { params(push_provider: StringKeyHash).returns(StreamChat::StreamResponse) }
647
821
  def upsert_push_provider(push_provider)
648
822
  post('push_providers', data: { push_provider: push_provider })
649
823
  end
650
824
 
651
- sig { params(type: String, name: String).returns(StreamChat::StreamResponse) }
825
+ # Delete a push provider by type and name.
826
+ T::Sig::WithoutRuntime.sig { params(type: String, name: String).returns(StreamChat::StreamResponse) }
652
827
  def delete_push_provider(type, name)
653
828
  delete("push_providers/#{type}/#{name}")
654
829
  end
655
830
 
656
- sig { returns(StreamChat::StreamResponse) }
831
+ # Lists all push providers.
832
+ T::Sig::WithoutRuntime.sig { returns(StreamChat::StreamResponse) }
657
833
  def list_push_providers
658
834
  get('push_providers')
659
835
  end
660
836
 
837
+ # Creates a signed URL for imports.
838
+ # @example
839
+ # url_resp = client.create_import_url('myfile.json')
840
+ # Faraday.put(url_resp['upload_url'], File.read('myfile.json'), 'Content-Type' => 'application/json')
841
+ # client.create_import(url_resp['path'], 'upsert')
842
+ T::Sig::WithoutRuntime.sig { params(filename: String).returns(StreamChat::StreamResponse) }
843
+ def create_import_url(filename)
844
+ post('import_urls', data: { filename: filename })
845
+ end
846
+
847
+ # Creates a new import.
848
+ # @example
849
+ # url_resp = client.create_import_url('myfile.json')
850
+ # Faraday.put(url_resp['upload_url'], File.read('myfile.json'), 'Content-Type' => 'application/json')
851
+ # client.create_import(url_resp['path'], 'upsert')
852
+ T::Sig::WithoutRuntime.sig { params(path: String, mode: String).returns(StreamChat::StreamResponse) }
853
+ def create_import(path, mode)
854
+ post('imports', data: { path: path, mode: mode })
855
+ end
856
+
857
+ # Returns an import by id.
858
+ T::Sig::WithoutRuntime.sig { params(id: String).returns(StreamChat::StreamResponse) }
859
+ def get_import(id)
860
+ get("imports/#{id}")
861
+ end
862
+
863
+ # Lists imports. Options dictionary can contain 'offset' and 'limit' keys for pagination.
864
+ T::Sig::WithoutRuntime.sig { params(options: T.untyped).returns(StreamChat::StreamResponse) }
865
+ def list_imports(options)
866
+ get('imports', params: options)
867
+ end
868
+
869
+ # Creates a campaign.
870
+ T::Sig::WithoutRuntime.sig { params(campaign: StringKeyHash).returns(StreamChat::StreamResponse) }
871
+ def create_campaign(campaign)
872
+ post('campaigns', data: { campaign: campaign })
873
+ end
874
+
875
+ # Gets a campaign.
876
+ T::Sig::WithoutRuntime.sig { params(campaign_id: String).returns(StreamChat::StreamResponse) }
877
+ def get_campaign(campaign_id)
878
+ get("campaigns/#{campaign_id}")
879
+ end
880
+
881
+ # Lists all campaigns. Options dictionary can contain 'offset' and 'limit' keys for pagination.
882
+ T::Sig::WithoutRuntime.sig { params(options: StringKeyHash).returns(StreamChat::StreamResponse) }
883
+ def list_campaigns(options)
884
+ get('campaigns', params: options)
885
+ end
886
+
887
+ # Updates a campaign.
888
+ T::Sig::WithoutRuntime.sig { params(campaign_id: String, campaign: StringKeyHash).returns(StreamChat::StreamResponse) }
889
+ def update_campaign(campaign_id, campaign)
890
+ put("campaigns/#{campaign_id}", data: { campaign: campaign })
891
+ end
892
+
893
+ # Deletes a campaign.
894
+ T::Sig::WithoutRuntime.sig { params(campaign_id: String).returns(StreamChat::StreamResponse) }
895
+ def delete_campaign(campaign_id)
896
+ delete("campaigns/#{campaign_id}")
897
+ end
898
+
899
+ # Schedules a campaign.
900
+ T::Sig::WithoutRuntime.sig { params(campaign_id: String, send_at: Integer).returns(StreamChat::StreamResponse) }
901
+ def schedule_campaign(campaign_id, send_at)
902
+ patch("campaigns/#{campaign_id}/schedule", data: { send_at: send_at })
903
+ end
904
+
905
+ # Stops a campaign.
906
+ T::Sig::WithoutRuntime.sig { params(campaign_id: String).returns(StreamChat::StreamResponse) }
907
+ def stop_campaign(campaign_id)
908
+ patch("campaigns/#{campaign_id}/stop")
909
+ end
910
+
911
+ # Resumes a campaign.
912
+ T::Sig::WithoutRuntime.sig { params(campaign_id: String).returns(StreamChat::StreamResponse) }
913
+ def resume_campaign(campaign_id)
914
+ patch("campaigns/#{campaign_id}/resume")
915
+ end
916
+
917
+ # Tests a campaign.
918
+ T::Sig::WithoutRuntime.sig { params(campaign_id: String, users: T::Array[StringKeyHash]).returns(StreamChat::StreamResponse) }
919
+ def test_campaign(campaign_id, users)
920
+ post("campaigns/#{campaign_id}/test", data: { users: users })
921
+ end
922
+
923
+ # Creates a campaign segment.
924
+ T::Sig::WithoutRuntime.sig { params(segment: StringKeyHash).returns(StreamChat::StreamResponse) }
925
+ def create_segment(segment)
926
+ post('segments', data: { segment: segment })
927
+ end
928
+
929
+ # Gets a campaign segment.
930
+ T::Sig::WithoutRuntime.sig { params(segment_id: String).returns(StreamChat::StreamResponse) }
931
+ def get_segment(segment_id)
932
+ get("segments/#{segment_id}")
933
+ end
934
+
935
+ # Lists all campaign segments. Options dictionary can contain 'offset' and 'limit' keys for pagination.
936
+ T::Sig::WithoutRuntime.sig { params(options: StringKeyHash).returns(StreamChat::StreamResponse) }
937
+ def list_segments(options)
938
+ get('segments', params: options)
939
+ end
940
+
941
+ # Updates a campaign segment.
942
+ T::Sig::WithoutRuntime.sig { params(segment_id: String, segment: StringKeyHash).returns(StreamChat::StreamResponse) }
943
+ def update_segment(segment_id, segment)
944
+ put("segments/#{segment_id}", data: { segment: segment })
945
+ end
946
+
947
+ # Deletes a campaign segment.
948
+ T::Sig::WithoutRuntime.sig { params(segment_id: String).returns(StreamChat::StreamResponse) }
949
+ def delete_segment(segment_id)
950
+ delete("segments/#{segment_id}")
951
+ end
952
+
661
953
  private
662
954
 
663
- sig { returns(T::Hash[String, String]) }
955
+ T::Sig::WithoutRuntime.sig { returns(T::Hash[String, String]) }
664
956
  def get_default_params
665
957
  { api_key: @api_key }
666
958
  end
667
959
 
668
- sig { returns(String) }
960
+ T::Sig::WithoutRuntime.sig { returns(String) }
669
961
  def get_user_agent
670
962
  "stream-ruby-client-#{StreamChat::VERSION}"
671
963
  end
672
964
 
673
- sig { returns(T::Hash[String, String]) }
965
+ T::Sig::WithoutRuntime.sig { returns(T::Hash[String, String]) }
674
966
  def get_default_headers
675
967
  {
676
968
  'Content-Type': 'application/json',
@@ -678,7 +970,7 @@ module StreamChat
678
970
  }
679
971
  end
680
972
 
681
- sig { params(response: Faraday::Response).returns(StreamChat::StreamResponse) }
973
+ T::Sig::WithoutRuntime.sig { params(response: Faraday::Response).returns(StreamChat::StreamResponse) }
682
974
  def parse_response(response)
683
975
  begin
684
976
  parsed_result = JSON.parse(response.body)
@@ -690,7 +982,7 @@ module StreamChat
690
982
  StreamResponse.new(parsed_result, response)
691
983
  end
692
984
 
693
- sig { params(method: Symbol, relative_url: String, params: T.nilable(StringKeyHash), data: T.nilable(StringKeyHash)).returns(StreamChat::StreamResponse) }
985
+ T::Sig::WithoutRuntime.sig { params(method: Symbol, relative_url: String, params: T.nilable(StringKeyHash), data: T.nilable(StringKeyHash)).returns(StreamChat::StreamResponse) }
694
986
  def make_http_request(method, relative_url, params: nil, data: nil)
695
987
  headers = get_default_headers
696
988
  headers['Authorization'] = @auth_token