From ec20d813dbb42a087e0c6810df3dec0baf357323 Mon Sep 17 00:00:00 2001 From: Jimmy Pettersson Date: Tue, 18 Feb 2025 10:55:24 +0100 Subject: [PATCH] add support for async export users endpoint --- lib/GetStream/StreamChat/Client.php | 11 +++++++++++ tests/integration/IntegrationTest.php | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/GetStream/StreamChat/Client.php b/lib/GetStream/StreamChat/Client.php index 2688f44..551cf29 100644 --- a/lib/GetStream/StreamChat/Client.php +++ b/lib/GetStream/StreamChat/Client.php @@ -1333,6 +1333,17 @@ public function getExportChannelStatus(string $id): StreamResponse return $this->get("export_channels/{$id}"); } + /** + * Schedules user export task for a list of users + * @link https://getstream.io/chat/docs/php/exporting_users/?language=php + * @param $userIds array of user IDs to export. + * @return StreamResponse returns task ID that you can use to get export status (see getTask method) + */ + public function exportUsers(array $userIds): StreamResponse + { + return $this->post("export/users", ["user_ids" => $userIds]); + } + /** * Returns task status * @link https://getstream.io/chat/docs/rest/#tasks-gettask diff --git a/tests/integration/IntegrationTest.php b/tests/integration/IntegrationTest.php index 7158526..bd5ce8b 100644 --- a/tests/integration/IntegrationTest.php +++ b/tests/integration/IntegrationTest.php @@ -1460,4 +1460,24 @@ public function testUpdateMessagePartialWithRestrictedVisibility() $this->assertNotNull($response["message"]["restricted_visibility"]); $this->assertEquals([$this->user1["id"]], $response["message"]["restricted_visibility"]); } + + public function testExportUsers() + { + $user = ["id" => $this->generateGuid()]; + $this->client->upsertUser($user); + + $response = $this->client->exportUsers([$user["id"]]); + $this->assertTrue(array_key_exists("task_id", (array)$response)); + + $taskId = $response["task_id"]; + for ($i = 0; $i < 30; $i++) { + $response = $this->client->getTask($taskId); + if ($response["status"] == "completed") { + $this->assertStringContainsString("/exports/users/", $response["result"]["url"]); + return; + } + usleep(300000); + } + $this->assertSame($response["status"], "completed"); + } }