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)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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)
  @moderation = T.let(Moderation.new(self), Moderation)
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

#api_secretObject (readonly)

Returns the value of attribute api_secret.



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

def api_secret
  @api_secret
end

#connObject (readonly)

Returns the value of attribute conn.



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

def conn
  @conn
end

#moderationObject (readonly)

Returns the value of attribute moderation.



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

def moderation
  @moderation
end

Class Method Details

.from_env(**options) ⇒ Object



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

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



510
511
512
513
514
515
516
517
# File 'lib/stream-chat/client.rb', line 510

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



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

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



504
505
506
# File 'lib/stream-chat/client.rb', line 504

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

#check_push(push_data) ⇒ Object



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

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



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

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



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

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



392
393
394
# File 'lib/stream-chat/client.rb', line 392

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

#create_blocklist(name, words) ⇒ Object



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

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

#create_channel_type(data) ⇒ Object



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

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



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

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

#create_guest(user) ⇒ Object



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

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

#create_import(path, mode) ⇒ Object



916
917
918
# File 'lib/stream-chat/client.rb', line 916

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

#create_import_url(filename) ⇒ Object



906
907
908
# File 'lib/stream-chat/client.rb', line 906

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

#create_permission(permission) ⇒ Object



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

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

#create_role(name) ⇒ Object



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

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

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



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

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



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

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

#deactivate_users(user_ids, **options) ⇒ Object

Raises:

  • (ArgumentError)


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

def deactivate_users(user_ids, **options)
  raise ArgumentError, 'user_ids should not be empty' if user_ids.empty?

  post('users/deactivate', data: { user_ids: user_ids, **options })
end

#delete(relative_url, params: nil) ⇒ Object



734
735
736
# File 'lib/stream-chat/client.rb', line 734

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

#delete_blocklist(name) ⇒ Object



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

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

#delete_channel_type(channel_type) ⇒ Object



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

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

#delete_channels(cids, hard_delete: false) ⇒ Object



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

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

#delete_command(name) ⇒ Object



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

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

#delete_device(device_id, user_id) ⇒ Object



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

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

#delete_message(message_id, **options) ⇒ Object



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

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

#delete_permission(id) ⇒ Object



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

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

#delete_push_provider(type, name) ⇒ Object



890
891
892
# File 'lib/stream-chat/client.rb', line 890

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

#delete_role(name) ⇒ Object



872
873
874
# File 'lib/stream-chat/client.rb', line 872

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

#delete_user(user_id, **options) ⇒ Object



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

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



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

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



649
650
651
# File 'lib/stream-chat/client.rb', line 649

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

#export_user(user_id, **options) ⇒ Object



300
301
302
# File 'lib/stream-chat/client.rb', line 300

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

#export_users(user_ids) ⇒ Object



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

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

#flag_message(id, **options) ⇒ Object



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

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

#flag_user(id, **options) ⇒ Object



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

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

#get(relative_url, params: nil) ⇒ Object



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

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

#get_app_settingsObject



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

def get_app_settings
  get('app')
end

#get_blocklist(name) ⇒ Object



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

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

#get_channel_type(channel_type) ⇒ Object



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

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

#get_command(name) ⇒ Object



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

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

#get_devices(user_id) ⇒ Object



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

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

#get_export_channel_status(task_id) ⇒ Object



655
656
657
# File 'lib/stream-chat/client.rb', line 655

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

#get_import(id) ⇒ Object



922
923
924
# File 'lib/stream-chat/client.rb', line 922

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

#get_message(id, **options) ⇒ Object



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

def get_message(id, **options)
  get("messages/#{id}", params: options)
end

#get_permission(id) ⇒ Object



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

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

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



534
535
536
537
538
539
540
541
542
543
# File 'lib/stream-chat/client.rb', line 534

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



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

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

#list_blocklistsObject



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

def list_blocklists
  get('blocklists')
end

#list_channel_typesObject



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

def list_channel_types
  get('channeltypes')
end

#list_commandsObject



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

def list_commands
  get('commands')
end

#list_imports(options) ⇒ Object



928
929
930
# File 'lib/stream-chat/client.rb', line 928

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

#list_permissionsObject



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

def list_permissions
  get('permissions')
end

#list_push_providersObject



896
897
898
# File 'lib/stream-chat/client.rb', line 896

def list_push_providers
  get('push_providers')
end

#list_rolesObject



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

def list_roles
  get('roles')
end

#mark_all_read(user_id) ⇒ Object



357
358
359
360
# File 'lib/stream-chat/client.rb', line 357

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

#mute_user(target_id, user_id) ⇒ Object



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

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



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

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



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

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



724
725
726
# File 'lib/stream-chat/client.rb', line 724

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



719
720
721
# File 'lib/stream-chat/client.rb', line 719

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



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

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



455
456
457
458
459
460
461
462
# File 'lib/stream-chat/client.rb', line 455

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_drafts(user_id, filter: nil, sort: nil, **options) ⇒ Object



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

def query_drafts(user_id, filter: nil, sort: nil, **options)
  data = { user_id: user_id }
  data['filter'] = filter if filter
  data['sort'] = sort if sort
  data.merge!(options) if options
  post('drafts/query', data: data)
end

#query_flag_reports(**options) ⇒ Object



168
169
170
171
# File 'lib/stream-chat/client.rb', line 168

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

#query_message_flags(filter_conditions, **options) ⇒ Object



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

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_threads(filter, sort: nil, **options) ⇒ Object



933
934
935
936
937
938
939
940
# File 'lib/stream-chat/client.rb', line 933

def query_threads(filter, sort: nil, **options)
  params = {}.merge(options).merge({
                                     filter: filter,
                                     sort: StreamChat.get_sort_fields(sort)
                                   })

  post('threads', data: params)
end

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



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

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



293
294
295
# File 'lib/stream-chat/client.rb', line 293

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

#remove_shadow_ban(target_id, **options) ⇒ Object



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

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



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

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

#restore_users(user_ids) ⇒ Object



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

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



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

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



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

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



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

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

#revoke_users_token(user_ids, before) ⇒ Object



703
704
705
706
707
708
709
710
711
712
713
714
715
716
# File 'lib/stream-chat/client.rb', line 703

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



568
569
570
# File 'lib/stream-chat/client.rb', line 568

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)


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

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



748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
# File 'lib/stream-chat/client.rb', line 748

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



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

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

#set_http_client(client) ⇒ Object



91
92
93
# File 'lib/stream-chat/client.rb', line 91

def set_http_client(client)
  @conn = client
end

#shadow_ban(target_id, **options) ⇒ Object



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

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



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

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

#unban_user(target_id, **options) ⇒ Object



317
318
319
320
# File 'lib/stream-chat/client.rb', line 317

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



134
135
136
137
# File 'lib/stream-chat/client.rb', line 134

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

#unflag_user(id, **options) ⇒ Object



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

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



350
351
352
353
# File 'lib/stream-chat/client.rb', line 350

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



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

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



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

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

#update_blocklist(name, words) ⇒ Object



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

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

#update_channel_type(channel_type, **options) ⇒ Object



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

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

#update_command(name, command) ⇒ Object



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

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

#update_message(message) ⇒ Object

Raises:

  • (ArgumentError)


399
400
401
402
403
# File 'lib/stream-chat/client.rb', line 399

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



409
410
411
412
413
# File 'lib/stream-chat/client.rb', line 409

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



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

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

#update_user(user) ⇒ Object



221
222
223
224
# File 'lib/stream-chat/client.rb', line 221

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

#update_user_partial(update) ⇒ Object



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

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

#update_users(users) ⇒ Object



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

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

#update_users_partial(updates) ⇒ Object



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

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

#upsert_push_provider(push_provider) ⇒ Object



884
885
886
# File 'lib/stream-chat/client.rb', line 884

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

#upsert_user(user) ⇒ Object



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

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

#upsert_users(users) ⇒ Object



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

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



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

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