Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support to an optional timeout on the api request #7

Open
wants to merge 1 commit into
base: 1.2-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/Command/CommandAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ abstract class CommandAbstract extends DataObject implements CommandInterface
*/
protected $optionalConfig = [];

/**
* @var array
*/
protected $requestOptions = [];

/**
* @var \Frenet\Framework\Object\FactoryInterface
*/
Expand Down Expand Up @@ -106,6 +111,24 @@ public function setOptionalConfig(array $optionalConfig = [])
return $this;
}

/**
* {@inheritdoc}
*/
public function setRequestOptions(array $requestOptions = [])
{
$this->requestOptions = $requestOptions;

return $this;
}

/**
* {@inheritdoc}
*/
public function getRequestOptions()
{
return $this->requestOptions;
}

/**
* @return array
*/
Expand All @@ -128,7 +151,12 @@ public function toJson()
public function execute()
{
/** @var \Frenet\Framework\Http\Response\ResponseInterface $response */
$response = $this->connection->request($this->getRequestMethod(), $this->getUrlPath(), $this->toArray());
$response = $this->connection->request(
$this->getRequestMethod(),
$this->getUrlPath(),
$this->toArray(),
$this->getRequestOptions()
);

/** @var \Frenet\ObjectType\EntityInterface $type */
$type = $this->typeFactory->create(['data' => (array) $response->getBody()]);
Expand Down
11 changes: 11 additions & 0 deletions src/Command/CommandInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ public function getRequestMethod();
*/
public function setOptionalConfig(array $optionalConfig = []);

/**
* @param array $requestOptions
* @return $this
*/
public function setRequestOptions(array $requestOptions = []);

/**
* @return array
*/
public function getRequestOptions();

/**
* @return array
*/
Expand Down
4 changes: 4 additions & 0 deletions src/Service/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ public function request($method, $resourcePath, array $data = [], array $config
$bodyType => $data
];

if (isset($config['timeout'])) {
$options['timeout'] = $config['timeout'];
}

return $this->makeRequest($method, $uri, $options);
}

Expand Down