Skip to content

Commit af24c3c

Browse files
Automatically update PHP SDK
1 parent 86a13cb commit af24c3c

4 files changed

Lines changed: 62 additions & 62 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "trophy/php",
3-
"version": "1.0.24",
3+
"version": "1.0.25",
44
"description": "Trophy PHP Library",
55
"keywords": [
66
"trophy",

src/Leaderboards/LeaderboardsClient.php

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
use Psr\Http\Client\ClientExceptionInterface;
1717
use Trophy\Leaderboards\Requests\LeaderboardsGetRequest;
1818
use Trophy\Types\LeaderboardResponseWithRankings;
19-
use Trophy\Leaderboards\Requests\UsersLeaderboardsRequest;
20-
use Trophy\Types\UserLeaderboardResponse;
2119

2220
class LeaderboardsClient
2321
{
@@ -168,62 +166,4 @@ public function get(string $key, LeaderboardsGetRequest $request, ?array $option
168166
body: $response->getBody()->getContents(),
169167
);
170168
}
171-
172-
/**
173-
* Get a user's rank, value, and history for a specific leaderboard.
174-
*
175-
* @param string $userId The user's ID in your database.
176-
* @param string $key Unique key of the leaderboard as set when created.
177-
* @param UsersLeaderboardsRequest $request
178-
* @param ?array{
179-
* baseUrl?: string,
180-
* maxRetries?: int,
181-
* } $options
182-
* @return UserLeaderboardResponse
183-
* @throws TrophyException
184-
* @throws TrophyApiException
185-
*/
186-
public function usersLeaderboards(string $userId, string $key, UsersLeaderboardsRequest $request, ?array $options = null): UserLeaderboardResponse
187-
{
188-
$options = array_merge($this->options, $options ?? []);
189-
$query = [];
190-
if ($request->run != null) {
191-
$query['run'] = $request->run;
192-
}
193-
try {
194-
$response = $this->client->sendRequest(
195-
new JsonApiRequest(
196-
baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::Default_->value,
197-
path: "users/$userId/leaderboards/$key",
198-
method: HttpMethod::GET,
199-
query: $query,
200-
),
201-
$options,
202-
);
203-
$statusCode = $response->getStatusCode();
204-
if ($statusCode >= 200 && $statusCode < 400) {
205-
$json = $response->getBody()->getContents();
206-
return UserLeaderboardResponse::fromJson($json);
207-
}
208-
} catch (JsonException $e) {
209-
throw new TrophyException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e);
210-
} catch (RequestException $e) {
211-
$response = $e->getResponse();
212-
if ($response === null) {
213-
throw new TrophyException(message: $e->getMessage(), previous: $e);
214-
}
215-
throw new TrophyApiException(
216-
message: "API request failed",
217-
statusCode: $response->getStatusCode(),
218-
body: $response->getBody()->getContents(),
219-
);
220-
} catch (ClientExceptionInterface $e) {
221-
throw new TrophyException(message: $e->getMessage(), previous: $e);
222-
}
223-
throw new TrophyApiException(
224-
message: 'API request failed',
225-
statusCode: $statusCode,
226-
body: $response->getBody()->getContents(),
227-
);
228-
}
229169
}

src/Leaderboards/Requests/UsersLeaderboardsRequest.php renamed to src/Users/Requests/UsersLeaderboardsRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Trophy\Leaderboards\Requests;
3+
namespace Trophy\Users\Requests;
44

55
use Trophy\Core\Json\JsonSerializableType;
66

src/Users/UsersClient.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
use Trophy\Types\GetUserPointsResponse;
2828
use Trophy\Users\Requests\UsersPointsEventSummaryRequest;
2929
use Trophy\Users\Types\UsersPointsEventSummaryResponseItem;
30+
use Trophy\Users\Requests\UsersLeaderboardsRequest;
31+
use Trophy\Types\UserLeaderboardResponse;
3032

3133
class UsersClient
3234
{
@@ -661,4 +663,62 @@ public function pointsEventSummary(string $id, string $key, UsersPointsEventSumm
661663
body: $response->getBody()->getContents(),
662664
);
663665
}
666+
667+
/**
668+
* Get a user's rank, value, and history for a specific leaderboard.
669+
*
670+
* @param string $id The user's ID in your database.
671+
* @param string $key Unique key of the leaderboard as set when created.
672+
* @param UsersLeaderboardsRequest $request
673+
* @param ?array{
674+
* baseUrl?: string,
675+
* maxRetries?: int,
676+
* } $options
677+
* @return UserLeaderboardResponse
678+
* @throws TrophyException
679+
* @throws TrophyApiException
680+
*/
681+
public function leaderboards(string $id, string $key, UsersLeaderboardsRequest $request, ?array $options = null): UserLeaderboardResponse
682+
{
683+
$options = array_merge($this->options, $options ?? []);
684+
$query = [];
685+
if ($request->run != null) {
686+
$query['run'] = $request->run;
687+
}
688+
try {
689+
$response = $this->client->sendRequest(
690+
new JsonApiRequest(
691+
baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::Default_->value,
692+
path: "users/$id/leaderboards/$key",
693+
method: HttpMethod::GET,
694+
query: $query,
695+
),
696+
$options,
697+
);
698+
$statusCode = $response->getStatusCode();
699+
if ($statusCode >= 200 && $statusCode < 400) {
700+
$json = $response->getBody()->getContents();
701+
return UserLeaderboardResponse::fromJson($json);
702+
}
703+
} catch (JsonException $e) {
704+
throw new TrophyException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e);
705+
} catch (RequestException $e) {
706+
$response = $e->getResponse();
707+
if ($response === null) {
708+
throw new TrophyException(message: $e->getMessage(), previous: $e);
709+
}
710+
throw new TrophyApiException(
711+
message: "API request failed",
712+
statusCode: $response->getStatusCode(),
713+
body: $response->getBody()->getContents(),
714+
);
715+
} catch (ClientExceptionInterface $e) {
716+
throw new TrophyException(message: $e->getMessage(), previous: $e);
717+
}
718+
throw new TrophyApiException(
719+
message: 'API request failed',
720+
statusCode: $statusCode,
721+
body: $response->getBody()->getContents(),
722+
);
723+
}
664724
}

0 commit comments

Comments
 (0)