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 ...@@ -33,5 +33,4 @@ interface ApiClientOptions extends HttpClientOptions, SerializerOptions
* @return string * @return string
*/ */
public function getApiClientClass(); 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 ...@@ -24,7 +24,8 @@ class ClientFactory
$serializerFactory->createSerializer($options), $serializerFactory->createSerializer($options),
$options->getLogger(), $options->getLogger(),
$options->getApiUrl(), $options->getApiUrl(),
$options->getDefaultRequestHeaders() $options->getDefaultRequestHeaders(),
($options instanceof ApiClientOptionsTimeout)? $options->getTimeout(): null
); );
if ($options->isCachedClient()) { if ($options->isCachedClient()) {
......
...@@ -16,8 +16,6 @@ class ClientImplementation implements Client, LoggerAwareInterface ...@@ -16,8 +16,6 @@ class ClientImplementation implements Client, LoggerAwareInterface
{ {
const CLIENT_VERSION = '1.6.5'; const CLIENT_VERSION = '1.6.5';
const DEFAULT_TIMEOUT = 10;
const LIBRARY_LOGIN_CONTEXT = 'wp-api-client'; const LIBRARY_LOGIN_CONTEXT = 'wp-api-client';
/** @var HttpClient */ /** @var HttpClient */
...@@ -35,6 +33,9 @@ class ClientImplementation implements Client, LoggerAwareInterface ...@@ -35,6 +33,9 @@ class ClientImplementation implements Client, LoggerAwareInterface
/** @var array */ /** @var array */
private $defaultRequestHeaders; private $defaultRequestHeaders;
/** @var int */
private $timeout;
/** /**
* Client constructor. * Client constructor.
* @param HttpClient $client * @param HttpClient $client
...@@ -42,19 +43,22 @@ class ClientImplementation implements Client, LoggerAwareInterface ...@@ -42,19 +43,22 @@ class ClientImplementation implements Client, LoggerAwareInterface
* @param LoggerInterface $logger * @param LoggerInterface $logger
* @param string $apiUri * @param string $apiUri
* @param array $defaultRequestHeaders * @param array $defaultRequestHeaders
* @param int $timeout
*/ */
public function __construct( public function __construct(
HttpClient $client, HttpClient $client,
Serializer $serializer, Serializer $serializer,
LoggerInterface $logger, LoggerInterface $logger,
$apiUri, $apiUri,
array $defaultRequestHeaders array $defaultRequestHeaders,
$timeout = 10
) { ) {
$this->client = $client; $this->client = $client;
$this->serializer = $serializer; $this->serializer = $serializer;
$this->logger = $logger; $this->logger = $logger;
$this->apiUrl = $apiUri; $this->apiUrl = $apiUri;
$this->defaultRequestHeaders = $defaultRequestHeaders; $this->defaultRequestHeaders = $defaultRequestHeaders;
$this->timeout = $timeout;
} }
/** /**
...@@ -73,7 +77,8 @@ class ClientImplementation implements Client, LoggerAwareInterface ...@@ -73,7 +77,8 @@ class ClientImplementation implements Client, LoggerAwareInterface
$fullUrl = $this->prepareFullUrl($request), $fullUrl = $this->prepareFullUrl($request),
$method = $request->getMethod(), $method = $request->getMethod(),
$body = $this->prepareRequestBody($request), $body = $this->prepareRequestBody($request),
$headers = $this->prepareRequestHeaders($request), self::DEFAULT_TIMEOUT $headers = $this->prepareRequestHeaders($request),
$this->timeout
); );
$this->logger->debug( $this->logger->debug(
......
...@@ -43,6 +43,10 @@ class TestClientFactory extends \PHPUnit\Framework\TestCase ...@@ -43,6 +43,10 @@ class TestClientFactory extends \PHPUnit\Framework\TestCase
->withAnyArgs() ->withAnyArgs()
->andReturn($isCachedClient); ->andReturn($isCachedClient);
$options->shouldReceive('getTimeout')
->withAnyArgs()
->andReturn(30);
return $options; 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