Skip to content

Commit 5fb3316

Browse files
author
Dominik süßenbach
committed
* Updated dependencies
* Fix register for tft & lol after riots api change
1 parent fd1708d commit 5fb3316

File tree

4 files changed

+1183
-878
lines changed

4 files changed

+1183
-878
lines changed

app/Services/Gateways/LeagueOfLegendsGateway.php

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -258,25 +258,65 @@ public function grabPlayerIdentity(array $params): ?array
258258
return null;
259259
}
260260

261-
$url = $this->getPlattformBaseUrl().'/lol/summoner/v4/summoners/by-name/'.$params[2];
262-
$summonerResponse = Http::withHeaders(['X-Riot-Token' => $this->getApiKey()])
261+
$identity = null;
262+
$accountResult = $this->grabAccount($params[2]);
263+
if ($accountResult) {
264+
$summonerResult = $this->grabSummoner($accountResult['puuid']);
265+
$identity = $summonerResult;
266+
$identity['name'] = $accountResult['gameName'].'#'.$accountResult['tagLine'];
267+
}
268+
269+
return $identity;
270+
}
271+
272+
/**
273+
* @param string $riotId Example: User#1234
274+
*/
275+
public function grabAccount(string $riotId): ?array
276+
{
277+
if (! str_contains($riotId, '#')) {
278+
return null;
279+
}
280+
281+
$nameTag = explode('#', $riotId);
282+
$url = $this->getRegionBaseUrl()."/riot/account/v1/accounts/by-riot-id/$nameTag[0]/$nameTag[1]";
283+
/** @var Response $accountResponse */
284+
$accountResponse = Http::withHeaders(['X-Riot-Token' => $this->getApiKey()])
263285
->withMiddleware(RateLimiterMiddleware::perSecond($this->getRateLimit(), new LolRateLimiterStore))
264286
->retry(3, 1000, throw: false)
265287
->get($url);
266288

267-
$identity = null;
289+
$result = null;
290+
if ($accountResponse->successful()) {
291+
/** @var array $result */
292+
$result = $accountResponse->json();
293+
} else {
294+
Log::warning('Could not get account from Riot API',
295+
['apiKey' => $this->getApiKey(), 'riotId' => $riotId, 'responseStatus' => $accountResponse->status(), 'url' => $url]);
296+
}
297+
298+
return $result;
299+
}
300+
301+
public function grabSummoner(string $puuid): ?array
302+
{
303+
$url = $this->getPlattformBaseUrl().'/lol/summoner/v4/summoners/by-puuid/'.$puuid;
268304
/** @var Response $summonerResponse */
305+
$summonerResponse = Http::withHeaders(['X-Riot-Token' => $this->getApiKey()])
306+
->withMiddleware(RateLimiterMiddleware::perSecond($this->getRateLimit(), new LolRateLimiterStore))
307+
->retry(3, 1000, throw: false)
308+
->get($url);
309+
310+
$result = null;
269311
if ($summonerResponse->successful()) {
312+
/** @var array $result */
270313
$result = $summonerResponse->json();
271-
if (is_array($result)) {
272-
$identity = $result;
273-
}
274314
} else {
275-
Log::warning('Could not get player identity from Riot API for League of Legends',
276-
['apiKey' => $this->getApiKey(), 'params' => $params, 'responseStatus' => $summonerResponse->status(), 'url' => $url]);
315+
Log::warning('Could not get summoner from Riot API',
316+
['apiKey' => $this->getApiKey(), 'puuid' => $puuid, 'responseStatus' => $summonerResponse->status(), 'url' => $url]);
277317
}
278318

279-
return $identity;
319+
return $result;
280320
}
281321

282322
public function grabPositionImage(string $positionName): ?string
@@ -478,7 +518,7 @@ protected function grabMatches(GameUser $gameUser, int $offset, int $count, stri
478518
foreach ($matchIds as $matchId) {
479519
$url = $this->getRegionBaseUrl().'/lol/match/v5/matches/'.$matchId;
480520
$matchResponse = Http::withHeaders(['X-Riot-Token' => $this->getApiKey()])
481-
->withMiddleware(RateLimiterMiddleware::perSecond($this->getRateLimit(), new LolRateLimiterStore()))
521+
->withMiddleware(RateLimiterMiddleware::perSecond($this->getRateLimit(), new LolRateLimiterStore))
482522
->retry(3, 1000, throw: false)
483523
->get($url);
484524
/** @var Response $matchResponse */

app/Services/Gateways/TeamfightTacticsGateway.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function grabPlayerData(GameUser $gameUser): ?array
3636
$stats = null;
3737
$url = $this->getPlattformBaseUrl().'/tft/league/v1/entries/by-summoner/'.$gameUser->options['id'];
3838
$leagueResponse = Http::withHeaders(['X-Riot-Token' => $this->getApiKey()])
39-
->withMiddleware(RateLimiterMiddleware::perSecond($this->rateLimit, new TftRateLimiterStore()))
39+
->withMiddleware(RateLimiterMiddleware::perSecond($this->rateLimit, new TftRateLimiterStore))
4040
->retry(3, 1000, throw: false)
4141
->get($url);
4242

@@ -54,31 +54,25 @@ public function grabPlayerData(GameUser $gameUser): ?array
5454
return $stats;
5555
}
5656

57-
public function grabPlayerIdentity(array $params): ?array
57+
public function grabSummoner(string $puuid): ?array
5858
{
59-
if (! isset($params[2])) {
60-
return null;
61-
}
62-
63-
$url = $this->getPlattformBaseUrl().'/tft/summoner/v1/summoners/by-name/'.$params[2];
59+
$url = $this->getPlattformBaseUrl().'/tft/summoner/v1/summoners/by-puuid/'.$puuid;
60+
/** @var Response $summonerResponse */
6461
$summonerResponse = Http::withHeaders(['X-Riot-Token' => $this->getApiKey()])
65-
->withMiddleware(RateLimiterMiddleware::perSecond($this->rateLimit, new TftRateLimiterStore()))
62+
->withMiddleware(RateLimiterMiddleware::perSecond($this->getRateLimit(), new TftRateLimiterStore))
6663
->retry(3, 1000, throw: false)
6764
->get($url);
6865

69-
$summoner = null;
70-
/** @var Response $summonerResponse */
66+
$result = null;
7167
if ($summonerResponse->successful()) {
68+
/** @var array $result */
7269
$result = $summonerResponse->json();
73-
if (is_array($result)) {
74-
$summoner = $result;
75-
}
7670
} else {
77-
Log::warning('Could not get player identity from Riot API for Teamfight Tactics',
78-
['apiKey' => $this->getApiKey(), 'params' => $params, 'responseStatus' => $summonerResponse->status(), 'url' => $url]);
71+
Log::warning('Could not get summoner from Riot API',
72+
['apiKey' => $this->getApiKey(), 'puuid' => $puuid, 'responseStatus' => $summonerResponse->status(), 'url' => $url]);
7973
}
8074

81-
return $summoner;
75+
return $result;
8276
}
8377

8478
public function grabPositionImage(string $positionName): ?string

app/Services/UserService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ protected function registerUser(Game $game, string $identityId, array $params):
234234

235235
$user = User::with('games')->find($identityId);
236236
if (! $user) {
237-
$user = new User();
237+
$user = new User;
238238
$user->identity_id = $identityId;
239239
$user->save();
240240
}

0 commit comments

Comments
 (0)