Skip to content
Permalink
Browse files

Replace old Requests engine

  • Loading branch information...
supergrecko committed Jun 23, 2019
1 parent 688934e commit 7228ec93ec87e17a61b4f689a4f5dc53de0bd2f3
@@ -121,7 +121,7 @@ private function read($real): array
return json_decode($this->fs->read($key), 1);
}
throw new LeagueException("Target file not found.");
throw new LeagueException("ERROR (code 9): Target file not found.");
}
/**
@@ -33,10 +33,10 @@ class Application
'HTTP_ERROR_EXCEPT' => [
'code.id'
],
'FORCE_CACHE_PERMANENT' => [
'CACHE_PERMANENT' => [
'match.id', 'match.timeline'
],
'FORCE_CACHE_NONE' => [
'CACHE_NONE' => [
'code.id'
]
];
@@ -133,7 +133,7 @@ public function load(): void
return;
}
throw new LeagueException("No valid API keys were found.");
throw new LeagueException("ERROR (code 12): No valid API keys were found.");
}
/**
@@ -224,11 +224,11 @@ public function setProvider(string $provider): void
*/
public function getCache(string $key = 'generic'): Cache
{
if ($this->caches[$key]) {
if (isset($this->caches[$key])) {
return $this->caches[$key];
}
throw new LeagueException("Cache Provider could not be located.");
throw new LeagueException("ERROR (code 13): Cache Provider could not be located.");
}
/**
@@ -150,7 +150,7 @@ public static function code(string $region, $ttl = 3600): Code
*/
public static function stub(): void
{
throw new LeagueException("Unsupported Endpoint.");
throw new LeagueException("ERROR (code 11): Unsupported Endpoint.");
}
/**
@@ -160,7 +160,7 @@ public static function stub(): void
*/
public static function tournament(): void
{
throw new LeagueException("Unsupported Endpoint.");
throw new LeagueException("ERROR (code 10): Unsupported Endpoint.");
}
}
@@ -24,14 +24,12 @@ class Champion extends Template
*/
public function rotation(): ChampionInfo
{
return Request::make(['champion', __FUNCTION__])
->useStandard()
->setDestination('https://{region}.api.riotgames.com/lol/platform/v3/champion-rotations')
->setMethod('GET')
->setArguments(['region' => $this->region])
->setTtl($this->ttl)
->compile()
->sendRequest();
return Request::create()
->with('destination', 'https://{region}.api.riotgames.com/lol/platform/v3/champion-rotations')
->with('ttl', $this->ttl)
->with('function', 'champion.rotation')
->with('region', $this->region)
->send();
}
}
@@ -24,14 +24,13 @@ class Code extends Template
*/
public function id(string $id)
{
return Request::make(['code', __FUNCTION__])
->useStandard()
->setDestination('https://{region}.api.riotgames.com/lol/platform/v4/third-party-code/by-summoner/{id}')
->setMethod('GET')
->setArguments(['region' => $this->region, 'id' => $id])
->setTtl($this->ttl)
->compile()
->sendRequest();
return Request::create()
->with('destination', 'https://{region}.api.riotgames.com/lol/platform/v4/third-party-code/by-summoner/{?}')
->with('ttl', $this->ttl)
->with('function', 'code.id')
->with('arguments', [$id])
->with('region', $this->region)
->send();
}
}
@@ -26,14 +26,13 @@ class League extends Template
*/
public function positions(string $id): LeagueEntryList
{
return Request::make(['league', __FUNCTION__])
->useStandard()
->setDestination('https://{region}.api.riotgames.com/lol/league/v4/entries/by-summoner/{id}')
->setMethod('GET')
->setArguments(['region' => $this->region, 'id' => $id])
->setTtl($this->ttl)
->compile()
->sendRequest();
return Request::create()
->with('destination', 'https://{region}.api.riotgames.com/lol/league/v4/entries/by-summoner/{?}')
->with('ttl', $this->ttl)
->with('function', 'league.positions')
->with('arguments', [$id])
->with('region', $this->region)
->send();
}
/**
@@ -45,14 +44,13 @@ public function positions(string $id): LeagueEntryList
*/
public function id(string $id): LeagueCollection
{
return Request::make(['league', __FUNCTION__])
->useStandard()
->setDestination('https://{region}.api.riotgames.com/lol/league/v4/leagues/{id}')
->setMethod('GET')
->setArguments(['region' => $this->region, 'id' => $id])
->setTtl($this->ttl)
->compile()
->sendRequest();
return Request::create()
->with('destination', 'https://{region}.api.riotgames.com/lol/league/v4/leagues/{?}')
->with('ttl', $this->ttl)
->with('function', 'league.id')
->with('arguments', [$id])
->with('region', $this->region)
->send();
}
/**
@@ -67,14 +65,13 @@ public function id(string $id): LeagueCollection
*/
public function entries(string $queue, string $tier, string $division, $page = 1): LeagueEntryList
{
return Request::make(['league', __FUNCTION__])
->useStandard()
->setDestination('https://{region}.api.riotgames.com/lol/league/v4/entries/{queue}/{tier}/{division}?page={page}')
->setMethod('GET')
->setArguments(['region' => $this->region, 'queue' => $queue, 'tier' => $tier, 'division' => $division, 'page' => $page])
->setTtl($this->ttl)
->compile()
->sendRequest();
return Request::create()
->with('destination', 'https://{region}.api.riotgames.com/lol/league/v4/entries/{?}/{?}/{?}?page={?}')
->with('ttl', $this->ttl)
->with('function', 'league.entries')
->with('arguments', [$queue, $tier, $division, $page])
->with('region', $this->region)
->send();
}
/**
@@ -86,14 +83,13 @@ public function entries(string $queue, string $tier, string $division, $page = 1
*/
public function challenger(string $queue): LeagueCollection
{
return Request::make(['league', __FUNCTION__])
->useStandard()
->setDestination('https://{region}.api.riotgames.com/lol/league/v4/challengerleagues/by-queue/{queue}')
->setMethod('GET')
->setArguments(['region' => $this->region, 'queue' => $queue])
->setTtl($this->ttl)
->compile()
->sendRequest();
return Request::create()
->with('destination', 'https://{region}.api.riotgames.com/lol/league/v4/challengerleagues/by-queue/{?}')
->with('ttl', $this->ttl)
->with('function', 'league.challenger')
->with('arguments', [$queue])
->with('region', $this->region)
->send();
}
/**
@@ -105,14 +101,13 @@ public function challenger(string $queue): LeagueCollection
*/
public function master(string $queue): LeagueCollection
{
return Request::make(['league', __FUNCTION__])
->useStandard()
->setDestination('https://{region}.api.riotgames.com/lol/league/v4/masterleagues/by-queue/{queue}')
->setMethod('GET')
->setArguments(['region' => $this->region, 'queue' => $queue])
->setTtl($this->ttl)
->compile()
->sendRequest();
return Request::create()
->with('destination', 'https://{region}.api.riotgames.com/lol/league/v4/masterleagues/by-queue/{?}')
->with('ttl', $this->ttl)
->with('function', 'league.challenger')
->with('arguments', [$queue])
->with('region', $this->region)
->send();
}
/**
@@ -124,14 +119,13 @@ public function master(string $queue): LeagueCollection
*/
public function grandmaster(string $queue): LeagueCollection
{
return Request::make(['league', __FUNCTION__])
->useStandard()
->setDestination('https://{region}.api.riotgames.com/lol/league/v4/grandmasterleagues/by-queue/{queue}')
->setMethod('GET')
->setArguments(['region' => $this->region, 'queue' => $queue])
->setTtl($this->ttl)
->compile()
->sendRequest();
return Request::create()
->with('destination', 'https://{region}.api.riotgames.com/lol/league/v4/grandmasterleagues/by-queue/{?}')
->with('ttl', $this->ttl)
->with('function', 'league.challenger')
->with('arguments', [$queue])
->with('region', $this->region)
->send();
}
}
@@ -26,14 +26,13 @@ class Mastery extends Template
*/
public function all(string $id): ChampionMasteryList
{
return Request::make(['mastery', __FUNCTION__])
->useStandard()
->setDestination('https://{region}.api.riotgames.com/lol/champion-mastery/v4/champion-masteries/by-summoner/{id}')
->setMethod('GET')
->setArguments(['region' => $this->region, 'id' => $id])
->setTtl($this->ttl)
->compile()
->sendRequest();
return Request::create()
->with('destination', 'https://{region}.api.riotgames.com/lol/champion-mastery/v4/champion-masteries/by-summoner/{?}')
->with('ttl', $this->ttl)
->with('function', 'mastery.all')
->with('arguments', [$id])
->with('region', $this->region)
->send();
}
/**
@@ -46,14 +45,13 @@ public function all(string $id): ChampionMasteryList
*/
public function id(string $id, $champion): ChampionMastery
{
return Request::make(['mastery', __FUNCTION__])
->useStandard()
->setDestination('https://{region}.api.riotgames.com/lol/champion-mastery/v4/champion-masteries/by-summoner/{id}/by-champion/{champion}')
->setMethod('GET')
->setArguments(['region' => $this->region, 'id' => $id, 'champion' => $champion])
->setTtl($this->ttl)
->compile()
->sendRequest();
return Request::create()
->with('destination', 'https://{region}.api.riotgames.com/lol/champion-mastery/v4/champion-masteries/by-summoner/{?}/by-champion/{?}')
->with('ttl', $this->ttl)
->with('function', 'mastery.id')
->with('arguments', [$id, $champion])
->with('region', $this->region)
->send();
}
/**
@@ -65,14 +63,13 @@ public function id(string $id, $champion): ChampionMastery
*/
public function score(string $id): int
{
return Request::make(['mastery', __FUNCTION__])
->useStandard()
->setDestination('https://{region}.api.riotgames.com/lol/champion-mastery/v4/scores/by-summoner/{id}')
->setMethod('GET')
->setArguments(['region' => $this->region, 'id' => $id])
->setTtl($this->ttl)
->compile()
->sendRequest();
return Request::create()
->with('destination', 'https://{region}.api.riotgames.com/lol/champion-mastery/v4/scores/by-summoner/{?}')
->with('ttl', $this->ttl)
->with('function', 'mastery.score')
->with('arguments', [$id])
->with('region', $this->region)
->send();
}
}
@@ -49,15 +49,13 @@ public function list(string $id, array $filters = []): MatchHistory
if ($item) $str .= '&' . http_build_query([$key => $item]);
}
}
return Request::make(['match', __FUNCTION__])
->useStandard()
->setDestination('https://{region}.api.riotgames.com/lol/match/v4/matchlists/by-account/{id}?' . trim($str, '&'))
->setMethod('GET')
->setArguments(['region' => $this->region, 'id' => $id])
->setTtl($this->ttl)
->compile()
->sendRequest();
return Request::create()
->with('destination', 'https://{region}.api.riotgames.com/lol/match/v4/matchlists/by-account/{?}?' . trim($str, '&'))
->with('ttl', $this->ttl)
->with('function', 'match.list')
->with('arguments', [$id])
->with('region', $this->region)
->send();
}
/**
@@ -69,14 +67,13 @@ public function list(string $id, array $filters = []): MatchHistory
*/
public function timeline($id): MatchTimeline
{
return Request::make(['match', __FUNCTION__])
->useStandard()
->setDestination('https://{region}.api.riotgames.com/lol/match/v4/timelines/by-match/{id}')
->setMethod('GET')
->setArguments(['region' => $this->region, 'id' => $id])
->setTtl($this->ttl)
->compile()
->sendRequest();
return Request::create()
->with('destination', 'https://{region}.api.riotgames.com/lol/match/v4/timelines/by-match/{?}')
->with('ttl', $this->ttl)
->with('function', 'match.timeline')
->with('arguments', [$id])
->with('region', $this->region)
->send();
}
/**
@@ -88,14 +85,13 @@ public function timeline($id): MatchTimeline
*/
public function id($id): MatchCollection
{
return Request::make(['match', __FUNCTION__])
->useStandard()
->setDestination('https://{region}.api.riotgames.com/lol/match/v4/matches/{id}')
->setMethod('GET')
->setArguments(['region' => $this->region, 'id' => $id])
->setTtl($this->ttl)
->compile()
->sendRequest();
return Request::create()
->with('destination', 'https://{region}.api.riotgames.com/lol/match/v4/matches/{?}')
->with('ttl', $this->ttl)
->with('function', 'match.id')
->with('arguments', [$id])
->with('region', $this->region)
->send();
}
}

0 comments on commit 7228ec9

Please sign in to comment.
You can’t perform that action at this time.