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 =
'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)


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/stream-chat/client.rb', line 49

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.



30
31
32
# File 'lib/stream-chat/client.rb', line 30

def api_key
  @api_key
end

#api_secretObject (readonly)

Returns the value of attribute api_secret.



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

def api_secret
  @api_secret
end

#connObject (readonly)

Returns the value of attribute conn.



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

def conn
  @conn
end

Class Method Details

.from_env(**options) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/stream-chat/client.rb', line 74

def self.from_env(**options)
  Client.new(ENV.fetch('STREAM_KEY'),
             ENV.fetch('STREAM_SECRET'),
             ENV.fetch('STREAM_CHAT_TIMEOUT', DEFAULT_TIMEOUT),
             base_url: ENV.fetch('STREAM_CHAT_URL', DEFAULT_BASE_URL),
             **options)
end

Instance Method Details

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



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

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



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

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



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

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

#check_push(push_data) ⇒ Object



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

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

#check_sns(sns_key = nil, sns_secret = nil, sns_topic_arn = nil) ⇒ Object



771
772
773
# File 'lib/stream-chat/client.rb', line 771

def check_sns(sns_key = nil, sns_secret = nil, sns_topic_arn = nil)
  post('check_sns', data: { sns_key: sns_key, sns_secret: sns_secret, sns_topic_arn: sns_topic_arn })
end

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



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

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

#commit_message(message_id) ⇒ Object



379
380
381
# File 'lib/stream-chat/client.rb', line 379

def commit_message(message_id)
  post("messages/#{message_id}/commit")
end

#create_blocklist(name, words) ⇒ Object



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

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

#create_channel_type(data) ⇒ Object



453
454
455
456
# File 'lib/stream-chat/client.rb', line 453

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



777
778
779
# File 'lib/stream-chat/client.rb', line 777

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

#create_guest(user) ⇒ Object



566
567
568
# File 'lib/stream-chat/client.rb', line 566

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

#create_import(path, mode) ⇒ Object



887
888
889
# File 'lib/stream-chat/client.rb', line 887

def create_import(path, mode)
  post('imports', data: { path: path, mode: mode })
end

#create_import_url(filename) ⇒ Object



877
878
879
# File 'lib/stream-chat/client.rb', line 877

def create_import_url(filename)
  post('import_urls', data: { filename: filename })
end

#create_permission(permission) ⇒ Object



819
820
821
# File 'lib/stream-chat/client.rb', line 819

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

#create_role(name) ⇒ Object



837
838
839
# File 'lib/stream-chat/client.rb', line 837

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

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



97
98
99
100
101
102
# File 'lib/stream-chat/client.rb', line 97

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



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

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

#delete(relative_url, params: nil) ⇒ Object



721
722
723
# File 'lib/stream-chat/client.rb', line 721

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

#delete_blocklist(name) ⇒ Object



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

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

#delete_channel_type(channel_type) ⇒ Object



478
479
480
# File 'lib/stream-chat/client.rb', line 478

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

#delete_channels(cids, hard_delete: false) ⇒ Object



671
672
673
# File 'lib/stream-chat/client.rb', line 671

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

#delete_command(name) ⇒ Object



795
796
797
# File 'lib/stream-chat/client.rb', line 795

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

#delete_device(device_id, user_id) ⇒ Object



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

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

#delete_message(message_id, **options) ⇒ Object



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

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

#delete_permission(id) ⇒ Object



831
832
833
# File 'lib/stream-chat/client.rb', line 831

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

#delete_push_provider(type, name) ⇒ Object



861
862
863
# File 'lib/stream-chat/client.rb', line 861

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

#delete_role(name) ⇒ Object



843
844
845
# File 'lib/stream-chat/client.rb', line 843

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

#delete_user(user_id, **options) ⇒ Object



254
255
256
# File 'lib/stream-chat/client.rb', line 254

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



664
665
666
# File 'lib/stream-chat/client.rb', line 664

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



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

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

#export_user(user_id, **options) ⇒ Object



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

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

#export_users(user_ids) ⇒ Object



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

def export_users(user_ids)
  post('export/users', data: { user_ids: user_ids })
end

#flag_message(id, **options) ⇒ Object



122
123
124
125
# File 'lib/stream-chat/client.rb', line 122

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

#flag_user(id, **options) ⇒ Object



149
150
151
152
# File 'lib/stream-chat/client.rb', line 149

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

#get(relative_url, params: nil) ⇒ Object



716
717
718
# File 'lib/stream-chat/client.rb', line 716

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

#get_app_settingsObject



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

def get_app_settings
  get('app')
end

#get_blocklist(name) ⇒ Object



590
591
592
# File 'lib/stream-chat/client.rb', line 590

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

#get_channel_type(channel_type) ⇒ Object



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

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

#get_command(name) ⇒ Object



783
784
785
# File 'lib/stream-chat/client.rb', line 783

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

#get_devices(user_id) ⇒ Object



514
515
516
# File 'lib/stream-chat/client.rb', line 514

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

#get_export_channel_status(task_id) ⇒ Object



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

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

#get_import(id) ⇒ Object



893
894
895
# File 'lib/stream-chat/client.rb', line 893

def get_import(id)
  get("imports/#{id}")
end

#get_message(id) ⇒ Object



181
182
183
# File 'lib/stream-chat/client.rb', line 181

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

#get_permission(id) ⇒ Object



813
814
815
# File 'lib/stream-chat/client.rb', line 813

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

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



521
522
523
524
525
526
527
528
529
530
# File 'lib/stream-chat/client.rb', line 521

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



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

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

#list_blocklistsObject



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

def list_blocklists
  get('blocklists')
end

#list_channel_typesObject



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

def list_channel_types
  get('channeltypes')
end

#list_commandsObject



801
802
803
# File 'lib/stream-chat/client.rb', line 801

def list_commands
  get('commands')
end

#list_imports(options) ⇒ Object



899
900
901
# File 'lib/stream-chat/client.rb', line 899

def list_imports(options)
  get('imports', params: options)
end

#list_permissionsObject



807
808
809
# File 'lib/stream-chat/client.rb', line 807

def list_permissions
  get('permissions')
end

#list_push_providersObject



867
868
869
# File 'lib/stream-chat/client.rb', line 867

def list_push_providers
  get('push_providers')
end

#list_rolesObject



849
850
851
# File 'lib/stream-chat/client.rb', line 849

def list_roles
  get('roles')
end

#mark_all_read(user_id) ⇒ Object



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

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

#mute_user(target_id, user_id) ⇒ Object



330
331
332
333
# File 'lib/stream-chat/client.rb', line 330

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



726
727
728
# File 'lib/stream-chat/client.rb', line 726

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



356
357
358
359
360
361
362
363
364
# File 'lib/stream-chat/client.rb', line 356

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



711
712
713
# File 'lib/stream-chat/client.rb', line 711

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



706
707
708
# File 'lib/stream-chat/client.rb', line 706

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



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

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



442
443
444
445
446
447
448
449
# File 'lib/stream-chat/client.rb', line 442

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



163
164
165
166
# File 'lib/stream-chat/client.rb', line 163

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

#query_message_flags(filter_conditions, **options) ⇒ Object



140
141
142
143
144
145
# File 'lib/stream-chat/client.rb', line 140

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



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

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



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

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

#remove_shadow_ban(target_id, **options) ⇒ Object



323
324
325
326
# File 'lib/stream-chat/client.rb', line 323

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

#restore_user(user_id) ⇒ Object



260
261
262
# File 'lib/stream-chat/client.rb', line 260

def restore_user(user_id)
  post('users/restore', data: { user_ids: [user_id] })
end

#restore_users(user_ids) ⇒ Object



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

def restore_users(user_ids)
  post('users/restore', data: { user_ids: user_ids })
end

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



170
171
172
173
174
175
176
177
# File 'lib/stream-chat/client.rb', line 170

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



677
678
679
680
# File 'lib/stream-chat/client.rb', line 677

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



684
685
686
# File 'lib/stream-chat/client.rb', line 684

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

#revoke_users_token(user_ids, before) ⇒ Object



690
691
692
693
694
695
696
697
698
699
700
701
702
703
# File 'lib/stream-chat/client.rb', line 690

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

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

#run_message_action(message_id, data) ⇒ Object



555
556
557
# File 'lib/stream-chat/client.rb', line 555

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)


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

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



735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
# File 'lib/stream-chat/client.rb', line 735

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



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

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

#set_http_client(client) ⇒ Object



86
87
88
# File 'lib/stream-chat/client.rb', line 86

def set_http_client(client)
  @conn = client
end

#shadow_ban(target_id, **options) ⇒ Object



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

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



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

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

#unban_user(target_id, **options) ⇒ Object



304
305
306
307
# File 'lib/stream-chat/client.rb', line 304

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



129
130
131
132
# File 'lib/stream-chat/client.rb', line 129

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

#unflag_user(id, **options) ⇒ Object



156
157
158
159
# File 'lib/stream-chat/client.rb', line 156

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



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

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



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

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



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

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

#update_blocklist(name, words) ⇒ Object



614
615
616
# File 'lib/stream-chat/client.rb', line 614

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

#update_channel_type(channel_type, **options) ⇒ Object



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

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

#update_command(name, command) ⇒ Object



789
790
791
# File 'lib/stream-chat/client.rb', line 789

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

#update_message(message) ⇒ Object

Raises:

  • (ArgumentError)


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

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



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

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



825
826
827
# File 'lib/stream-chat/client.rb', line 825

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

#update_user(user) ⇒ Object



216
217
218
219
# File 'lib/stream-chat/client.rb', line 216

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

#update_user_partial(update) ⇒ Object



248
249
250
# File 'lib/stream-chat/client.rb', line 248

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

#update_users(users) ⇒ Object



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

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

#update_users_partial(updates) ⇒ Object



242
243
244
# File 'lib/stream-chat/client.rb', line 242

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

#upsert_push_provider(push_provider) ⇒ Object



855
856
857
# File 'lib/stream-chat/client.rb', line 855

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

#upsert_user(user) ⇒ Object



236
237
238
# File 'lib/stream-chat/client.rb', line 236

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

#upsert_users(users) ⇒ Object



223
224
225
226
227
228
229
230
231
232
# File 'lib/stream-chat/client.rb', line 223

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



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

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