Use the same API client instance across the codebase
This commit is contained in:
parent
a38c9712e6
commit
4d26acea5b
@ -18,8 +18,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 function Aviat\AnimeClient\getApiClient;
|
||||||
use Amp\Artax\{Client, DefaultClient};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to simplify making and validating simultaneous requests
|
* Class to simplify making and validating simultaneous requests
|
||||||
@ -72,10 +71,7 @@ final class ParallelAPIRequest {
|
|||||||
*/
|
*/
|
||||||
public function makeRequests(): array
|
public function makeRequests(): array
|
||||||
{
|
{
|
||||||
$client = new DefaultClient();
|
$client = getApiClient();
|
||||||
|
|
||||||
// Timeouts suck
|
|
||||||
$client->setOption(Client::OP_TRANSFER_TIMEOUT, 0);
|
|
||||||
|
|
||||||
$promises = [];
|
$promises = [];
|
||||||
|
|
||||||
@ -98,10 +94,7 @@ final class ParallelAPIRequest {
|
|||||||
*/
|
*/
|
||||||
public function getResponses(): array
|
public function getResponses(): array
|
||||||
{
|
{
|
||||||
$client = new DefaultClient();
|
$client = getApiClient();
|
||||||
|
|
||||||
// Timeouts suck
|
|
||||||
$client->setOption(Client::OP_TRANSFER_TIMEOUT, 0);
|
|
||||||
|
|
||||||
$promises = [];
|
$promises = [];
|
||||||
|
|
||||||
|
@ -207,6 +207,24 @@ function checkFolderPermissions(ConfigInterface $config): array
|
|||||||
return $errors;
|
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
|
* Simplify making a request with Artax
|
||||||
*
|
*
|
||||||
@ -216,8 +234,7 @@ function checkFolderPermissions(ConfigInterface $config): array
|
|||||||
*/
|
*/
|
||||||
function getResponse ($request): Response
|
function getResponse ($request): Response
|
||||||
{
|
{
|
||||||
$client = new DefaultClient;
|
$client = getApiClient();
|
||||||
$client->setOption(Client::OP_TRANSFER_TIMEOUT, 0);
|
|
||||||
return wait($client->request($request));
|
return wait($client->request($request));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user