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



482
483
484
485
486
487
488
489
# File 'lib/stream-chat/client.rb', line 482

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



287
288
289
290
# File 'lib/stream-chat/client.rb', line 287

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



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

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

#check_push(push_data) ⇒ Object



730
731
732
# File 'lib/stream-chat/client.rb', line 730

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

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



738
739
740
# File 'lib/stream-chat/client.rb', line 738

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



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

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

#create_channel_type(data) ⇒ Object



438
439
440
441
# File 'lib/stream-chat/client.rb', line 438

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



744
745
746
# File 'lib/stream-chat/client.rb', line 744

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

#create_guest(user) ⇒ Object



551
552
553
# File 'lib/stream-chat/client.rb', line 551

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

#create_permission(permission) ⇒ Object



786
787
788
# File 'lib/stream-chat/client.rb', line 786

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

#create_role(name) ⇒ Object



804
805
806
# File 'lib/stream-chat/client.rb', line 804

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

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



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

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



265
266
267
# File 'lib/stream-chat/client.rb', line 265

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

#delete(relative_url, params: nil) ⇒ Object



696
697
698
# File 'lib/stream-chat/client.rb', line 696

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

#delete_blocklist(name) ⇒ Object



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

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

#delete_channel_type(channel_type) ⇒ Object



463
464
465
# File 'lib/stream-chat/client.rb', line 463

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

#delete_channels(cids, hard_delete: false) ⇒ Object



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

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

#delete_command(name) ⇒ Object



762
763
764
# File 'lib/stream-chat/client.rb', line 762

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

#delete_device(device_id, user_id) ⇒ Object



493
494
495
# File 'lib/stream-chat/client.rb', line 493

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

#delete_message(message_id, **options) ⇒ Object



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

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

#delete_permission(id) ⇒ Object



798
799
800
# File 'lib/stream-chat/client.rb', line 798

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

#delete_push_provider(type, name) ⇒ Object



828
829
830
# File 'lib/stream-chat/client.rb', line 828

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

#delete_role(name) ⇒ Object



810
811
812
# File 'lib/stream-chat/client.rb', line 810

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

#delete_user(user_id, **options) ⇒ Object



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

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



639
640
641
# File 'lib/stream-chat/client.rb', line 639

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



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

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

#export_user(user_id, **options) ⇒ Object



278
279
280
# File 'lib/stream-chat/client.rb', line 278

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

#flag_message(id, **options) ⇒ Object



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

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

#flag_user(id, **options) ⇒ Object



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

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

#get(relative_url, params: nil) ⇒ Object



691
692
693
# File 'lib/stream-chat/client.rb', line 691

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

#get_app_settingsObject



115
116
117
# File 'lib/stream-chat/client.rb', line 115

def get_app_settings
  get('app')
end

#get_blocklist(name) ⇒ Object



575
576
577
# File 'lib/stream-chat/client.rb', line 575

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

#get_channel_type(channel_type) ⇒ Object



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

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

#get_command(name) ⇒ Object



750
751
752
# File 'lib/stream-chat/client.rb', line 750

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

#get_devices(user_id) ⇒ Object



499
500
501
# File 'lib/stream-chat/client.rb', line 499

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

#get_export_channel_status(task_id) ⇒ Object



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

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

#get_message(id) ⇒ Object



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

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

#get_permission(id) ⇒ Object



780
781
782
# File 'lib/stream-chat/client.rb', line 780

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

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



506
507
508
509
510
511
512
513
514
515
# File 'lib/stream-chat/client.rb', line 506

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



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

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

#list_blocklistsObject



563
564
565
# File 'lib/stream-chat/client.rb', line 563

def list_blocklists
  get('blocklists')
end

#list_channel_typesObject



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

def list_channel_types
  get('channeltypes')
end

#list_commandsObject



768
769
770
# File 'lib/stream-chat/client.rb', line 768

def list_commands
  get('commands')
end

#list_permissionsObject



774
775
776
# File 'lib/stream-chat/client.rb', line 774

def list_permissions
  get('permissions')
end

#list_push_providersObject



834
835
836
# File 'lib/stream-chat/client.rb', line 834

def list_push_providers
  get('push_providers')
end

#list_rolesObject



816
817
818
# File 'lib/stream-chat/client.rb', line 816

def list_roles
  get('roles')
end

#mark_all_read(user_id) ⇒ Object



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

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

#mute_user(target_id, user_id) ⇒ Object



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

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



701
702
703
# File 'lib/stream-chat/client.rb', line 701

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



347
348
349
350
351
352
353
354
355
# File 'lib/stream-chat/client.rb', line 347

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



686
687
688
# File 'lib/stream-chat/client.rb', line 686

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



681
682
683
# File 'lib/stream-chat/client.rb', line 681

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



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

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



427
428
429
430
431
432
433
434
# File 'lib/stream-chat/client.rb', line 427

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



166
167
168
169
# File 'lib/stream-chat/client.rb', line 166

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

#query_message_flags(filter_conditions, **options) ⇒ Object



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

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



412
413
414
415
416
417
418
# File 'lib/stream-chat/client.rb', line 412

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



271
272
273
# File 'lib/stream-chat/client.rb', line 271

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

#remove_shadow_ban(target_id, **options) ⇒ Object



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

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



173
174
175
176
177
178
179
180
# File 'lib/stream-chat/client.rb', line 173

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



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

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



659
660
661
# File 'lib/stream-chat/client.rb', line 659

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

#revoke_users_token(user_ids, before) ⇒ Object



665
666
667
668
669
670
671
672
673
674
675
676
677
678
# File 'lib/stream-chat/client.rb', line 665

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



540
541
542
# File 'lib/stream-chat/client.rb', line 540

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)


193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/stream-chat/client.rb', line 193

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



710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
# File 'lib/stream-chat/client.rb', line 710

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



526
527
528
# File 'lib/stream-chat/client.rb', line 526

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



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

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



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

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

#unban_user(target_id, **options) ⇒ Object



295
296
297
298
# File 'lib/stream-chat/client.rb', line 295

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



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

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

#unflag_user(id, **options) ⇒ Object



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

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



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

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



359
360
361
362
363
364
365
366
# File 'lib/stream-chat/client.rb', line 359

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



109
110
111
# File 'lib/stream-chat/client.rb', line 109

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

#update_blocklist(name, words) ⇒ Object



599
600
601
# File 'lib/stream-chat/client.rb', line 599

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

#update_channel_type(channel_type, **options) ⇒ Object



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

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

#update_command(name, command) ⇒ Object



756
757
758
# File 'lib/stream-chat/client.rb', line 756

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

#update_message(message) ⇒ Object

Raises:

  • (ArgumentError)


371
372
373
374
375
# File 'lib/stream-chat/client.rb', line 371

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



381
382
383
384
385
# File 'lib/stream-chat/client.rb', line 381

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



792
793
794
# File 'lib/stream-chat/client.rb', line 792

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

#update_user(user) ⇒ Object



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

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

#update_user_partial(update) ⇒ Object



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

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

#update_users(users) ⇒ Object



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

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

#update_users_partial(updates) ⇒ Object



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

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

#upsert_push_provider(push_provider) ⇒ Object



822
823
824
# File 'lib/stream-chat/client.rb', line 822

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

#upsert_user(user) ⇒ Object



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

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

#upsert_users(users) ⇒ Object



226
227
228
229
230
231
232
233
234
235
# File 'lib/stream-chat/client.rb', line 226

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



519
520
521
522
# File 'lib/stream-chat/client.rb', line 519

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