Skip to content
This repository has been archived by the owner on Jul 2, 2020. It is now read-only.

Commit

Permalink
Fix returning of 429 headers
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbroberg committed May 3, 2018
1 parent d2d419c commit 4ea26ac
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion src/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ private function request($shard, $endpoint)
*/
public function getTelemetry($telemetryUrl)
{

$response = $this->client->get($telemetryUrl);

if ($response->getStatusCode() !== 200) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4ea26ac

Please sign in to comment.