Skip to content
Permalink
Browse files

Static data serving

  • Loading branch information...
supergrecko committed Mar 29, 2019
1 parent 2302b1a commit 4863d6ca6d4eefec5e7720f3b0e43059c9b54a5d
19 LICENSE
@@ -0,0 +1,19 @@
Copyright (c) 2019 Mats Larsen, https://github.com/supergrecko <me@supergrecko.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@@ -5,18 +5,18 @@

# The Basics
- [Creating the Client](Creating-the-Client)
- [Tokens (API Keys)](https://github.com/supergrecko/RiotQuest/wiki/Creating-the-Client#tokens)
- [Tokens (API Keys)](Creating-the-Client#tokens)
- [Sending the Request](Sending-the-Request)
- [Handling the Response](Handling-the-Response)

# Endpoints

# Framework
- [Return Types](Return-Types)
- [Working with Collections](https://github.com/supergrecko/RiotQuest/wiki/Return-Types#working-with-a-collection)
- [Working with Collections](Return-Types#working-with-a-collection)
- [Rate Limiting](Rate-Limiting)
- [Caching](Caching)
- [Symfony Cache Example](https://github.com/supergrecko/RiotQuest/wiki/Caching#how-to-use-symfonys-cache)
- [Symfony Cache Example](Caching#how-to-use-symfonys-cache)

# Collections
@foreach ($class['collections'] as $col)
Submodule out updated from 2f138b to 13cf86
@@ -9,10 +9,9 @@
* Class Client
*
* Static accessor for the entire Client API
* Provies helper method to essential usages
* Provides helper method to essential usages
* for the API.
*
* TODO: cache templates for collections
* TODO: unit tests
*
* @package RiotQuest\Support\Facades
@@ -28,7 +27,7 @@ class Client extends Module
* @param $limit
* @return Token
*/
public static function token($token, $type, $limit): Token
public static function token($token, $type, $limit)
{
return new Token($token, $type, $limit);
}
@@ -0,0 +1,52 @@
<?php
namespace RiotQuest\Components\Console\Make;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use RiotQuest\Components\DataProvider\DataDragon\Assets;
class TemplatesCommand extends Command
{
protected static $defaultName = 'make:static';
protected function configure()
{
$this
->setDescription('Generates the static assets for a locale.')
->setHelp('Gather all static assets for certain locale')
->addArgument('locale', InputArgument::REQUIRED, 'The locate to target');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln([
'<info>================================</info>',
'* RiotQuest CLI 1.0 ',
'<info>================================</info>'
]);
$output->writeln([
'- Generating Static Assets',
]);
Assets::setLocate($input->getArgument('locale'));
foreach (Assets::$map as $key => $value)
{
Assets::update($key);
}
$output->writeln([
'- Completed Static Asset Generation',
]);
$output->writeln([
'<info>================================</info>'
]);
}
}
@@ -0,0 +1,115 @@
<?php
namespace RiotQuest\Components\DataProvider\DataDragon;
use RiotQuest\Components\Framework\Utils\Versions;
class Assets
{
/**
* Game version
*
* @var
*/
public static $version;
/**
* Loaded files into memory
*
* @var array
*/
public static $loaded = [
];
/**
* Locale to pull data from
*
* @var string
*/
public static $locale = 'en_GB';
/**
* DataDragon basepath
*
* @var string
*/
public static $basePath = 'https://ddragon.leagueoflegends.com/cdn/%s';
/**
* Basepath for output directory
*
* @var string
*/
public const OUTPUT_DIRECTORY = __DIR__ . '/../../../../storage/static/';
/**
* Map over static data endpoints
*
* @var array
*/
public static $map = [
'champion' => "/data/%s/champion.json"
];
/**
* Paths out for assets for local storage
*
* @var array
*/
public static $out = [
'champion' => self::OUTPUT_DIRECTORY . '%s/champion.json'
];
/***
* Bootstrapper
*
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public static function enable()
{
static::$version = Versions::current();
}
/**
* Override the locale
*
* @param $locale
*/
public static function setLocate($locale)
{
static::$locale = $locale;
}
/**
* Updates an asset in the registry
*
* @param $path
*/
public static function update($path)
{
if (in_array($path, array_keys(static::$map))) {
$file = sprintf(static::$basePath . static::$map[$path], static::$version, static::$locale);
$output = sprintf(static::$out[$path], static::$locale);
file_put_contents($output, file_get_contents($file));
}
}
/**
* Get a file from the registry
*
* @param $path
* @return mixed
*/
public static function get($path)
{
if (in_array($path, array_keys(static::$map))) {
if (!isset(static::$loaded[$path . '/' . static::$locale])) {
static::$loaded[$path . '/' . static::$locale] = json_decode(file_get_contents(sprintf(static::$out[$path], static::$locale)), 1);
}
return static::$loaded[$path . '/' . static::$locale];
}
}
}
@@ -0,0 +1,69 @@
<?php
namespace RiotQuest\Components\DataProvider\DataDragon;
use RiotQuest\Components\Framework\Utils\Versions;
class Dragon
{
/**
* Game version to use
*
* @var string
*/
private static $version;
/**
* Dragon constructor.
*
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public static function enable()
{
static::$version = Versions::current();
}
/**
* Override the current version
*
* @param $version
*/
public static function overrideVersion($version)
{
static::$version = $version;
}
/**
* Resets the overwritten version
*
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public static function resetVersion()
{
static::$version = Versions::current();
}
/**
* Get a summoner icon link
*
* @param $id
* @return string
*/
public static function getProfileIcon($id)
{
return sprintf('https://ddragon.leagueoflegends.com/cdn/%s/img/profileicon/%d.png', static::$version, $id);
}
/**
* Get a champion square icon
*
* @param $id
* @return string
*/
public static function getChampionSquare($id)
{
return sprintf('https://ddragon.leagueoflegends.com/cdn/%s/img/champion/%s.png', static::$version, $id);
}
}
@@ -2,6 +2,8 @@
namespace RiotQuest\Components\Framework\Collections;
use RiotQuest\Components\Framework\Client\Client;
/**
* Class LeagueItem
*
@@ -24,6 +26,18 @@
class LeagueItem extends Collection
{
/**
* Get the summoner object for this league item
*
* @return Summoner
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Psr\SimpleCache\InvalidArgumentException
* @throws \ReflectionException
* @throws \RiotQuest\Contracts\RiotQuestException
*/
public function getSummoner()
{
return Client::summoner($this->region)->id($this->summonerId);
}
}

0 comments on commit 4863d6c

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