From 4ea26acd79aece261ce66b000f804af009fe5d4b Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 3 May 2018 19:18:57 +1000 Subject: [PATCH] Fix returning of 429 headers --- src/API.php | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/API.php b/src/API.php index 53bfc36..b4c83dd 100644 --- a/src/API.php +++ b/src/API.php @@ -73,7 +73,6 @@ private function request($shard, $endpoint) */ public function getTelemetry($telemetryUrl) { - $response = $this->client->get($telemetryUrl); if ($response->getStatusCode() !== 200) { @@ -108,6 +107,63 @@ public function getPlayer($shard, $playerId) return $this->processPlayerResponse($response); } + public function getPlayerSeason($shard, $playerId, $season) + { + $response = $this->request($shard, "players/$playerId/seasons/$season"); + $response = new JsonApiResponse($response); + $hydrator = new ClassHydrator(); + $playerSeason = $hydrator->hydrate($response->document()); + + $matches = $response->document()->primaryResource()->relationship('matchesSolo')->toArray(); + $playerSeason->matches['solo'] = []; + foreach ($matches['data'] as $match) { + $playerSeason->matches['solo'][] = $match['id']; + } + + $matches = $response->document()->primaryResource()->relationship('matchesSoloFPP')->toArray(); + $playerSeason->matches['solo-fpp'] = []; + foreach ($matches['data'] as $match) { + $playerSeason->matches['solo-fpp'][] = $match['id']; + } + + $matches = $response->document()->primaryResource()->relationship('matchesDuo')->toArray(); + $playerSeason->matches['duo'] = []; + foreach ($matches['data'] as $match) { + $playerSeason->matches['duo'][] = $match['id']; + } + + $matches = $response->document()->primaryResource()->relationship('matchesDuoFPP')->toArray(); + $playerSeason->matches['duo-fpp'] = []; + foreach ($matches['data'] as $match) { + $playerSeason->matches['duo-fpp'][] = $match['id']; + } + + $matches = $response->document()->primaryResource()->relationship('matchesSquad')->toArray(); + $playerSeason->matches['squad'] = []; + foreach ($matches['data'] as $match) { + $playerSeason->matches['squad'][] = $match['id']; + } + + $matches = $response->document()->primaryResource()->relationship('matchesSquadFPP')->toArray(); + $playerSeason->matches['squad-fpp'] = []; + foreach ($matches['data'] as $match) { + $playerSeason->matches['squad-fpp'][] = $match['id']; + } + + return $playerSeason; + } + + public function getSeasons($shard) + { + $response = $this->request($shard, "seasons"); + + $response = new JsonApiResponse($response); + $hydrator = new ClassHydrator(); + $seasons = $hydrator->hydrate($response->document()); + + return $seasons; + } + /** * @param $shard * @param array $filters