Compare commits
2 Commits
b871a4fac2
...
4d26acea5b
Author | SHA1 | Date |
---|---|---|
Timothy Warren | 4d26acea5b | |
Timothy Warren | a38c9712e6 |
|
@ -27,10 +27,10 @@ use Aviat\AnimeClient\API\Kitsu;
|
|||
</div>
|
||||
</section>
|
||||
|
||||
<?php if (array_key_exists('anime', $data['media']) || array_key_exists('manga', $data['media'])): ?>
|
||||
<?php if ( ! (empty($data['media']['anime']) || empty($data['media']['manga']))): ?>
|
||||
<h3>Media</h3>
|
||||
<div class="tabs">
|
||||
<?php if (array_key_exists('anime', $data['media'])): ?>
|
||||
<?php if ( ! empty($data['media']['anime'])): ?>
|
||||
<input checked="checked" type="radio" id="media-anime" name="media-tabs" />
|
||||
<label for="media-anime">Anime</label>
|
||||
|
||||
|
@ -58,7 +58,7 @@ use Aviat\AnimeClient\API\Kitsu;
|
|||
</section>
|
||||
<?php endif ?>
|
||||
|
||||
<?php if (array_key_exists('manga', $data['media'])): ?>
|
||||
<?php if ( ! empty($data['media']['manga'])): ?>
|
||||
<input type="radio" id="media-manga" name="media-tabs" />
|
||||
<label for="media-manga">Manga</label>
|
||||
|
||||
|
|
|
@ -131,19 +131,38 @@ final class UserTransformer extends AbstractTransformer {
|
|||
return $output;
|
||||
}
|
||||
|
||||
private function organizeStats($stats, $data): array
|
||||
private function organizeStats($stats, $data = []): array
|
||||
{
|
||||
// $timeOnAnime = $this->formatAnimeTime($orgData['attributes']['lifeSpentOnAnime']);
|
||||
$animeStats = [];
|
||||
$mangaStats = [];
|
||||
$otherStats = [];
|
||||
|
||||
return [
|
||||
'Time spent watching anime:' => $this->formatAnimeTime($stats['anime-amount-consumed']['time']),
|
||||
'Anime series watched:' => number_format($stats['anime-amount-consumed']['media']),
|
||||
'Anime episodes watched:' => number_format($stats['anime-amount-consumed']['units']),
|
||||
'Manga series read:' => number_format($stats['manga-amount-consumed']['media']),
|
||||
'Manga chapters read:' => number_format($stats['manga-amount-consumed']['units']),
|
||||
'Posts:' => number_format($data['postsCount']),
|
||||
'Comments:' => number_format($data['commentsCount']),
|
||||
'Media Rated:' => number_format($data['ratingsCount']),
|
||||
];
|
||||
if (array_key_exists('anime-amount-consumed', $stats))
|
||||
{
|
||||
$animeStats = [
|
||||
'Time spent watching anime:' => $this->formatAnimeTime($stats['anime-amount-consumed']['time']),
|
||||
'Anime series watched:' => number_format($stats['anime-amount-consumed']['media']),
|
||||
'Anime episodes watched:' => number_format($stats['anime-amount-consumed']['units']),
|
||||
];
|
||||
}
|
||||
|
||||
if (array_key_exists('manga-amount-consumed', $stats))
|
||||
{
|
||||
$mangaStats = [
|
||||
'Manga series read:' => number_format($stats['manga-amount-consumed']['media']),
|
||||
'Manga chapters read:' => number_format($stats['manga-amount-consumed']['units']),
|
||||
];
|
||||
}
|
||||
|
||||
if ( ! empty($data))
|
||||
{
|
||||
$otherStats = [
|
||||
'Posts:' => number_format($data['postsCount']),
|
||||
'Comments:' => number_format($data['commentsCount']),
|
||||
'Media Rated:' => number_format($data['ratingsCount']),
|
||||
];
|
||||
}
|
||||
|
||||
return array_merge($animeStats, $mangaStats, $otherStats);
|
||||
}
|
||||
}
|
|
@ -18,8 +18,7 @@ namespace Aviat\AnimeClient\API;
|
|||
|
||||
use function Amp\call;
|
||||
use function Amp\Promise\{all, wait};
|
||||
|
||||
use Amp\Artax\{Client, DefaultClient};
|
||||
use function Aviat\AnimeClient\getApiClient;
|
||||
|
||||
/**
|
||||
* Class to simplify making and validating simultaneous requests
|
||||
|
@ -72,10 +71,7 @@ final class ParallelAPIRequest {
|
|||
*/
|
||||
public function makeRequests(): array
|
||||
{
|
||||
$client = new DefaultClient();
|
||||
|
||||
// Timeouts suck
|
||||
$client->setOption(Client::OP_TRANSFER_TIMEOUT, 0);
|
||||
$client = getApiClient();
|
||||
|
||||
$promises = [];
|
||||
|
||||
|
@ -98,10 +94,7 @@ final class ParallelAPIRequest {
|
|||
*/
|
||||
public function getResponses(): array
|
||||
{
|
||||
$client = new DefaultClient();
|
||||
|
||||
// Timeouts suck
|
||||
$client->setOption(Client::OP_TRANSFER_TIMEOUT, 0);
|
||||
$client = getApiClient();
|
||||
|
||||
$promises = [];
|
||||
|
||||
|
|
|
@ -207,6 +207,24 @@ function checkFolderPermissions(ConfigInterface $config): array
|
|||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an API Client, with better defaults
|
||||
*
|
||||
* @return DefaultClient
|
||||
*/
|
||||
function getApiClient ()
|
||||
{
|
||||
static $client;
|
||||
|
||||
if ($client === NULL)
|
||||
{
|
||||
$client = new DefaultClient;
|
||||
$client->setOption(Client::OP_TRANSFER_TIMEOUT, 0);
|
||||
}
|
||||
|
||||
return $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simplify making a request with Artax
|
||||
*
|
||||
|
@ -216,8 +234,7 @@ function checkFolderPermissions(ConfigInterface $config): array
|
|||
*/
|
||||
function getResponse ($request): Response
|
||||
{
|
||||
$client = new DefaultClient;
|
||||
$client->setOption(Client::OP_TRANSFER_TIMEOUT, 0);
|
||||
$client = getApiClient();
|
||||
return wait($client->request($request));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue