-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from simivar/feature/implement-all-lor-ranked
Implement all Lor Leaderboard v1 endpoints
- Loading branch information
Showing
13 changed files
with
248 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Riot\API\Version1; | ||
|
||
use JsonException; | ||
use Psr\Http\Client\ClientExceptionInterface; | ||
use Riot\API\AbstractApi; | ||
use Riot\DTO\LeaderboardDTO; | ||
use Riot\Exception as RiotException; | ||
|
||
final class LorRanked extends AbstractApi | ||
{ | ||
/** | ||
* @throws JsonException | ||
* @throws RiotException\BadGatewayException | ||
* @throws RiotException\BadRequestException | ||
* @throws RiotException\DataNotFoundException | ||
* @throws RiotException\ForbiddenException | ||
* @throws RiotException\GatewayTimeoutException | ||
* @throws RiotException\InternalServerErrorException | ||
* @throws RiotException\MethodNotAllowedException | ||
* @throws RiotException\RateLimitExceededException | ||
* @throws RiotException\ServiceUnavailableException | ||
* @throws RiotException\UnauthorizedException | ||
* @throws RiotException\UnsupportedMediaTypeException | ||
* @throws ClientExceptionInterface | ||
*/ | ||
public function getLeaderboards(string $geoRegion): LeaderboardDTO | ||
{ | ||
$response = $this->riotConnection->get( | ||
$geoRegion, | ||
'lor/ranked/v1/leaderboards', | ||
); | ||
$body = $response->getBody()->getContents(); | ||
|
||
return LeaderboardDTO::createFromArray(json_decode($body, true, 512, JSON_THROW_ON_ERROR)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Riot\Collection; | ||
|
||
use Ramsey\Collection\AbstractCollection; | ||
use Riot\DTO\PlayerDTO; | ||
|
||
final class PlayerDTOCollection extends AbstractCollection | ||
{ | ||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
public function getType(): string | ||
{ | ||
return PlayerDTO::class; | ||
} | ||
|
||
/** | ||
* @param array<array<string, string|int>> $data | ||
* | ||
* @return PlayerDTOCollection<PlayerDTO> | ||
*/ | ||
public static function createFromArray(array $data): self | ||
{ | ||
$collection = new self(); | ||
foreach ($data as $item) { | ||
$collection->add(PlayerDTO::createFromArray($item)); | ||
} | ||
|
||
return $collection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Riot\DTO; | ||
|
||
use Riot\Collection\PlayerDTOCollection; | ||
|
||
final class LeaderboardDTO implements DTOInterface | ||
{ | ||
/** @var PlayerDTOCollection<PlayerDTO> */ | ||
private PlayerDTOCollection $players; | ||
|
||
/** | ||
* @param PlayerDTOCollection<PlayerDTO> $players | ||
*/ | ||
public function __construct(PlayerDTOCollection $players) | ||
{ | ||
$this->players = $players; | ||
} | ||
|
||
public function getPlayers(): PlayerDTOCollection | ||
{ | ||
return $this->players; | ||
} | ||
|
||
public static function createFromArray(array $data): self | ||
{ | ||
return new self( | ||
PlayerDTOCollection::createFromArray($data['players']), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Riot\DTO; | ||
|
||
final class PlayerDTO implements DTOInterface | ||
{ | ||
private string $name; | ||
|
||
private int $rank; | ||
|
||
private int $lp; | ||
|
||
public function __construct(string $name, int $rank, int $lp) | ||
{ | ||
$this->name = $name; | ||
$this->rank = $rank; | ||
$this->lp = $lp; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function getRank(): int | ||
{ | ||
return $this->rank; | ||
} | ||
|
||
public function getLp(): int | ||
{ | ||
return $this->lp; | ||
} | ||
|
||
public static function createFromArray(array $data): self | ||
{ | ||
return new self( | ||
$data['name'], | ||
$data['rank'], | ||
(int) $data['lp'], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Riot\Tests\Unit\DTO; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Riot\Collection\PlayerDTOCollection; | ||
use Riot\DTO\PlayerDTO; | ||
|
||
final class PlayerDTOCollectionTest extends TestCase | ||
{ | ||
public function testCreateFromArrayCreatesProperObject(): void | ||
{ | ||
$data = [ | ||
'players' => [ | ||
'name' => 'Player One', | ||
'rank' => 0, | ||
'lp' => 367, | ||
], | ||
]; | ||
$object = PlayerDTOCollection::createFromArray($data); | ||
self::assertFalse($object->isEmpty()); | ||
self::assertInstanceOf(PlayerDTO::class, $object->offsetGet(0)); | ||
} | ||
|
||
public function testCreateFromArrayReturnsEmptyCollectionWhenNoData(): void | ||
{ | ||
$data = []; | ||
$object = PlayerDTOCollection::createFromArray($data); | ||
self::assertTrue($object->isEmpty()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Riot\Tests\Unit\DTO; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Riot\Collection\PlayerDTOCollection; | ||
use Riot\DTO\LeaderboardDTO; | ||
|
||
final class LeaderboardDTOTest extends TestCase | ||
{ | ||
public function testCreateFromArrayCreatesProperObject(): void | ||
{ | ||
$data = [ | ||
'players' => [], | ||
]; | ||
$object = LeaderboardDTO::createFromArray($data); | ||
self::assertInstanceOf(PlayerDTOCollection::class, $object->getPlayers()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Riot\Tests\Unit\DTO; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Riot\DTO\PlayerDTO; | ||
|
||
final class PlayerDTOTest extends TestCase | ||
{ | ||
public function testCreateFromArrayCreatesProperObject(): void | ||
{ | ||
$data = [ | ||
'name' => 'Player One', | ||
'rank' => 0, | ||
'lp' => 367, | ||
]; | ||
$object = PlayerDTO::createFromArray($data); | ||
self::assertSame('Player One', $object->getName()); | ||
self::assertSame(0, $object->getRank()); | ||
self::assertSame(367, $object->getLp()); | ||
} | ||
} |