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)


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

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.



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

def api_key
  @api_key
end

#api_secretObject (readonly)

Returns the value of attribute api_secret.



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

def api_secret
  @api_secret
end

#connObject (readonly)

Returns the value of attribute conn.



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

def conn
  @conn
end

Class Method Details

.from_env(**options) ⇒ Object



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

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) }.merge(options))
end

Instance Method Details

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



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

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



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

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



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

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

#check_push(push_data) ⇒ Object



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

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

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



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

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



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

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

#create_campaign(campaign) ⇒ Object



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

def create_campaign(campaign)
  post('campaigns', data: { campaign: campaign })
end

#create_channel_type(data) ⇒ Object



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

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



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

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

#create_guest(user) ⇒ Object



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

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

#create_import(path, mode) ⇒ Object



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

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

#create_import_url(filename) ⇒ Object



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

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

#create_permission(permission) ⇒ Object



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

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

#create_role(name) ⇒ Object



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

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

#create_segment(segment) ⇒ Object



925
926
927
# File 'lib/stream-chat/client.rb', line 925

def create_segment(segment)
  post('segments', data: { segment: segment })
end

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



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

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



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

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

#delete(relative_url, params: nil) ⇒ Object



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

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

#delete_blocklist(name) ⇒ Object



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

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

#delete_campaign(campaign_id) ⇒ Object



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

def delete_campaign(campaign_id)
  delete("campaigns/#{campaign_id}")
end

#delete_channel_type(channel_type) ⇒ Object



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

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

#delete_channels(cids, hard_delete: false) ⇒ Object



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

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

#delete_command(name) ⇒ Object



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

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

#delete_device(device_id, user_id) ⇒ Object



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

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

#delete_message(message_id, **options) ⇒ Object



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

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

#delete_permission(id) ⇒ Object



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

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

#delete_push_provider(type, name) ⇒ Object



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

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

#delete_role(name) ⇒ Object



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

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

#delete_segment(segment_id) ⇒ Object



949
950
951
# File 'lib/stream-chat/client.rb', line 949

def delete_segment(segment_id)
  delete("segments/#{segment_id}")
end

#delete_user(user_id, **options) ⇒ Object



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

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



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

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



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

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

#export_user(user_id, **options) ⇒ Object



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

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

#flag_message(id, **options) ⇒ Object



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

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

#flag_user(id, **options) ⇒ Object



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

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

#get(relative_url, params: nil) ⇒ Object



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

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

#get_app_settingsObject



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

def get_app_settings
  get('app')
end

#get_blocklist(name) ⇒ Object



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

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

#get_campaign(campaign_id) ⇒ Object



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

def get_campaign(campaign_id)
  get("campaigns/#{campaign_id}")
end

#get_channel_type(channel_type) ⇒ Object



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

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

#get_command(name) ⇒ Object



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

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

#get_devices(user_id) ⇒ Object



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

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

#get_export_channel_status(task_id) ⇒ Object



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

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

#get_import(id) ⇒ Object



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

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

#get_message(id) ⇒ Object



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

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

#get_permission(id) ⇒ Object



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

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

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



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

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_segment(segment_id) ⇒ Object



931
932
933
# File 'lib/stream-chat/client.rb', line 931

def get_segment(segment_id)
  get("segments/#{segment_id}")
end

#get_task(task_id) ⇒ Object



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

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

#list_blocklistsObject



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

def list_blocklists
  get('blocklists')
end

#list_campaigns(options) ⇒ Object



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

def list_campaigns(options)
  get('campaigns', params: options)
end

#list_channel_typesObject



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

def list_channel_types
  get('channeltypes')
end

#list_commandsObject



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

def list_commands
  get('commands')
end

#list_imports(options) ⇒ Object



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

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

#list_permissionsObject



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

def list_permissions
  get('permissions')
end

#list_push_providersObject



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

def list_push_providers
  get('push_providers')
end

#list_rolesObject



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

def list_roles
  get('roles')
end

#list_segments(options) ⇒ Object



937
938
939
# File 'lib/stream-chat/client.rb', line 937

def list_segments(options)
  get('segments', params: options)
end

#mark_all_read(user_id) ⇒ Object



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

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

#mute_user(target_id, user_id) ⇒ Object



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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

#query_message_flags(filter_conditions, **options) ⇒ Object



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

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



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

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



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

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

#remove_shadow_ban(target_id, **options) ⇒ Object



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

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

#resume_campaign(campaign_id) ⇒ Object



913
914
915
# File 'lib/stream-chat/client.rb', line 913

def resume_campaign(campaign_id)
  patch("campaigns/#{campaign_id}/resume")
end

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



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

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



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

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



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

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

#revoke_users_token(user_ids, before) ⇒ Object



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

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



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

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

#schedule_campaign(campaign_id, send_at) ⇒ Object



901
902
903
# File 'lib/stream-chat/client.rb', line 901

def schedule_campaign(campaign_id, send_at)
  patch("campaigns/#{campaign_id}/schedule", data: { send_at: send_at })
end

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

Raises:

  • (ArgumentError)


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

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



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

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



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

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

#set_http_client(client) ⇒ Object



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

def set_http_client(client)
  @conn = client
end

#shadow_ban(target_id, **options) ⇒ Object



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

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

#stop_campaign(campaign_id) ⇒ Object



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

def stop_campaign(campaign_id)
  patch("campaigns/#{campaign_id}/stop")
end

#test_campaign(campaign_id, users) ⇒ Object



919
920
921
# File 'lib/stream-chat/client.rb', line 919

def test_campaign(campaign_id, users)
  post("campaigns/#{campaign_id}/test", data: { users: users })
end

#translate_message(message_id, language) ⇒ Object



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

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

#unban_user(target_id, **options) ⇒ Object



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

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



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

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

#unflag_user(id, **options) ⇒ Object



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

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



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

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



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

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



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

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

#update_blocklist(name, words) ⇒ Object



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

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

#update_campaign(campaign_id, campaign) ⇒ Object



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

def update_campaign(campaign_id, campaign)
  put("campaigns/#{campaign_id}", data: { campaign: campaign })
end

#update_channel_type(channel_type, **options) ⇒ Object



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

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

#update_command(name, command) ⇒ Object



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

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

#update_message(message) ⇒ Object

Raises:

  • (ArgumentError)


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

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



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

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



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

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

#update_segment(segment_id, segment) ⇒ Object



943
944
945
# File 'lib/stream-chat/client.rb', line 943

def update_segment(segment_id, segment)
  put("segments/#{segment_id}", data: { segment: segment })
end

#update_user(user) ⇒ Object



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

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

#update_user_partial(update) ⇒ Object



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

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

#update_users(users) ⇒ Object



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

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

#update_users_partial(updates) ⇒ Object



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

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

#upsert_push_provider(push_provider) ⇒ Object



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

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

#upsert_user(user) ⇒ Object



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

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

#upsert_users(users) ⇒ Object



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

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



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

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