Class: StreamChat::Client
- Inherits:
-
Object
- Object
- StreamChat::Client
- 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
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_secret ⇒ Object
readonly
Returns the value of attribute api_secret.
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
-
#moderation ⇒ Object
readonly
Returns the value of attribute moderation.
Class Method Summary collapse
Instance Method Summary collapse
- #add_device(device_id, push_provider, user_id, push_provider_name = nil) ⇒ Object
- #ban_user(target_id, **options) ⇒ Object
- #channel(channel_type, channel_id: nil, data: nil) ⇒ Object
- #check_push(push_data) ⇒ Object
- #check_sns(sns_key = nil, sns_secret = nil, sns_topic_arn = nil) ⇒ Object
- #check_sqs(sqs_key = nil, sqs_secret = nil, sqs_url = nil) ⇒ Object
- #commit_message(message_id) ⇒ Object
- #create_blocklist(name, words) ⇒ Object
- #create_channel_type(data) ⇒ Object
- #create_command(command) ⇒ Object
- #create_guest(user) ⇒ Object
- #create_import(path, mode) ⇒ Object
- #create_import_url(filename) ⇒ Object
- #create_permission(permission) ⇒ Object
- #create_reminder(message_id, user_id, remind_at = nil) ⇒ Object
- #create_role(name) ⇒ Object
- #create_token(user_id, exp = nil, iat = nil) ⇒ Object
- #deactivate_user(user_id, **options) ⇒ Object
- #deactivate_users(user_ids, **options) ⇒ Object
- #delete(relative_url, params: nil) ⇒ Object
- #delete_blocklist(name) ⇒ Object
- #delete_channel_type(channel_type) ⇒ Object
- #delete_channels(cids, hard_delete: false) ⇒ Object
- #delete_command(name) ⇒ Object
- #delete_device(device_id, user_id) ⇒ Object
- #delete_message(message_id, **options) ⇒ Object
- #delete_message_for_me(message_id, user_id) ⇒ Object
- #delete_message_with_options(message_id, hard: nil, delete_for_me: nil, user_id: nil) ⇒ Object
- #delete_permission(id) ⇒ Object
- #delete_push_provider(type, name) ⇒ Object
- #delete_reminder(message_id, user_id) ⇒ Object
- #delete_role(name) ⇒ Object
- #delete_user(user_id, **options) ⇒ Object
- #delete_users(user_ids, user: SOFT_DELETE, messages: nil, conversations: nil) ⇒ Object
- #export_channels(*channels, **options) ⇒ Object
- #export_user(user_id, **options) ⇒ Object
- #export_users(user_ids) ⇒ Object
- #flag_message(id, **options) ⇒ Object
- #flag_user(id, **options) ⇒ Object
- #get(relative_url, params: nil) ⇒ Object
- #get_active_live_locations(user_id) ⇒ Object
- #get_app_settings ⇒ Object
- #get_blocklist(name) ⇒ Object
- #get_channel_type(channel_type) ⇒ Object
- #get_command(name) ⇒ Object
- #get_devices(user_id) ⇒ Object
- #get_export_channel_status(task_id) ⇒ Object
- #get_import(id) ⇒ Object
- #get_message(id, **options) ⇒ Object
- #get_permission(id) ⇒ Object
- #get_rate_limits(server_side: false, android: false, ios: false, web: false, endpoints: []) ⇒ Object
- #get_task(task_id) ⇒ Object
- #hard_delete_message(message_id) ⇒ Object
-
#initialize(api_key, api_secret, timeout = nil, **options) ⇒ Client
constructor
A new instance of Client.
- #list_blocklists ⇒ Object
- #list_channel_types ⇒ Object
- #list_commands ⇒ Object
- #list_imports(options) ⇒ Object
- #list_permissions ⇒ Object
- #list_push_providers ⇒ Object
- #list_roles ⇒ Object
- #mark_all_read(user_id) ⇒ Object
- #mute_user(target_id, user_id) ⇒ Object
- #patch(relative_url, params: nil, data: nil) ⇒ Object
- #pin_message(message_id, user_id, expiration: nil) ⇒ Object
- #post(relative_url, params: nil, data: nil) ⇒ Object
- #put(relative_url, params: nil, data: nil) ⇒ Object
- #query_banned_users(filter_conditions, sort: nil, **options) ⇒ Object
- #query_channels(filter_conditions, sort: nil, **options) ⇒ Object
- #query_drafts(user_id, filter: nil, sort: nil, **options) ⇒ Object
- #query_flag_reports(**options) ⇒ Object
- #query_message_flags(filter_conditions, **options) ⇒ Object
- #query_reminders(user_id, filter_conditions = {}, sort: nil, **options) ⇒ Object
- #query_threads(filter, sort: nil, **options) ⇒ Object
- #query_users(filter_conditions, sort: nil, **options) ⇒ Object
- #reactivate_user(user_id, **options) ⇒ Object
- #remove_shadow_ban(target_id, **options) ⇒ Object
- #restore_user(user_id) ⇒ Object
- #restore_users(user_ids) ⇒ Object
- #review_flag_report(report_id, review_result, user_id, **details) ⇒ Object
- #revoke_tokens(before) ⇒ Object
- #revoke_user_token(user_id, before) ⇒ Object
- #revoke_users_token(user_ids, before) ⇒ Object
- #run_message_action(message_id, data) ⇒ Object
- #search(filter_conditions, query, sort: nil, **options) ⇒ Object
- #send_file(relative_url, file_url, user, content_type = nil) ⇒ Object
- #send_user_event(user_id, event) ⇒ Object
- #set_http_client(client) ⇒ Object
- #shadow_ban(target_id, **options) ⇒ Object
- #translate_message(message_id, language) ⇒ Object
- #unban_user(target_id, **options) ⇒ Object
- #undelete_message(message_id, undeleted_by, **options) ⇒ Object
- #unflag_message(id, **options) ⇒ Object
- #unflag_user(id, **options) ⇒ Object
- #unmute_user(target_id, user_id) ⇒ Object
- #unpin_message(message_id, user_id) ⇒ Object
- #unread_counts(user_id) ⇒ Object
- #unread_counts_batch(user_ids) ⇒ Object
- #update_app_settings(**settings) ⇒ Object
- #update_blocklist(name, words) ⇒ Object
- #update_channel_type(channel_type, **options) ⇒ Object
- #update_command(name, command) ⇒ Object
- #update_location(user_id, created_by_device_id:, message_id:, **options) ⇒ Object
- #update_message(message) ⇒ Object
- #update_message_partial(message_id, updates, user_id: nil, **options) ⇒ Object
- #update_permission(id, permission) ⇒ Object
- #update_reminder(message_id, user_id, remind_at = nil) ⇒ Object
- #update_user(user) ⇒ Object
- #update_user_partial(update) ⇒ Object
- #update_users(users) ⇒ Object
- #update_users_partial(updates) ⇒ Object
- #upsert_push_provider(push_provider) ⇒ Object
- #upsert_user(user) ⇒ Object
- #upsert_users(users) ⇒ Object
- #verify_webhook(request_body, x_signature) ⇒ Object
Constructor Details
#initialize(api_key, api_secret, timeout = nil, **options) ⇒ Client
Returns a new instance of Client.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/stream-chat/client.rb', line 54 def initialize(api_key, api_secret, timeout = nil, **) 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([:base_url] || DEFAULT_BASE_URL, String) conn = Faraday.new(@base_url) do |faraday| faraday.[:open_timeout] = @timeout faraday.[: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_key ⇒ Object (readonly)
Returns the value of attribute api_key.
32 33 34 |
# File 'lib/stream-chat/client.rb', line 32 def api_key @api_key end |
#api_secret ⇒ Object (readonly)
Returns the value of attribute api_secret.
35 36 37 |
# File 'lib/stream-chat/client.rb', line 35 def api_secret @api_secret end |
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
38 39 40 |
# File 'lib/stream-chat/client.rb', line 38 def conn @conn end |
#moderation ⇒ Object (readonly)
Returns the value of attribute moderation.
41 42 43 |
# File 'lib/stream-chat/client.rb', line 41 def moderation @moderation end |
Class Method Details
.from_env(**options) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/stream-chat/client.rb', line 80 def self.from_env(**) 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), **) end |
Instance Method Details
#add_device(device_id, push_provider, user_id, push_provider_name = nil) ⇒ Object
560 561 562 563 564 565 566 567 |
# File 'lib/stream-chat/client.rb', line 560 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
310 311 312 313 |
# File 'lib/stream-chat/client.rb', line 310 def ban_user(target_id, **) payload = { target_user_id: target_id }.merge() post('moderation/ban', data: payload) end |
#channel(channel_type, channel_id: nil, data: nil) ⇒ Object
554 555 556 |
# File 'lib/stream-chat/client.rb', line 554 def channel(channel_type, channel_id: nil, data: nil) StreamChat::Channel.new(self, channel_type, channel_id, data) end |
#check_push(push_data) ⇒ Object
818 819 820 |
# File 'lib/stream-chat/client.rb', line 818 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
834 835 836 |
# File 'lib/stream-chat/client.rb', line 834 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
826 827 828 |
# File 'lib/stream-chat/client.rb', line 826 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
405 406 407 |
# File 'lib/stream-chat/client.rb', line 405 def () post("messages/#{}/commit") end |
#create_blocklist(name, words) ⇒ Object
665 666 667 |
# File 'lib/stream-chat/client.rb', line 665 def create_blocklist(name, words) post('blocklists', data: { name: name, words: words }) end |
#create_channel_type(data) ⇒ Object
516 517 518 519 |
# File 'lib/stream-chat/client.rb', line 516 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
840 841 842 |
# File 'lib/stream-chat/client.rb', line 840 def create_command(command) post('commands', data: command) end |
#create_guest(user) ⇒ Object
629 630 631 |
# File 'lib/stream-chat/client.rb', line 629 def create_guest(user) post('guests', data: user) end |
#create_import(path, mode) ⇒ Object
993 994 995 |
# File 'lib/stream-chat/client.rb', line 993 def create_import(path, mode) post('imports', data: { path: path, mode: mode }) end |
#create_import_url(filename) ⇒ Object
983 984 985 |
# File 'lib/stream-chat/client.rb', line 983 def create_import_url(filename) post('import_urls', data: { filename: filename }) end |
#create_permission(permission) ⇒ Object
925 926 927 |
# File 'lib/stream-chat/client.rb', line 925 def () post('permissions', data: ) end |
#create_reminder(message_id, user_id, remind_at = nil) ⇒ Object
1025 1026 1027 1028 1029 |
# File 'lib/stream-chat/client.rb', line 1025 def create_reminder(, user_id, remind_at = nil) data = { user_id: user_id } data[:remind_at] = remind_at.rfc3339 if remind_at.instance_of?(DateTime) post("messages/#{}/reminders", data: data) end |
#create_role(name) ⇒ Object
943 944 945 |
# File 'lib/stream-chat/client.rb', line 943 def create_role(name) post('roles', data: { name: name }) end |
#create_token(user_id, exp = nil, iat = nil) ⇒ Object
103 104 105 106 107 108 |
# File 'lib/stream-chat/client.rb', line 103 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
280 281 282 |
# File 'lib/stream-chat/client.rb', line 280 def deactivate_user(user_id, **) post("users/#{user_id}/deactivate", params: ) end |
#deactivate_users(user_ids, **options) ⇒ Object
286 287 288 289 290 |
# File 'lib/stream-chat/client.rb', line 286 def deactivate_users(user_ids, **) raise ArgumentError, 'user_ids should not be empty' if user_ids.empty? post('users/deactivate', data: { user_ids: user_ids, ** }) end |
#delete(relative_url, params: nil) ⇒ Object
784 785 786 |
# File 'lib/stream-chat/client.rb', line 784 def delete(relative_url, params: nil) make_http_request(:delete, relative_url, params: params) end |
#delete_blocklist(name) ⇒ Object
689 690 691 |
# File 'lib/stream-chat/client.rb', line 689 def delete_blocklist(name) delete("blocklists/#{name}") end |
#delete_channel_type(channel_type) ⇒ Object
541 542 543 |
# File 'lib/stream-chat/client.rb', line 541 def delete_channel_type(channel_type) delete("channeltypes/#{channel_type}") end |
#delete_channels(cids, hard_delete: false) ⇒ Object
734 735 736 |
# File 'lib/stream-chat/client.rb', line 734 def delete_channels(cids, hard_delete: false) post('channels/delete', data: { cids: cids, hard_delete: hard_delete }) end |
#delete_command(name) ⇒ Object
901 902 903 |
# File 'lib/stream-chat/client.rb', line 901 def delete_command(name) delete("commands/#{name}") end |
#delete_device(device_id, user_id) ⇒ Object
571 572 573 |
# File 'lib/stream-chat/client.rb', line 571 def delete_device(device_id, user_id) delete('devices', params: { id: device_id, user_id: user_id }) end |
#delete_message(message_id, **options) ⇒ Object
430 431 432 |
# File 'lib/stream-chat/client.rb', line 430 def (, **) delete("messages/#{}", params: ) end |
#delete_message_for_me(message_id, user_id) ⇒ Object
442 443 444 445 446 |
# File 'lib/stream-chat/client.rb', line 442 def (, user_id) raise ArgumentError, 'user_id must not be empty for delete_for_me functionality' if user_id.to_s.empty? (, delete_for_me: true, deleted_by: user_id) end |
#delete_message_with_options(message_id, hard: nil, delete_for_me: nil, user_id: nil) ⇒ Object
450 451 452 453 454 455 456 457 458 459 460 461 462 |
# File 'lib/stream-chat/client.rb', line 450 def (, hard: nil, delete_for_me: nil, user_id: nil) = {} [:hard] = true if hard if delete_for_me raise ArgumentError, 'user_id must not be empty for delete_for_me functionality' if user_id.to_s.empty? [:delete_for_me] = true [:deleted_by] = user_id end (, **) end |
#delete_permission(id) ⇒ Object
937 938 939 |
# File 'lib/stream-chat/client.rb', line 937 def (id) delete("permissions/#{id}") end |
#delete_push_provider(type, name) ⇒ Object
967 968 969 |
# File 'lib/stream-chat/client.rb', line 967 def delete_push_provider(type, name) delete("push_providers/#{type}/#{name}") end |
#delete_reminder(message_id, user_id) ⇒ Object
1048 1049 1050 |
# File 'lib/stream-chat/client.rb', line 1048 def delete_reminder(, user_id) delete("messages/#{}/reminders", params: { user_id: user_id }) end |
#delete_role(name) ⇒ Object
949 950 951 |
# File 'lib/stream-chat/client.rb', line 949 def delete_role(name) delete("roles/#{name}") end |
#delete_user(user_id, **options) ⇒ Object
260 261 262 |
# File 'lib/stream-chat/client.rb', line 260 def delete_user(user_id, **) delete("users/#{user_id}", params: ) end |
#delete_users(user_ids, user: SOFT_DELETE, messages: nil, conversations: nil) ⇒ Object
727 728 729 |
# File 'lib/stream-chat/client.rb', line 727 def delete_users(user_ids, user: SOFT_DELETE, messages: nil, conversations: nil) post('users/delete', data: { user_ids: user_ids, user: user, messages: , conversations: conversations }) end |
#export_channels(*channels, **options) ⇒ Object
699 700 701 |
# File 'lib/stream-chat/client.rb', line 699 def export_channels(*channels, **) post('export_channels', data: { channels: channels, ** }) end |
#export_user(user_id, **options) ⇒ Object
301 302 303 |
# File 'lib/stream-chat/client.rb', line 301 def export_user(user_id, **) get("users/#{user_id}/export", params: ) end |
#export_users(user_ids) ⇒ Object
715 716 717 |
# File 'lib/stream-chat/client.rb', line 715 def export_users(user_ids) post('export/users', data: { user_ids: user_ids }) end |
#flag_message(id, **options) ⇒ Object
128 129 130 131 |
# File 'lib/stream-chat/client.rb', line 128 def (id, **) payload = { target_message_id: id }.merge() post('moderation/flag', data: payload) end |
#flag_user(id, **options) ⇒ Object
155 156 157 158 |
# File 'lib/stream-chat/client.rb', line 155 def flag_user(id, **) payload = { target_user_id: id }.merge() post('moderation/flag', data: payload) end |
#get(relative_url, params: nil) ⇒ Object
779 780 781 |
# File 'lib/stream-chat/client.rb', line 779 def get(relative_url, params: nil) make_http_request(:get, relative_url, params: params) end |
#get_active_live_locations(user_id) ⇒ Object
864 865 866 |
# File 'lib/stream-chat/client.rb', line 864 def get_active_live_locations(user_id) get('users/live_locations', params: { user_id: user_id }) end |
#get_app_settings ⇒ Object
118 119 120 |
# File 'lib/stream-chat/client.rb', line 118 def get_app_settings get('app') end |
#get_blocklist(name) ⇒ Object
653 654 655 |
# File 'lib/stream-chat/client.rb', line 653 def get_blocklist(name) get("blocklists/#{name}") end |
#get_channel_type(channel_type) ⇒ Object
523 524 525 |
# File 'lib/stream-chat/client.rb', line 523 def get_channel_type(channel_type) get("channeltypes/#{channel_type}") end |
#get_command(name) ⇒ Object
889 890 891 |
# File 'lib/stream-chat/client.rb', line 889 def get_command(name) get("commands/#{name}") end |
#get_devices(user_id) ⇒ Object
577 578 579 |
# File 'lib/stream-chat/client.rb', line 577 def get_devices(user_id) get('devices', params: { user_id: user_id }) end |
#get_export_channel_status(task_id) ⇒ Object
705 706 707 |
# File 'lib/stream-chat/client.rb', line 705 def get_export_channel_status(task_id) get("export_channels/#{task_id}") end |
#get_import(id) ⇒ Object
999 1000 1001 |
# File 'lib/stream-chat/client.rb', line 999 def get_import(id) get("imports/#{id}") end |
#get_message(id, **options) ⇒ Object
187 188 189 |
# File 'lib/stream-chat/client.rb', line 187 def (id, **) get("messages/#{id}", params: ) end |
#get_permission(id) ⇒ Object
919 920 921 |
# File 'lib/stream-chat/client.rb', line 919 def (id) get("permissions/#{id}") end |
#get_rate_limits(server_side: false, android: false, ios: false, web: false, endpoints: []) ⇒ Object
584 585 586 587 588 589 590 591 592 593 |
# File 'lib/stream-chat/client.rb', line 584 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
721 722 723 |
# File 'lib/stream-chat/client.rb', line 721 def get_task(task_id) get("tasks/#{task_id}") end |
#hard_delete_message(message_id) ⇒ Object
436 437 438 |
# File 'lib/stream-chat/client.rb', line 436 def () (, hard: true) end |
#list_blocklists ⇒ Object
641 642 643 |
# File 'lib/stream-chat/client.rb', line 641 def list_blocklists get('blocklists') end |
#list_channel_types ⇒ Object
529 530 531 |
# File 'lib/stream-chat/client.rb', line 529 def list_channel_types get('channeltypes') end |
#list_commands ⇒ Object
907 908 909 |
# File 'lib/stream-chat/client.rb', line 907 def list_commands get('commands') end |
#list_imports(options) ⇒ Object
1005 1006 1007 |
# File 'lib/stream-chat/client.rb', line 1005 def list_imports() get('imports', params: ) end |
#list_permissions ⇒ Object
913 914 915 |
# File 'lib/stream-chat/client.rb', line 913 def get('permissions') end |
#list_push_providers ⇒ Object
973 974 975 |
# File 'lib/stream-chat/client.rb', line 973 def list_push_providers get('push_providers') end |
#list_roles ⇒ Object
955 956 957 |
# File 'lib/stream-chat/client.rb', line 955 def list_roles get('roles') end |
#mark_all_read(user_id) ⇒ Object
358 359 360 361 |
# File 'lib/stream-chat/client.rb', line 358 def mark_all_read(user_id) payload = { user: { id: user_id } } post('channels/read', data: payload) end |
#mute_user(target_id, user_id) ⇒ Object
344 345 346 347 |
# File 'lib/stream-chat/client.rb', line 344 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
789 790 791 |
# File 'lib/stream-chat/client.rb', line 789 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
382 383 384 385 386 387 388 389 390 |
# File 'lib/stream-chat/client.rb', line 382 def (, user_id, expiration: nil) updates = { set: { pinned: true, pin_expires: expiration } } (, updates, user_id: user_id) end |
#post(relative_url, params: nil, data: nil) ⇒ Object
774 775 776 |
# File 'lib/stream-chat/client.rb', line 774 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
769 770 771 |
# File 'lib/stream-chat/client.rb', line 769 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
479 480 481 482 483 484 485 |
# File 'lib/stream-chat/client.rb', line 479 def query_banned_users(filter_conditions, sort: nil, **) params = .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
505 506 507 508 509 510 511 512 |
# File 'lib/stream-chat/client.rb', line 505 def query_channels(filter_conditions, sort: nil, **) data = { state: true, watch: false, presence: false } data = data.merge().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
852 853 854 855 856 857 858 |
# File 'lib/stream-chat/client.rb', line 852 def query_drafts(user_id, filter: nil, sort: nil, **) data = { user_id: user_id } data['filter'] = filter if filter data['sort'] = sort if sort data.merge!() if post('drafts/query', data: data) end |
#query_flag_reports(**options) ⇒ Object
169 170 171 172 |
# File 'lib/stream-chat/client.rb', line 169 def query_flag_reports(**) data = { filter_conditions: } post('moderation/reports', data: data) end |
#query_message_flags(filter_conditions, **options) ⇒ Object
146 147 148 149 150 151 |
# File 'lib/stream-chat/client.rb', line 146 def (filter_conditions, **) params = .merge({ filter_conditions: filter_conditions }) get('moderation/flags/message', params: { payload: params.to_json }) end |
#query_reminders(user_id, filter_conditions = {}, sort: nil, **options) ⇒ Object
1059 1060 1061 1062 1063 1064 1065 1066 |
# File 'lib/stream-chat/client.rb', line 1059 def query_reminders(user_id, filter_conditions = {}, sort: nil, **) params = .merge({ filter_conditions: filter_conditions, sort: sort || [{ field: 'remind_at', direction: 1 }], user_id: user_id }) post('reminders/query', data: params) end |
#query_threads(filter, sort: nil, **options) ⇒ Object
1010 1011 1012 1013 1014 1015 1016 1017 |
# File 'lib/stream-chat/client.rb', line 1010 def query_threads(filter, sort: nil, **) params = {}.merge().merge({ filter: filter, sort: StreamChat.get_sort_fields(sort) }) post('threads', data: params) end |
#query_users(filter_conditions, sort: nil, **options) ⇒ Object
490 491 492 493 494 495 496 |
# File 'lib/stream-chat/client.rb', line 490 def query_users(filter_conditions, sort: nil, **) params = .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
294 295 296 |
# File 'lib/stream-chat/client.rb', line 294 def reactivate_user(user_id, **) post("users/#{user_id}/reactivate", params: ) end |
#remove_shadow_ban(target_id, **options) ⇒ Object
337 338 339 340 |
# File 'lib/stream-chat/client.rb', line 337 def remove_shadow_ban(target_id, **) params = { target_user_id: target_id, shadow: true }.merge() delete('moderation/ban', params: params) end |
#restore_user(user_id) ⇒ Object
266 267 268 |
# File 'lib/stream-chat/client.rb', line 266 def restore_user(user_id) post('users/restore', data: { user_ids: [user_id] }) end |
#restore_users(user_ids) ⇒ Object
272 273 274 |
# File 'lib/stream-chat/client.rb', line 272 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
176 177 178 179 180 181 182 183 |
# File 'lib/stream-chat/client.rb', line 176 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
740 741 742 743 |
# File 'lib/stream-chat/client.rb', line 740 def revoke_tokens(before) before = before.rfc3339 if before.instance_of?(DateTime) update_app_settings({ 'revoke_tokens_issued_before' => before }) end |
#revoke_user_token(user_id, before) ⇒ Object
747 748 749 |
# File 'lib/stream-chat/client.rb', line 747 def revoke_user_token(user_id, before) revoke_users_token([user_id], before) end |
#revoke_users_token(user_ids, before) ⇒ Object
753 754 755 756 757 758 759 760 761 762 763 764 765 766 |
# File 'lib/stream-chat/client.rb', line 753 def revoke_users_token(user_ids, before) before = before.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
618 619 620 |
# File 'lib/stream-chat/client.rb', line 618 def (, data) post("messages/#{}/action", data: data) end |
#search(filter_conditions, query, sort: nil, **options) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/stream-chat/client.rb', line 196 def search(filter_conditions, query, sort: nil, **) offset = T.cast([:offset], T.nilable(Integer)) next_value = [: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: .merge(to_merge).to_json }) end |
#send_file(relative_url, file_url, user, content_type = nil) ⇒ Object
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 |
# File 'lib/stream-chat/client.rb', line 798 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
604 605 606 |
# File 'lib/stream-chat/client.rb', line 604 def send_user_event(user_id, event) post("users/#{user_id}/event", data: event) end |
#set_http_client(client) ⇒ Object
92 93 94 |
# File 'lib/stream-chat/client.rb', line 92 def set_http_client(client) @conn = client end |
#shadow_ban(target_id, **options) ⇒ Object
329 330 331 332 |
# File 'lib/stream-chat/client.rb', line 329 def shadow_ban(target_id, **) payload = { target_user_id: target_id, shadow: true }.merge() post('moderation/ban', data: payload) end |
#translate_message(message_id, language) ⇒ Object
612 613 614 |
# File 'lib/stream-chat/client.rb', line 612 def (, language) post("messages/#{}/translate", data: { language: language }) end |
#unban_user(target_id, **options) ⇒ Object
318 319 320 321 |
# File 'lib/stream-chat/client.rb', line 318 def unban_user(target_id, **) params = { target_user_id: target_id }.merge() delete('moderation/ban', params: params) end |
#undelete_message(message_id, undeleted_by, **options) ⇒ Object
466 467 468 469 |
# File 'lib/stream-chat/client.rb', line 466 def (, undeleted_by, **) payload = { undeleted_by: undeleted_by }.merge() post("messages/#{}/undelete", data: payload) end |
#unflag_message(id, **options) ⇒ Object
135 136 137 138 |
# File 'lib/stream-chat/client.rb', line 135 def (id, **) payload = { target_message_id: id }.merge() post('moderation/unflag', data: payload) end |
#unflag_user(id, **options) ⇒ Object
162 163 164 165 |
# File 'lib/stream-chat/client.rb', line 162 def unflag_user(id, **) payload = { target_user_id: id }.merge() post('moderation/unflag', data: payload) end |
#unmute_user(target_id, user_id) ⇒ Object
351 352 353 354 |
# File 'lib/stream-chat/client.rb', line 351 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
394 395 396 397 398 399 400 401 |
# File 'lib/stream-chat/client.rb', line 394 def (, user_id) updates = { set: { pinned: false } } (, updates, user_id: user_id) end |
#unread_counts(user_id) ⇒ Object
365 366 367 |
# File 'lib/stream-chat/client.rb', line 365 def unread_counts(user_id) get('/unread', params: { user_id: user_id }) end |
#unread_counts_batch(user_ids) ⇒ Object
371 372 373 |
# File 'lib/stream-chat/client.rb', line 371 def unread_counts_batch(user_ids) post('/unread_batch', data: { user_ids: user_ids }) end |
#update_app_settings(**settings) ⇒ Object
112 113 114 |
# File 'lib/stream-chat/client.rb', line 112 def update_app_settings(**settings) patch('app', data: settings) end |
#update_blocklist(name, words) ⇒ Object
677 678 679 |
# File 'lib/stream-chat/client.rb', line 677 def update_blocklist(name, words) put("blocklists/#{name}", data: { words: words }) end |
#update_channel_type(channel_type, **options) ⇒ Object
535 536 537 |
# File 'lib/stream-chat/client.rb', line 535 def update_channel_type(channel_type, **) put("channeltypes/#{channel_type}", data: ) end |
#update_command(name, command) ⇒ Object
895 896 897 |
# File 'lib/stream-chat/client.rb', line 895 def update_command(name, command) put("commands/#{name}", data: command) end |
#update_location(user_id, created_by_device_id:, message_id:, **options) ⇒ Object
878 879 880 881 882 883 884 885 |
# File 'lib/stream-chat/client.rb', line 878 def update_location(user_id, created_by_device_id:, message_id:, **) data = { created_by_device_id: created_by_device_id, message_id: } data.merge!() if put('users/live_locations', data: data, params: { user_id: user_id }) end |
#update_message(message) ⇒ Object
412 413 414 415 416 |
# File 'lib/stream-chat/client.rb', line 412 def () raise ArgumentError, 'message must have an id' unless .key? 'id' post("messages/#{['id']}", data: { message: }) end |
#update_message_partial(message_id, updates, user_id: nil, **options) ⇒ Object
422 423 424 425 426 |
# File 'lib/stream-chat/client.rb', line 422 def (, updates, user_id: nil, **) params = updates.merge() params['user'] = { id: user_id } if user_id put("messages/#{}", data: params) end |
#update_permission(id, permission) ⇒ Object
931 932 933 |
# File 'lib/stream-chat/client.rb', line 931 def (id, ) put("permissions/#{id}", data: ) end |
#update_reminder(message_id, user_id, remind_at = nil) ⇒ Object
1037 1038 1039 1040 1041 |
# File 'lib/stream-chat/client.rb', line 1037 def update_reminder(, user_id, remind_at = nil) data = { user_id: user_id } data[:remind_at] = remind_at.rfc3339 if remind_at patch("messages/#{}/reminders", data: data) end |
#update_user(user) ⇒ Object
222 223 224 225 |
# File 'lib/stream-chat/client.rb', line 222 def update_user(user) warn '[DEPRECATION] `update_user` is deprecated. Please use `upsert_user` instead.' upsert_user(user) end |
#update_user_partial(update) ⇒ Object
254 255 256 |
# File 'lib/stream-chat/client.rb', line 254 def update_user_partial(update) update_users_partial([update]) end |
#update_users(users) ⇒ Object
215 216 217 218 |
# File 'lib/stream-chat/client.rb', line 215 def update_users(users) warn '[DEPRECATION] `update_users` is deprecated. Please use `upsert_users` instead.' upsert_users(users) end |
#update_users_partial(updates) ⇒ Object
248 249 250 |
# File 'lib/stream-chat/client.rb', line 248 def update_users_partial(updates) patch('users', data: { users: updates }) end |
#upsert_push_provider(push_provider) ⇒ Object
961 962 963 |
# File 'lib/stream-chat/client.rb', line 961 def upsert_push_provider(push_provider) post('push_providers', data: { push_provider: push_provider }) end |
#upsert_user(user) ⇒ Object
242 243 244 |
# File 'lib/stream-chat/client.rb', line 242 def upsert_user(user) upsert_users([user]) end |
#upsert_users(users) ⇒ Object
229 230 231 232 233 234 235 236 237 238 |
# File 'lib/stream-chat/client.rb', line 229 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
597 598 599 600 |
# File 'lib/stream-chat/client.rb', line 597 def verify_webhook(request_body, x_signature) signature = OpenSSL::HMAC.hexdigest('SHA256', @api_secret, request_body) signature == x_signature end |