Skip to content

Commit 62230d8

Browse files
add support for async export users endpoint (#150)
* add support for async export users endpoint * Update spec/client_spec.rb Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent aaa8021 commit 62230d8

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/stream-chat/client.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,16 @@ def get_export_channel_status(task_id)
643643
get("export_channels/#{task_id}")
644644
end
645645

646+
# Requests a users export.
647+
#
648+
# User exports are created asynchronously, you can use the Task ID returned by
649+
# the APIs to keep track of the status and to download the final result when it is ready.
650+
# Use `get_task` to check the status of the export.
651+
sig { params(user_ids: T::Array[String]).returns(StreamChat::StreamResponse) }
652+
def export_users(user_ids)
653+
post('export/users', data: { user_ids: user_ids })
654+
end
655+
646656
# Returns the status of a task.
647657
sig { params(task_id: String).returns(StreamChat::StreamResponse) }
648658
def get_task(task_id)

spec/client_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,29 @@ def loop_times(times)
592592
end
593593
end
594594

595+
it 'request users export' do
596+
user_id1 = SecureRandom.uuid
597+
@client.update_users([{ id: user_id1 }])
598+
599+
resp = @client.export_users([user_id1])
600+
expect(resp['task_id']).not_to be_empty
601+
602+
task_id = resp['task_id']
603+
loop do
604+
resp = @client.get_task(task_id)
605+
expect(resp['status']).not_to be_empty
606+
expect(resp['created_at']).not_to be_empty
607+
expect(resp['updated_at']).not_to be_empty
608+
if resp['status'] == 'completed'
609+
expect(resp['result']).not_to be_empty
610+
expect(resp['result']['url']).not_to be_empty
611+
expect(resp).not_to include 'error'
612+
break
613+
end
614+
sleep(0.5)
615+
end
616+
end
617+
595618
it 'request delete channels' do
596619
ch1 = @client.channel('messaging', channel_id: SecureRandom.uuid)
597620
ch1.create(@random_user[:id])

0 commit comments

Comments
 (0)