Fixes for 4.1 #14

Merged
timw4mail merged 16 commits from develop into master 2018-12-13 14:51:01 -05:00
2 changed files with 22 additions and 12 deletions
Showing only changes of commit 4d26acea5b - Show all commits

View File

@ -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 = [];

View File

@ -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));
}