Skip to content

Commit 7e4d9f8

Browse files
authored
Merge pull request #2 from simivar/feature/implement-summoner-endpoints
Implement summoner endpoints
2 parents 6242a5f + c929500 commit 7e4d9f8

File tree

7 files changed

+150
-15
lines changed

7 files changed

+150
-15
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,28 @@ and uses PSR-17 and PSR-18 abstraction so you are free to choose any HTTP Client
1515
composer require simivar/riot-php symfony/http-client nyholm/psr7
1616
```
1717

18+
## APIs Coverage
19+
| API | Docs | Status |
20+
| -------------------- | ----------------------------------------------------------------- | ------ |
21+
| Account v1 | [docs](https://developer.riotgames.com/apis#account-v1) | - |
22+
| Champion Mastery v4 | [docs](https://developer.riotgames.com/apis#champion-mastery-v4) | - |
23+
| Champion v3 | [docs](https://developer.riotgames.com/apis#champion-v3) | - |
24+
| Clash v1 | [docs](https://developer.riotgames.com/apis#clash-v1) | - |
25+
| League Exp v4 | [docs](https://developer.riotgames.com/apis#league-exp-v4) | - |
26+
| League v4 | [docs](https://developer.riotgames.com/apis#league-v4) | - |
27+
| Lol Status v3 | [docs](https://developer.riotgames.com/apis#lol-status-v3) | - |
28+
| 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) | - |
30+
| Match v4 | [docs](https://developer.riotgames.com/apis#match-v4) | - |
31+
| Spectator v4 | [docs](https://developer.riotgames.com/apis#spectator-v4) | - |
32+
| Summoner v4 | [docs](https://developer.riotgames.com/apis#summoner-v4) | 100% |
33+
| Tft League v1 | [docs](https://developer.riotgames.com/apis#tft-league-v1) | - |
34+
| Tft Match v1 | [docs](https://developer.riotgames.com/apis#tft-match-v1) | - |
35+
| Tft Summoner v1 | [docs](https://developer.riotgames.com/apis#tft-summoner-v1) | - |
36+
| Third Party Code v4 | [docs](https://developer.riotgames.com/apis#third-party-code-v4) | 100% |
37+
| Tournament Stub v4 | [docs](https://developer.riotgames.com/apis#tournament-stub-v4) | - |
38+
| Tournament v4 | [docs](https://developer.riotgames.com/apis#tournament-v4) | - |
39+
1840
# Legal notice
1941
Riot PHP isn't endorsed by Riot Games and doesn't reflect the views or opinions of Riot Games or anyone officially
2042
involved in producing or managing Riot Games properties. Riot Games, and all associated properties are trademarks

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"php": ">=7.4",
1818
"psr/http-client": "^1.0",
1919
"psr/http-message": "^1.0",
20-
"psr/http-factory": "^1.0"
20+
"psr/http-factory": "^1.0",
21+
"ext-json": "*"
2122
},
2223
"autoload": {
2324
"psr-4": {

src/Riot/API/Version4/Summoner.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,64 @@ public function getByName(string $summonerName, string $region): ?SummonerDTO
3030

3131
return SummonerDTO::createFromArray(json_decode($body, true, 512, JSON_THROW_ON_ERROR));
3232
}
33+
34+
/**
35+
* @throws RateLimitExceededException
36+
* @throws \JsonException
37+
*/
38+
public function getByAccountId(string $encryptedAccountId, string $region): ?SummonerDTO
39+
{
40+
$response = $this->riotConnection->get(
41+
$region,
42+
sprintf('lol/summoner/v4/summoners/by-account/%s', $encryptedAccountId),
43+
);
44+
45+
if (null === $response) {
46+
return null;
47+
}
48+
49+
$body = $response->getBody()->getContents();
50+
51+
return SummonerDTO::createFromArray(json_decode($body, true, 512, JSON_THROW_ON_ERROR));
52+
}
53+
54+
/**
55+
* @throws RateLimitExceededException
56+
* @throws \JsonException
57+
*/
58+
public function getByPuuid(string $encryptedPuuid, string $region): ?SummonerDTO
59+
{
60+
$response = $this->riotConnection->get(
61+
$region,
62+
sprintf('lol/summoner/v4/summoners/by-puuid/%s', $encryptedPuuid),
63+
);
64+
65+
if (null === $response) {
66+
return null;
67+
}
68+
69+
$body = $response->getBody()->getContents();
70+
71+
return SummonerDTO::createFromArray(json_decode($body, true, 512, JSON_THROW_ON_ERROR));
72+
}
73+
74+
/**
75+
* @throws RateLimitExceededException
76+
* @throws \JsonException
77+
*/
78+
public function getById(string $id, string $region): ?SummonerDTO
79+
{
80+
$response = $this->riotConnection->get(
81+
$region,
82+
sprintf('lol/summoner/v4/summoners/%s', $id),
83+
);
84+
85+
if (null === $response) {
86+
return null;
87+
}
88+
89+
$body = $response->getBody()->getContents();
90+
91+
return SummonerDTO::createFromArray(json_decode($body, true, 512, JSON_THROW_ON_ERROR));
92+
}
3393
}

tests/Unit/API/Version4/SummonerTest.php

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Riot\Tests\API\Version4;
5+
namespace Riot\Tests\Unit\API\Version4;
66

77
use PHPUnit\Framework\TestCase;
88
use Psr\Http\Message\ResponseInterface;
@@ -13,21 +13,19 @@
1313

1414
final class SummonerTest extends TestCase
1515
{
16-
public function testGetByNameReturnsNullOnGetNull(): void
16+
private function setUpNullResponse(string $path): ConnectionInterface
1717
{
18-
$riotConnection = $this->createMock(ConnectionInterface::class);
19-
$riotConnection->expects(self::once())
18+
$nullRiotConnectionResponse = $this->createMock(ConnectionInterface::class);
19+
$nullRiotConnectionResponse->expects(self::once())
2020
->method('get')
21-
->with(self::equalTo('eun1'), self::equalTo('lol/summoner/v4/summoners/by-name/simivar'))
21+
->with(self::equalTo('eun1'), self::equalTo($path))
2222
->willReturn(null)
2323
;
2424

25-
$summoner = new Summoner($riotConnection);
26-
$result = $summoner->getByName('simivar', 'eun1');
27-
self::assertNull($result);
25+
return $nullRiotConnectionResponse;
2826
}
2927

30-
public function testGetByNameReturnsSummonerDTOOnSuccess(): void
28+
private function setUpJsonResponse(string $path): ConnectionInterface
3129
{
3230
$apiResponse = '{"id": "1","accountId": "2","puuid": "3","name": "Simivar","profileIconId": 4,"revisionDate": 5,"summonerLevel": 6}';
3331

@@ -46,12 +44,66 @@ public function testGetByNameReturnsSummonerDTOOnSuccess(): void
4644
$riotConnection = $this->createMock(ConnectionInterface::class);
4745
$riotConnection->expects(self::once())
4846
->method('get')
49-
->with(self::equalTo('eun1'), self::equalTo('lol/summoner/v4/summoners/by-name/simivar'))
47+
->with(self::equalTo('eun1'), self::equalTo($path))
5048
->willReturn($response)
5149
;
5250

53-
$summoner = new Summoner($riotConnection);
51+
return $riotConnection;
52+
}
53+
54+
public function testGetByNameReturnsNullOnGetNull(): void
55+
{
56+
$summoner = new Summoner($this->setUpNullResponse('lol/summoner/v4/summoners/by-name/simivar'));
57+
$result = $summoner->getByName('simivar', 'eun1');
58+
self::assertNull($result);
59+
}
60+
61+
public function testGetByNameReturnsSummonerDTOOnSuccess(): void
62+
{
63+
$summoner = new Summoner($this->setUpJsonResponse('lol/summoner/v4/summoners/by-name/simivar'));
5464
$result = $summoner->getByName('simivar', 'eun1');
5565
self::assertInstanceOf(SummonerDTO::class, $result);
5666
}
67+
68+
public function testGetByAccountIdReturnsNullOnGetNull(): void
69+
{
70+
$summoner = new Summoner($this->setUpNullResponse('lol/summoner/v4/summoners/by-account/simivar'));
71+
$result = $summoner->getByAccountId('simivar', 'eun1');
72+
self::assertNull($result);
73+
}
74+
75+
public function testGetByAccountIdReturnsSummonerDTOOnSuccess(): void
76+
{
77+
$summoner = new Summoner($this->setUpJsonResponse('lol/summoner/v4/summoners/by-account/simivar'));
78+
$result = $summoner->getByAccountId('simivar', 'eun1');
79+
self::assertInstanceOf(SummonerDTO::class, $result);
80+
}
81+
82+
public function testGetByPuuidReturnsNullOnGetNull(): void
83+
{
84+
$summoner = new Summoner($this->setUpNullResponse('lol/summoner/v4/summoners/by-puuid/simivar'));
85+
$result = $summoner->getByPuuid('simivar', 'eun1');
86+
self::assertNull($result);
87+
}
88+
89+
public function testGetByPuuidReturnsSummonerDTOOnSuccess(): void
90+
{
91+
$summoner = new Summoner($this->setUpJsonResponse('lol/summoner/v4/summoners/by-puuid/simivar'));
92+
$result = $summoner->getByPuuid('simivar', 'eun1');
93+
self::assertInstanceOf(SummonerDTO::class, $result);
94+
}
95+
96+
public function testGetByIdReturnsNullOnGetNull(): void
97+
{
98+
$summoner = new Summoner($this->setUpNullResponse('lol/summoner/v4/summoners/simivar'));
99+
$result = $summoner->getById('simivar', 'eun1');
100+
self::assertNull($result);
101+
}
102+
103+
public function testGetByIdReturnsSummonerDTOOnSuccess(): void
104+
{
105+
$summoner = new Summoner($this->setUpJsonResponse('lol/summoner/v4/summoners/simivar'));
106+
$result = $summoner->getById('simivar', 'eun1');
107+
self::assertInstanceOf(SummonerDTO::class, $result);
108+
}
57109
}

tests/Unit/API/Version4/ThirdPartyCodeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Riot\Tests\API\Version4;
5+
namespace Riot\Tests\Unit\API\Version4;
66

77
use PHPUnit\Framework\TestCase;
88
use Psr\Http\Message\ResponseInterface;

tests/Unit/DTO/SummonerDTOTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Riot\Tests\DTO;
5+
namespace Riot\Tests\Unit\DTO;
66

77
use PHPUnit\Framework\TestCase;
88
use Riot\DTO\SummonerDTO;

tests/Unit/Exception/RateLimitExceededExceptionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Riot\Tests\Exception;
5+
namespace Riot\Tests\Unit\Exception;
66

77
use PHPUnit\Framework\TestCase;
88
use Psr\Http\Message\ResponseInterface;

0 commit comments

Comments
 (0)