Skip to content

Commit 29f3ea9

Browse files
authored
Merge pull request #27 from simivar/feature/implement-all-lor-ranked
Implement all Lor Leaderboard v1 endpoints
2 parents 8387f2c + 4c3131d commit 29f3ea9

File tree

13 files changed

+248
-1
lines changed

13 files changed

+248
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ composer require simivar/riot-php symfony/http-client nyholm/psr7
2626
| League v4 | [docs](https://developer.riotgames.com/apis#league-v4) | - |
2727
| Lol Status v3 | [docs](https://developer.riotgames.com/apis#lol-status-v3) | 100% |
2828
| Lor Match v1 | [docs](https://developer.riotgames.com/apis#lor-match-v1) | - |
29-
| Lor Ranked v1 | [docs](https://developer.riotgames.com/apis#lor-ranked-v1) | - |
29+
| Lor Ranked v1 | [docs](https://developer.riotgames.com/apis#lor-ranked-v1) | 100% |
3030
| Match v4 | [docs](https://developer.riotgames.com/apis#match-v4) | - |
3131
| Spectator v4 | [docs](https://developer.riotgames.com/apis#spectator-v4) | - |
3232
| Summoner v4 | [docs](https://developer.riotgames.com/apis#summoner-v4) | 100% |

src/Riot/API.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,13 @@ public function getLolStatusV3Api(): Version3\LolStatus
7373

7474
return $this->apis['lolStatusV3'];
7575
}
76+
77+
public function getLorRankedV1Api(): Version1\LorRanked
78+
{
79+
if (!isset($this->apis['lorRankedV1'])) {
80+
$this->apis['lorRankedV1'] = new Version1\LorRanked($this->riotConnection);
81+
}
82+
83+
return $this->apis['lorRankedV1'];
84+
}
7685
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Riot\API\Version1;
6+
7+
use JsonException;
8+
use Psr\Http\Client\ClientExceptionInterface;
9+
use Riot\API\AbstractApi;
10+
use Riot\DTO\LeaderboardDTO;
11+
use Riot\Exception as RiotException;
12+
13+
final class LorRanked extends AbstractApi
14+
{
15+
/**
16+
* @throws JsonException
17+
* @throws RiotException\BadGatewayException
18+
* @throws RiotException\BadRequestException
19+
* @throws RiotException\DataNotFoundException
20+
* @throws RiotException\ForbiddenException
21+
* @throws RiotException\GatewayTimeoutException
22+
* @throws RiotException\InternalServerErrorException
23+
* @throws RiotException\MethodNotAllowedException
24+
* @throws RiotException\RateLimitExceededException
25+
* @throws RiotException\ServiceUnavailableException
26+
* @throws RiotException\UnauthorizedException
27+
* @throws RiotException\UnsupportedMediaTypeException
28+
* @throws ClientExceptionInterface
29+
*/
30+
public function getLeaderboards(string $geoRegion): LeaderboardDTO
31+
{
32+
$response = $this->riotConnection->get(
33+
$geoRegion,
34+
'lor/ranked/v1/leaderboards',
35+
);
36+
$body = $response->getBody()->getContents();
37+
38+
return LeaderboardDTO::createFromArray(json_decode($body, true, 512, JSON_THROW_ON_ERROR));
39+
}
40+
}

src/Riot/Collection/IncidentDTOCollection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public function getType(): string
1919

2020
/**
2121
* @param array<array<string, mixed>> $data
22+
*
23+
* @return IncidentDTOCollection<IncidentDTO>
2224
*/
2325
public static function createFromArray(array $data): self
2426
{

src/Riot/Collection/MessageDTOCollection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public function getType(): string
1919

2020
/**
2121
* @param array<array<string, array|string>> $data
22+
*
23+
* @return MessageDTOCollection<MessageDTO>
2224
*/
2325
public static function createFromArray(array $data): self
2426
{
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Riot\Collection;
6+
7+
use Ramsey\Collection\AbstractCollection;
8+
use Riot\DTO\PlayerDTO;
9+
10+
final class PlayerDTOCollection extends AbstractCollection
11+
{
12+
/**
13+
* @codeCoverageIgnore
14+
*/
15+
public function getType(): string
16+
{
17+
return PlayerDTO::class;
18+
}
19+
20+
/**
21+
* @param array<array<string, string|int>> $data
22+
*
23+
* @return PlayerDTOCollection<PlayerDTO>
24+
*/
25+
public static function createFromArray(array $data): self
26+
{
27+
$collection = new self();
28+
foreach ($data as $item) {
29+
$collection->add(PlayerDTO::createFromArray($item));
30+
}
31+
32+
return $collection;
33+
}
34+
}

src/Riot/Collection/ServiceDTOCollection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public function getType(): string
1919

2020
/**
2121
* @param array<array<string, array|string>> $data
22+
*
23+
* @return ServiceDTOCollection<ServiceDTO>
2224
*/
2325
public static function createFromArray(array $data): self
2426
{

src/Riot/Collection/TranslationDTOCollection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public function getType(): string
1919

2020
/**
2121
* @param array<array<string, string>> $data
22+
*
23+
* @return TranslationDTOCollection<TranslationDTO>
2224
*/
2325
public static function createFromArray(array $data): self
2426
{

src/Riot/DTO/LeaderboardDTO.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Riot\DTO;
6+
7+
use Riot\Collection\PlayerDTOCollection;
8+
9+
final class LeaderboardDTO implements DTOInterface
10+
{
11+
/** @var PlayerDTOCollection<PlayerDTO> */
12+
private PlayerDTOCollection $players;
13+
14+
/**
15+
* @param PlayerDTOCollection<PlayerDTO> $players
16+
*/
17+
public function __construct(PlayerDTOCollection $players)
18+
{
19+
$this->players = $players;
20+
}
21+
22+
public function getPlayers(): PlayerDTOCollection
23+
{
24+
return $this->players;
25+
}
26+
27+
public static function createFromArray(array $data): self
28+
{
29+
return new self(
30+
PlayerDTOCollection::createFromArray($data['players']),
31+
);
32+
}
33+
}

src/Riot/DTO/PlayerDTO.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Riot\DTO;
6+
7+
final class PlayerDTO implements DTOInterface
8+
{
9+
private string $name;
10+
11+
private int $rank;
12+
13+
private int $lp;
14+
15+
public function __construct(string $name, int $rank, int $lp)
16+
{
17+
$this->name = $name;
18+
$this->rank = $rank;
19+
$this->lp = $lp;
20+
}
21+
22+
public function getName(): string
23+
{
24+
return $this->name;
25+
}
26+
27+
public function getRank(): int
28+
{
29+
return $this->rank;
30+
}
31+
32+
public function getLp(): int
33+
{
34+
return $this->lp;
35+
}
36+
37+
public static function createFromArray(array $data): self
38+
{
39+
return new self(
40+
$data['name'],
41+
$data['rank'],
42+
(int) $data['lp'],
43+
);
44+
}
45+
}

0 commit comments

Comments
 (0)