Class: StreamChat::Client

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/stream-chat/client.rb

Constant Summary collapse

DEFAULT_BASE_URL =

For now we disable runtime type checks. We will enable it with a major bump in the future, but for now, let's just run a static type check.

'https://chat.stream-io-api.com'
DEFAULT_TIMEOUT =
6.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, api_secret, timeout = nil, **options) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/stream-chat/client.rb', line 53

def initialize(api_key, api_secret, timeout = nil, **options)
  raise ArgumentError, 'api_key and api_secret are required' if api_key.to_s.empty? || api_secret.to_s.empty?

  @api_key = api_key
  @api_secret = api_secret
  @timeout = T.let(timeout&.to_f || DEFAULT_TIMEOUT, Float)
  @auth_token = T.let(JWT.encode({ server: true }, @api_secret, 'HS256'), String)
  @base_url = T.let(options[:base_url] || DEFAULT_BASE_URL, String)
  conn = Faraday.new(@base_url) do |faraday|
    faraday.options[:open_timeout] = @timeout
    faraday.options[:timeout] = @timeout
    faraday.request :multipart
    faraday.adapter :net_http_persistent, pool_size: 5 do |http|
      # AWS load balancer idle timeout is 60 secs, so let's make it 59
      http.idle_timeout = 59
    end
  end
  @conn = T.let(conn, Faraday::Connection)
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



34
35
36
# File 'lib/stream-chat/client.rb', line 34

def api_key
  @api_key
end

#api_secretObject (readonly)

Returns the value of attribute api_secret.



37
38
39
# File 'lib/stream-chat/client.rb', line 37

def api_secret
  @api_secret
end

#connObject (readonly)

Returns the value of attribute conn.



40
41
42
# File 'lib/stream-chat/client.rb', line 40

def conn
  @conn
end

Class Method Details

.from_env(**options) ⇒ Object



78
79
80
81
82
83
# File 'lib/stream-chat/client.rb', line 78

def self.from_env(**options)
  Client.new(T.must(ENV['STREAM_KEY']),
             T.must(ENV['STREAM_SECRET']),
             ENV['STREAM_CHAT_TIMEOUT'],
             **{ base_url: ENV['STREAM_CHAT_URL'] }.merge(options))
end

Instance Method Details

#add_device(device_id, push_provider, user_id, push_provider_name = nil) ⇒ Object



393
394
395
396
397
398
399
400
# File 'lib/stream-chat/client.rb', line 393

def add_device(device_id, push_provider, user_id, push_provider_name = nil)
  post('devices', data: {
         id: device_id,
         push_provider: push_provider,
         push_provider_name: push_provider_name,
         user_id: user_id
       })
end

#ban_user(target_id, **options) ⇒ Object



244
245
246
247
# File 'lib/stream-chat/client.rb', line 244

def ban_user(target_id, **options)
  payload = { target_user_id: target_id }.merge(options)
  post('moderation/ban', data: payload)
end

#channel(channel_type, channel_id: nil, data: nil) ⇒ Object



388
389
390
# File 'lib/stream-chat/client.rb', line 388

def channel(channel_type, channel_id: nil, data: nil)
  StreamChat::Channel.new(self, channel_type, channel_id, data)
end

#check_push(push_data) ⇒ Object



572
573
574
# File 'lib/stream-chat/client.rb', line 572

def check_push(push_data)
  post('check_push', data: push_data)
end

#check_sqs(sqs_key = nil, sqs_secret = nil, sqs_url = nil) ⇒ Object



577
578
579
# File 'lib/stream-chat/client.rb', line 577

def check_sqs(sqs_key = nil, sqs_secret = nil, sqs_url = nil)
  post('check_sqs', data: { sqs_key: sqs_key, sqs_secret: sqs_secret, sqs_url: sqs_url })
end

#create_blocklist(name, words) ⇒ Object



461
462
463
# File 'lib/stream-chat/client.rb', line 461

def create_blocklist(name, words)
  post('blocklists', data: { name: name, words: words })
end

#create_channel_type(data) ⇒ Object



354
355
356
357
# File 'lib/stream-chat/client.rb', line 354

def create_channel_type(data)
  data['commands'] = ['all'] unless data.key?('commands') || data['commands'].nil? || data['commands'].empty?
  post('channeltypes', data: data)
end

#create_command(command) ⇒ Object



582
583
584
# File 'lib/stream-chat/client.rb', line 582

def create_command(command)
  post('commands', data: command)
end

#create_guest(user) ⇒ Object



446
447
448
# File 'lib/stream-chat/client.rb', line 446

def create_guest(user)
  post('guests', data: user)
end

#create_permission(permission) ⇒ Object



617
618
619
# File 'lib/stream-chat/client.rb', line 617

def create_permission(permission)
  post('permissions', data: permission)
end

#create_role(name) ⇒ Object



632
633
634
# File 'lib/stream-chat/client.rb', line 632

def create_role(name)
  post('roles', data: { name: name })
end

#create_token(user_id, exp = nil, iat = nil) ⇒ Object



94
95
96
97
98
99
# File 'lib/stream-chat/client.rb', line 94

def create_token(user_id, exp = nil, iat = nil)
  payload = { user_id: user_id }
  payload['exp'] = exp unless exp.nil?
  payload['iat'] = iat unless iat.nil?
  JWT.encode(payload, @api_secret, 'HS256')
end

#deactivate_user(user_id, **options) ⇒ Object



229
230
231
# File 'lib/stream-chat/client.rb', line 229

def deactivate_user(user_id, **options)
  post("users/#{user_id}/deactivate", params: options)
end

#delete(relative_url, params: nil) ⇒ Object



543
544
545
# File 'lib/stream-chat/client.rb', line 543

def delete(relative_url, params: nil)
  make_http_request(:delete, relative_url, params: params)
end

#delete_blocklist(name) ⇒ Object



471
472
473
# File 'lib/stream-chat/client.rb', line 471

def delete_blocklist(name)
  delete("blocklists/#{name}")
end

#delete_channel_type(channel_type) ⇒ Object



375
376
377
# File 'lib/stream-chat/client.rb', line 375

def delete_channel_type(channel_type)
  delete("channeltypes/#{channel_type}")
end

#delete_channels(cids, hard_delete: false) ⇒ Object



496
497
498
# File 'lib/stream-chat/client.rb', line 496

def delete_channels(cids, hard_delete: false)
  post('channels/delete', data: { cids: cids, hard_delete: hard_delete })
end

#delete_command(name) ⇒ Object



597
598
599
# File 'lib/stream-chat/client.rb', line 597

def delete_command(name)
  delete("commands/#{name}")
end

#delete_device(device_id, user_id) ⇒ Object



403
404
405
# File 'lib/stream-chat/client.rb', line 403

def delete_device(device_id, user_id)
  delete('devices', params: { id: device_id, user_id: user_id })
end

#delete_message(message_id, **options) ⇒ Object



321
322
323
# File 'lib/stream-chat/client.rb', line 321

def delete_message(message_id, **options)
  delete("messages/#{message_id}", params: options)
end

#delete_permission(id) ⇒ Object



627
628
629
# File 'lib/stream-chat/client.rb', line 627

def delete_permission(id)
  delete("permissions/#{id}")
end

#delete_push_provider(type, name) ⇒ Object



652
653
654
# File 'lib/stream-chat/client.rb', line 652

def delete_push_provider(type, name)
  delete("push_providers/#{type}/#{name}")
end

#delete_role(name) ⇒ Object



637
638
639
# File 'lib/stream-chat/client.rb', line 637

def delete_role(name)
  delete("roles/#{name}")
end

#delete_user(user_id, **options) ⇒ Object



224
225
226
# File 'lib/stream-chat/client.rb', line 224

def delete_user(user_id, **options)
  delete("users/#{user_id}", params: options)
end

#delete_users(user_ids, user: SOFT_DELETE, messages: nil, conversations: nil) ⇒ Object



491
492
493
# File 'lib/stream-chat/client.rb', line 491

def delete_users(user_ids, user: SOFT_DELETE, messages: nil, conversations: nil)
  post('users/delete', data: { user_ids: user_ids, user: user, messages: messages, conversations: conversations })
end

#export_channels(*channels, **options) ⇒ Object



476
477
478
# File 'lib/stream-chat/client.rb', line 476

def export_channels(*channels, **options)
  post('export_channels', data: { channels: channels, **options })
end

#export_user(user_id, **options) ⇒ Object



239
240
241
# File 'lib/stream-chat/client.rb', line 239

def export_user(user_id, **options)
  get("users/#{user_id}/export", params: options)
end

#flag_message(id, **options) ⇒ Object



112
113
114
115
# File 'lib/stream-chat/client.rb', line 112

def flag_message(id, **options)
  payload = { target_message_id: id }.merge(options)
  post('moderation/flag', data: payload)
end

#flag_user(id, **options) ⇒ Object



132
133
134
135
# File 'lib/stream-chat/client.rb', line 132

def flag_user(id, **options)
  payload = { target_user_id: id }.merge(options)
  post('moderation/flag', data: payload)
end

#get(relative_url, params: nil) ⇒ Object



538
539
540
# File 'lib/stream-chat/client.rb', line 538

def get(relative_url, params: nil)
  make_http_request(:get, relative_url, params: params)
end

#get_app_settingsObject



107
108
109
# File 'lib/stream-chat/client.rb', line 107

def get_app_settings
  get('app')
end

#get_blocklist(name) ⇒ Object



456
457
458
# File 'lib/stream-chat/client.rb', line 456

def get_blocklist(name)
  get("blocklists/#{name}")
end

#get_channel_type(channel_type) ⇒ Object



360
361
362
# File 'lib/stream-chat/client.rb', line 360

def get_channel_type(channel_type)
  get("channeltypes/#{channel_type}")
end

#get_command(name) ⇒ Object



587
588
589
# File 'lib/stream-chat/client.rb', line 587

def get_command(name)
  get("commands/#{name}")
end

#get_devices(user_id) ⇒ Object



408
409
410
# File 'lib/stream-chat/client.rb', line 408

def get_devices(user_id)
  get('devices', params: { user_id: user_id })
end

#get_export_channel_status(task_id) ⇒ Object



481
482
483
# File 'lib/stream-chat/client.rb', line 481

def get_export_channel_status(task_id)
  get("export_channels/#{task_id}")
end

#get_message(id) ⇒ Object



160
161
162
# File 'lib/stream-chat/client.rb', line 160

def get_message(id)
  get("messages/#{id}")
end

#get_permission(id) ⇒ Object



612
613
614
# File 'lib/stream-chat/client.rb', line 612

def get_permission(id)
  get("permissions/#{id}")
end

#get_rate_limits(server_side: false, android: false, ios: false, web: false, endpoints: []) ⇒ Object



413
414
415
416
417
418
419
420
421
422
# File 'lib/stream-chat/client.rb', line 413

def get_rate_limits(server_side: false, android: false, ios: false, web: false, endpoints: [])
  params = {}
  params['server_side'] = server_side if server_side
  params['android'] = android if android
  params['ios'] = ios if ios
  params['web'] = web if web
  params['endpoints'] = endpoints.join(',') unless endpoints.empty?

  get('rate_limits', params: params)
end

#get_task(task_id) ⇒ Object



486
487
488
# File 'lib/stream-chat/client.rb', line 486

def get_task(task_id)
  get("tasks/#{task_id}")
end

#list_blocklistsObject



451
452
453
# File 'lib/stream-chat/client.rb', line 451

def list_blocklists
  get('blocklists')
end

#list_channel_typesObject



365
366
367
# File 'lib/stream-chat/client.rb', line 365

def list_channel_types
  get('channeltypes')
end

#list_commandsObject



602
603
604
# File 'lib/stream-chat/client.rb', line 602

def list_commands
  get('commands')
end

#list_permissionsObject



607
608
609
# File 'lib/stream-chat/client.rb', line 607

def list_permissions
  get('permissions')
end

#list_push_providersObject



657
658
659
# File 'lib/stream-chat/client.rb', line 657

def list_push_providers
  get('push_providers')
end

#list_rolesObject



642
643
644
# File 'lib/stream-chat/client.rb', line 642

def list_roles
  get('roles')
end

#mark_all_read(user_id) ⇒ Object



280
281
282
283
# File 'lib/stream-chat/client.rb', line 280

def mark_all_read(user_id)
  payload = { user: { id: user_id } }
  post('channels/read', data: payload)
end

#mute_user(target_id, user_id) ⇒ Object



268
269
270
271
# File 'lib/stream-chat/client.rb', line 268

def mute_user(target_id, user_id)
  payload = { target_id: target_id, user_id: user_id }
  post('moderation/mute', data: payload)
end

#patch(relative_url, params: nil, data: nil) ⇒ Object



548
549
550
# File 'lib/stream-chat/client.rb', line 548

def patch(relative_url, params: nil, data: nil)
  make_http_request(:patch, relative_url, params: params, data: data)
end

#pin_message(message_id, user_id, expiration: nil) ⇒ Object



286
287
288
289
290
291
292
293
294
# File 'lib/stream-chat/client.rb', line 286

def pin_message(message_id, user_id, expiration: nil)
  updates = {
    set: {
      pinned: true,
      pin_expires: expiration
    }
  }
  update_message_partial(message_id, updates, user_id: user_id)
end

#post(relative_url, params: nil, data: nil) ⇒ Object



533
534
535
# File 'lib/stream-chat/client.rb', line 533

def post(relative_url, params: nil, data: nil)
  make_http_request(:post, relative_url, params: params, data: data)
end

#put(relative_url, params: nil, data: nil) ⇒ Object



528
529
530
# File 'lib/stream-chat/client.rb', line 528

def put(relative_url, params: nil, data: nil)
  make_http_request(:put, relative_url, params: params, data: data)
end

#query_banned_users(filter_conditions, sort: nil, **options) ⇒ Object



326
327
328
329
330
331
332
# File 'lib/stream-chat/client.rb', line 326

def query_banned_users(filter_conditions, sort: nil, **options)
  params = options.merge({
                           filter_conditions: filter_conditions,
                           sort: StreamChat.get_sort_fields(sort)
                         })
  get('query_banned_users', params: { payload: params.to_json })
end

#query_channels(filter_conditions, sort: nil, **options) ⇒ Object



344
345
346
347
348
349
350
351
# File 'lib/stream-chat/client.rb', line 344

def query_channels(filter_conditions, sort: nil, **options)
  data = { state: true, watch: false, presence: false }
  data = data.merge(options).merge({
                                     filter_conditions: filter_conditions,
                                     sort: StreamChat.get_sort_fields(sort)
                                   })
  post('channels', data: data)
end

#query_flag_reports(**options) ⇒ Object



144
145
146
147
# File 'lib/stream-chat/client.rb', line 144

def query_flag_reports(**options)
  data = { filter_conditions: options }
  post('moderation/reports', data: data)
end

#query_message_flags(filter_conditions, **options) ⇒ Object



124
125
126
127
128
129
# File 'lib/stream-chat/client.rb', line 124

def query_message_flags(filter_conditions, **options)
  params = options.merge({
                           filter_conditions: filter_conditions
                         })
  get('moderation/flags/message', params: { payload: params.to_json })
end

#query_users(filter_conditions, sort: nil, **options) ⇒ Object



335
336
337
338
339
340
341
# File 'lib/stream-chat/client.rb', line 335

def query_users(filter_conditions, sort: nil, **options)
  params = options.merge({
                           filter_conditions: filter_conditions,
                           sort: StreamChat.get_sort_fields(sort)
                         })
  get('users', params: { payload: params.to_json })
end

#reactivate_user(user_id, **options) ⇒ Object



234
235
236
# File 'lib/stream-chat/client.rb', line 234

def reactivate_user(user_id, **options)
  post("users/#{user_id}/reactivate", params: options)
end

#remove_shadow_ban(target_id, **options) ⇒ Object



262
263
264
265
# File 'lib/stream-chat/client.rb', line 262

def remove_shadow_ban(target_id, **options)
  params = { target_user_id: target_id, shadow: true }.merge(options)
  delete('moderation/ban', params: params)
end

#review_flag_report(report_id, review_result, user_id, **details) ⇒ Object



150
151
152
153
154
155
156
157
# File 'lib/stream-chat/client.rb', line 150

def review_flag_report(report_id, review_result, user_id, **details)
  data = {
    review_result: review_result,
    user_id: user_id,
    review_details: details
  }
  patch("moderation/reports/#{report_id}", data: data)
end

#revoke_tokens(before) ⇒ Object



501
502
503
504
# File 'lib/stream-chat/client.rb', line 501

def revoke_tokens(before)
  before = T.cast(before, DateTime).rfc3339 if before.instance_of?(DateTime)
  update_app_settings({ 'revoke_tokens_issued_before' => before })
end

#revoke_user_token(user_id, before) ⇒ Object



507
508
509
# File 'lib/stream-chat/client.rb', line 507

def revoke_user_token(user_id, before)
  revoke_users_token([user_id], before)
end

#revoke_users_token(user_ids, before) ⇒ Object



512
513
514
515
516
517
518
519
520
521
522
523
524
525
# File 'lib/stream-chat/client.rb', line 512

def revoke_users_token(user_ids, before)
  before = T.cast(before, DateTime).rfc3339 if before.instance_of?(DateTime)

  updates = []
  user_ids.each do |user_id|
    updates.push({
                   'id' => user_id,
                   'set' => {
                     'revoke_tokens_issued_before' => before
                   }
                 })
  end
  update_users_partial(updates)
end

#run_message_action(message_id, data) ⇒ Object



441
442
443
# File 'lib/stream-chat/client.rb', line 441

def run_message_action(message_id, data)
  post("messages/#{message_id}/action", data: data)
end

#search(filter_conditions, query, sort: nil, **options) ⇒ Object

Raises:

  • (ArgumentError)


165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/stream-chat/client.rb', line 165

def search(filter_conditions, query, sort: nil, **options)
  offset = T.cast(options[:offset], T.nilable(Integer))
  next_value = options[:next]
  raise ArgumentError, 'cannot use offset with next or sort parameters' if offset&.positive? && (next_value || (!sort.nil? && !sort.empty?))

  to_merge = {
    filter_conditions: filter_conditions,
    sort: StreamChat.get_sort_fields(sort)
  }
  if query.is_a? String
    to_merge[:query] = query
  else
    to_merge[:message_filter_conditions] = query
  end
  get('search', params: { payload: options.merge(to_merge).to_json })
end

#send_file(relative_url, file_url, user, content_type = nil) ⇒ Object



553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
# File 'lib/stream-chat/client.rb', line 553

def send_file(relative_url, file_url, user, content_type = nil)
  url = [@base_url, relative_url].join('/')

  body = { user: user.to_json }

  body[:file] = Faraday::UploadIO.new(file_url, content_type || 'application/octet-stream')

  response = @conn.post url do |req|
    req.headers['X-Stream-Client'] = get_user_agent
    req.headers['Authorization'] = @auth_token
    req.headers['stream-auth-type'] = 'jwt'
    req.params = get_default_params
    req.body = body
  end

  parse_response(response)
end

#send_user_event(user_id, event) ⇒ Object



431
432
433
# File 'lib/stream-chat/client.rb', line 431

def send_user_event(user_id, event)
  post("users/#{user_id}/event", data: event)
end

#set_http_client(client) ⇒ Object



89
90
91
# File 'lib/stream-chat/client.rb', line 89

def set_http_client(client)
  @conn = client
end

#shadow_ban(target_id, **options) ⇒ Object



256
257
258
259
# File 'lib/stream-chat/client.rb', line 256

def shadow_ban(target_id, **options)
  payload = { target_user_id: target_id, shadow: true }.merge(options)
  post('moderation/ban', data: payload)
end

#translate_message(message_id, language) ⇒ Object



436
437
438
# File 'lib/stream-chat/client.rb', line 436

def translate_message(message_id, language)
  post("messages/#{message_id}/translate", data: { language: language })
end

#unban_user(target_id, **options) ⇒ Object



250
251
252
253
# File 'lib/stream-chat/client.rb', line 250

def unban_user(target_id, **options)
  params = { target_user_id: target_id }.merge(options)
  delete('moderation/ban', params: params)
end

#unflag_message(id, **options) ⇒ Object



118
119
120
121
# File 'lib/stream-chat/client.rb', line 118

def unflag_message(id, **options)
  payload = { target_message_id: id }.merge(options)
  post('moderation/unflag', data: payload)
end

#unflag_user(id, **options) ⇒ Object



138
139
140
141
# File 'lib/stream-chat/client.rb', line 138

def unflag_user(id, **options)
  payload = { target_user_id: id }.merge(options)
  post('moderation/unflag', data: payload)
end

#unmute_user(target_id, user_id) ⇒ Object



274
275
276
277
# File 'lib/stream-chat/client.rb', line 274

def unmute_user(target_id, user_id)
  payload = { target_id: target_id, user_id: user_id }
  post('moderation/unmute', data: payload)
end

#unpin_message(message_id, user_id) ⇒ Object



297
298
299
300
301
302
303
304
# File 'lib/stream-chat/client.rb', line 297

def unpin_message(message_id, user_id)
  updates = {
    set: {
      pinned: false
    }
  }
  update_message_partial(message_id, updates, user_id: user_id)
end

#update_app_settings(**settings) ⇒ Object



102
103
104
# File 'lib/stream-chat/client.rb', line 102

def update_app_settings(**settings)
  patch('app', data: settings)
end

#update_blocklist(name, words) ⇒ Object



466
467
468
# File 'lib/stream-chat/client.rb', line 466

def update_blocklist(name, words)
  put("blocklists/#{name}", data: { words: words })
end

#update_channel_type(channel_type, **options) ⇒ Object



370
371
372
# File 'lib/stream-chat/client.rb', line 370

def update_channel_type(channel_type, **options)
  put("channeltypes/#{channel_type}", data: options)
end

#update_command(name, command) ⇒ Object



592
593
594
# File 'lib/stream-chat/client.rb', line 592

def update_command(name, command)
  put("commands/#{name}", data: command)
end

#update_message(message) ⇒ Object

Raises:

  • (ArgumentError)


307
308
309
310
311
# File 'lib/stream-chat/client.rb', line 307

def update_message(message)
  raise ArgumentError, 'message must have an id' unless message.key? 'id'

  post("messages/#{message['id']}", data: { message: message })
end

#update_message_partial(message_id, updates, user_id: nil, **options) ⇒ Object



314
315
316
317
318
# File 'lib/stream-chat/client.rb', line 314

def update_message_partial(message_id, updates, user_id: nil, **options)
  params = updates.merge(options)
  params['user'] = { id: user_id } if user_id
  put("messages/#{message_id}", data: params)
end

#update_permission(id, permission) ⇒ Object



622
623
624
# File 'lib/stream-chat/client.rb', line 622

def update_permission(id, permission)
  put("permissions/#{id}", data: permission)
end

#update_user(user) ⇒ Object



191
192
193
194
# File 'lib/stream-chat/client.rb', line 191

def update_user(user)
  warn '[DEPRECATION] `update_user` is deprecated.  Please use `upsert_user` instead.'
  upsert_user(user)
end

#update_user_partial(update) ⇒ Object



219
220
221
# File 'lib/stream-chat/client.rb', line 219

def update_user_partial(update)
  update_users_partial([update])
end

#update_users(users) ⇒ Object



184
185
186
187
# File 'lib/stream-chat/client.rb', line 184

def update_users(users)
  warn '[DEPRECATION] `update_users` is deprecated.  Please use `upsert_users` instead.'
  upsert_users(users)
end

#update_users_partial(updates) ⇒ Object



214
215
216
# File 'lib/stream-chat/client.rb', line 214

def update_users_partial(updates)
  patch('users', data: { users: updates })
end

#upsert_push_provider(push_provider) ⇒ Object



647
648
649
# File 'lib/stream-chat/client.rb', line 647

def upsert_push_provider(push_provider)
  post('push_providers', data: { push_provider: push_provider })
end

#upsert_user(user) ⇒ Object



209
210
211
# File 'lib/stream-chat/client.rb', line 209

def upsert_user(user)
  upsert_users([user])
end

#upsert_users(users) ⇒ Object



197
198
199
200
201
202
203
204
205
206
# File 'lib/stream-chat/client.rb', line 197

def upsert_users(users)
  payload = {}
  users.each do |user|
    id = user[:id] || user['id']
    raise ArgumentError, 'user must have an id' unless id

    payload[id] = user
  end
  post('users', data: { users: payload })
end

#verify_webhook(request_body, x_signature) ⇒ Object



425
426
427
428
# File 'lib/stream-chat/client.rb', line 425

def verify_webhook(request_body, x_signature)
  signature = OpenSSL::HMAC.hexdigest('SHA256', @api_secret, request_body)
  signature == x_signature
end