@@ -258,25 +258,65 @@ public function grabPlayerIdentity(array $params): ?array
258
258
return null ;
259
259
}
260
260
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 ()])
263
285
->withMiddleware (RateLimiterMiddleware::perSecond ($ this ->getRateLimit (), new LolRateLimiterStore ))
264
286
->retry (3 , 1000 , throw: false )
265
287
->get ($ url );
266
288
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 ;
268
304
/** @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 ;
269
311
if ($ summonerResponse ->successful ()) {
312
+ /** @var array $result */
270
313
$ result = $ summonerResponse ->json ();
271
- if (is_array ($ result )) {
272
- $ identity = $ result ;
273
- }
274
314
} 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 ]);
277
317
}
278
318
279
- return $ identity ;
319
+ return $ result ;
280
320
}
281
321
282
322
public function grabPositionImage (string $ positionName ): ?string
@@ -478,7 +518,7 @@ protected function grabMatches(GameUser $gameUser, int $offset, int $count, stri
478
518
foreach ($ matchIds as $ matchId ) {
479
519
$ url = $ this ->getRegionBaseUrl ().'/lol/match/v5/matches/ ' .$ matchId ;
480
520
$ matchResponse = Http::withHeaders (['X-Riot-Token ' => $ this ->getApiKey ()])
481
- ->withMiddleware (RateLimiterMiddleware::perSecond ($ this ->getRateLimit (), new LolRateLimiterStore () ))
521
+ ->withMiddleware (RateLimiterMiddleware::perSecond ($ this ->getRateLimit (), new LolRateLimiterStore ))
482
522
->retry (3 , 1000 , throw: false )
483
523
->get ($ url );
484
524
/** @var Response $matchResponse */
0 commit comments