diff --git a/lib/stream-chat/client.rb b/lib/stream-chat/client.rb index 9432a9d..4abb6fe 100644 --- a/lib/stream-chat/client.rb +++ b/lib/stream-chat/client.rb @@ -643,6 +643,16 @@ def get_export_channel_status(task_id) get("export_channels/#{task_id}") end + # Requests a users export. + # + # User exports are created asynchronously, you can use the Task ID returned by + # the APIs to keep track of the status and to download the final result when it is ready. + # Use `get_task` to check the status of the export. + sig { params(user_ids: T::Array[String]).returns(StreamChat::StreamResponse) } + def export_users(user_ids) + post('export/users', data: { user_ids: user_ids }) + end + # Returns the status of a task. sig { params(task_id: String).returns(StreamChat::StreamResponse) } def get_task(task_id) diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 5bc66cd..9cd583e 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -592,6 +592,29 @@ def loop_times(times) end end + it 'request users export' do + user_id1 = SecureRandom.uuid + @client.update_users([{ id: user_id1 }]) + + resp = @client.export_users([user_id1]) + expect(resp['task_id']).not_to be_empty + + task_id = resp['task_id'] + loop do + resp = @client.get_task(task_id) + expect(resp['status']).not_to be_empty + expect(resp['created_at']).not_to be_empty + expect(resp['updated_at']).not_to be_empty + if resp['status'] == 'completed' + expect(resp['result']).not_to be_empty + expect(resp['result']['url']).not_to be_empty + expect(resp).not_to include 'error' + break + end + sleep(0.5) + end + end + it 'request delete channels' do ch1 = @client.channel('messaging', channel_id: SecureRandom.uuid) ch1.create(@random_user[:id])