Skip to content
Snippets Groups Projects
Commit 912a6c0f authored by Grzegorz Rola's avatar Grzegorz Rola
Browse files

Added timeout to options.

parent a34f5f6d
No related branches found
No related tags found
No related merge requests found
## [1.1.0] - 2019-05-30
### Added
- Timeout in api client options interface
......@@ -33,5 +33,4 @@ interface ApiClientOptions extends HttpClientOptions, SerializerOptions
* @return string
*/
public function getApiClientClass();
}
\ No newline at end of file
<?php
namespace WPDesk\ApiClient\Client;
interface ApiClientOptionsTimeout extends ApiClientOptions
{
/**
* @return int
*/
public function getTimeout();
}
\ No newline at end of file
......@@ -24,7 +24,8 @@ class ClientFactory
$serializerFactory->createSerializer($options),
$options->getLogger(),
$options->getApiUrl(),
$options->getDefaultRequestHeaders()
$options->getDefaultRequestHeaders(),
($options instanceof ApiClientOptionsTimeout)? $options->getTimeout(): null
);
if ($options->isCachedClient()) {
......
......@@ -16,8 +16,6 @@ class ClientImplementation implements Client, LoggerAwareInterface
{
const CLIENT_VERSION = '1.6.5';
const DEFAULT_TIMEOUT = 10;
const LIBRARY_LOGIN_CONTEXT = 'wp-api-client';
/** @var HttpClient */
......@@ -35,6 +33,9 @@ class ClientImplementation implements Client, LoggerAwareInterface
/** @var array */
private $defaultRequestHeaders;
/** @var int */
private $timeout;
/**
* Client constructor.
* @param HttpClient $client
......@@ -42,19 +43,22 @@ class ClientImplementation implements Client, LoggerAwareInterface
* @param LoggerInterface $logger
* @param string $apiUri
* @param array $defaultRequestHeaders
* @param int $timeout
*/
public function __construct(
HttpClient $client,
Serializer $serializer,
LoggerInterface $logger,
$apiUri,
array $defaultRequestHeaders
array $defaultRequestHeaders,
$timeout = 10
) {
$this->client = $client;
$this->serializer = $serializer;
$this->logger = $logger;
$this->apiUrl = $apiUri;
$this->client = $client;
$this->serializer = $serializer;
$this->logger = $logger;
$this->apiUrl = $apiUri;
$this->defaultRequestHeaders = $defaultRequestHeaders;
$this->timeout = $timeout;
}
/**
......@@ -73,7 +77,8 @@ class ClientImplementation implements Client, LoggerAwareInterface
$fullUrl = $this->prepareFullUrl($request),
$method = $request->getMethod(),
$body = $this->prepareRequestBody($request),
$headers = $this->prepareRequestHeaders($request), self::DEFAULT_TIMEOUT
$headers = $this->prepareRequestHeaders($request),
$this->timeout
);
$this->logger->debug(
......
......@@ -43,6 +43,10 @@ class TestClientFactory extends \PHPUnit\Framework\TestCase
->withAnyArgs()
->andReturn($isCachedClient);
$options->shouldReceive('getTimeout')
->withAnyArgs()
->andReturn(30);
return $options;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment