Skip to content

Commit 68e4f0d

Browse files
add support for async export users endpoint (#133)
1 parent 6e59a31 commit 68e4f0d

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/GetStream/StreamChat/Client.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,17 @@ public function getExportChannelStatus(string $id): StreamResponse
13331333
return $this->get("export_channels/{$id}");
13341334
}
13351335

1336+
/**
1337+
* Schedules user export task for a list of users
1338+
* @link https://getstream.io/chat/docs/php/exporting_users/?language=php
1339+
* @param $userIds array of user IDs to export.
1340+
* @return StreamResponse returns task ID that you can use to get export status (see getTask method)
1341+
*/
1342+
public function exportUsers(array $userIds): StreamResponse
1343+
{
1344+
return $this->post("export/users", ["user_ids" => $userIds]);
1345+
}
1346+
13361347
/**
13371348
* Returns task status
13381349
* @link https://getstream.io/chat/docs/rest/#tasks-gettask

tests/integration/IntegrationTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,4 +1460,24 @@ public function testUpdateMessagePartialWithRestrictedVisibility()
14601460
$this->assertNotNull($response["message"]["restricted_visibility"]);
14611461
$this->assertEquals([$this->user1["id"]], $response["message"]["restricted_visibility"]);
14621462
}
1463+
1464+
public function testExportUsers()
1465+
{
1466+
$user = ["id" => $this->generateGuid()];
1467+
$this->client->upsertUser($user);
1468+
1469+
$response = $this->client->exportUsers([$user["id"]]);
1470+
$this->assertTrue(array_key_exists("task_id", (array)$response));
1471+
1472+
$taskId = $response["task_id"];
1473+
for ($i = 0; $i < 30; $i++) {
1474+
$response = $this->client->getTask($taskId);
1475+
if ($response["status"] == "completed") {
1476+
$this->assertStringContainsString("/exports/users/", $response["result"]["url"]);
1477+
return;
1478+
}
1479+
usleep(300000);
1480+
}
1481+
$this->assertSame($response["status"], "completed");
1482+
}
14631483
}

0 commit comments

Comments
 (0)