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

Merge branch 'feature/timeout' into 'master'

Added timeout to options.

See merge request !3
parents a34f5f6d 912a6c0f
No related branches found
Tags 1.1.0
1 merge request!3Added timeout to options.
Pipeline #5222 passed with stages
in 3 minutes and 46 seconds
## [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