Remove default API client timeouts, fix time on anime calculation
All checks were successful
timw4mail/HummingBirdAnimeClient/PR-14 This commit looks good
All checks were successful
timw4mail/HummingBirdAnimeClient/PR-14 This commit looks good
This commit is contained in:
parent
aacf7ece65
commit
b871a4fac2
@ -97,11 +97,15 @@ final class UserTransformer extends AbstractTransformer {
|
|||||||
/**
|
/**
|
||||||
* Format the time spent on anime in a more readable format
|
* Format the time spent on anime in a more readable format
|
||||||
*
|
*
|
||||||
* @param int $minutes
|
* @param int $seconds
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function formatAnimeTime(int $minutes): string
|
private function formatAnimeTime(int $seconds): string
|
||||||
{
|
{
|
||||||
|
// All the seconds left
|
||||||
|
$remSeconds = $seconds % 60;
|
||||||
|
$minutes = ($seconds - $remSeconds) / 60;
|
||||||
|
|
||||||
$minutesPerDay = 1440;
|
$minutesPerDay = 1440;
|
||||||
$minutesPerYear = $minutesPerDay * 365;
|
$minutesPerYear = $minutesPerDay * 365;
|
||||||
|
|
||||||
@ -111,15 +115,13 @@ final class UserTransformer extends AbstractTransformer {
|
|||||||
|
|
||||||
// Minutes short of a day
|
// Minutes short of a day
|
||||||
$extraMinutes = $minutes % $minutesPerDay;
|
$extraMinutes = $minutes % $minutesPerDay;
|
||||||
|
|
||||||
$days = ($minutes - $extraMinutes) / $minutesPerDay;
|
$days = ($minutes - $extraMinutes) / $minutesPerDay;
|
||||||
|
|
||||||
// Minutes short of an hour
|
// Minutes short of an hour
|
||||||
$remMinutes = $extraMinutes % 60;
|
$remMinutes = $extraMinutes % 60;
|
||||||
|
|
||||||
$hours = ($extraMinutes - $remMinutes) / 60;
|
$hours = ($extraMinutes - $remMinutes) / 60;
|
||||||
|
|
||||||
$output = "{$days} days, {$hours} hours, and {$remMinutes} minutes.";
|
$output = "{$days} days, {$hours} hours, {$remMinutes} minutes, and {$remSeconds} seconds.";
|
||||||
|
|
||||||
if ($years > 0)
|
if ($years > 0)
|
||||||
{
|
{
|
||||||
|
@ -19,7 +19,7 @@ namespace Aviat\AnimeClient\API;
|
|||||||
use function Amp\call;
|
use function Amp\call;
|
||||||
use function Amp\Promise\{all, wait};
|
use function Amp\Promise\{all, wait};
|
||||||
|
|
||||||
use Amp\Artax\DefaultClient;
|
use Amp\Artax\{Client, DefaultClient};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to simplify making and validating simultaneous requests
|
* Class to simplify making and validating simultaneous requests
|
||||||
@ -73,6 +73,10 @@ final class ParallelAPIRequest {
|
|||||||
public function makeRequests(): array
|
public function makeRequests(): array
|
||||||
{
|
{
|
||||||
$client = new DefaultClient();
|
$client = new DefaultClient();
|
||||||
|
|
||||||
|
// Timeouts suck
|
||||||
|
$client->setOption(Client::OP_TRANSFER_TIMEOUT, 0);
|
||||||
|
|
||||||
$promises = [];
|
$promises = [];
|
||||||
|
|
||||||
foreach ($this->requests as $key => $url)
|
foreach ($this->requests as $key => $url)
|
||||||
@ -95,6 +99,10 @@ final class ParallelAPIRequest {
|
|||||||
public function getResponses(): array
|
public function getResponses(): array
|
||||||
{
|
{
|
||||||
$client = new DefaultClient();
|
$client = new DefaultClient();
|
||||||
|
|
||||||
|
// Timeouts suck
|
||||||
|
$client->setOption(Client::OP_TRANSFER_TIMEOUT, 0);
|
||||||
|
|
||||||
$promises = [];
|
$promises = [];
|
||||||
|
|
||||||
foreach ($this->requests as $key => $url)
|
foreach ($this->requests as $key => $url)
|
||||||
|
@ -18,8 +18,7 @@ namespace Aviat\AnimeClient;
|
|||||||
|
|
||||||
use function Amp\Promise\wait;
|
use function Amp\Promise\wait;
|
||||||
|
|
||||||
use Amp\Artax\DefaultClient;
|
use Amp\Artax\{Client, DefaultClient, Response};
|
||||||
use Amp\Artax\Response;
|
|
||||||
|
|
||||||
use Aviat\Ion\ConfigInterface;
|
use Aviat\Ion\ConfigInterface;
|
||||||
use Yosymfony\Toml\{Toml, TomlBuilder};
|
use Yosymfony\Toml\{Toml, TomlBuilder};
|
||||||
@ -217,7 +216,9 @@ function checkFolderPermissions(ConfigInterface $config): array
|
|||||||
*/
|
*/
|
||||||
function getResponse ($request): Response
|
function getResponse ($request): Response
|
||||||
{
|
{
|
||||||
return wait((new DefaultClient)->request($request));
|
$client = new DefaultClient;
|
||||||
|
$client->setOption(Client::OP_TRANSFER_TIMEOUT, 0);
|
||||||
|
return wait($client->request($request));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user