Skip to content

Commit

Permalink
Merge pull request #16 from realifetech/feature/BE-203-canvas---be-im…
Browse files Browse the repository at this point in the history
…plement-audience-fi

BE-203 add connection close header and connection_timeout
  • Loading branch information
tomrutherford-livestyled authored Jan 29, 2021
2 parents 7f8deb0 + d888c4b commit 2727ed3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function create($data)
$response = $this->httpClient->post($this->getPath(), [
'body' => json_encode($data),
'headers' => $this->getHeaders(),
'connect_timeout' => 1
]);
} catch (BadResponseException $e) {
throw new EntityCreationException($e->getMessage(), $e->getCode(), $e);
Expand All @@ -67,6 +68,7 @@ public function update($id, $data)
$response = $this->httpClient->patch($this->getPathWithId($id), [
'body' => json_encode($data),
'headers' => $this->getHeaders(true),
'connect_timeout' => 1
]);
} catch (BadResponseException $e) {
throw new EntityCreationException($e->getMessage(), $e->getCode(), $e);
Expand All @@ -87,7 +89,8 @@ public function find($id, $filters = [])
try {
$response = $this->httpClient->get($this->getPathWithId($id), [
'headers' => $this->getHeaders(),
'query' => $filters
'query' => $filters,
'connect_timeout' => 1
]);
} catch (BadResponseException $e) {
throw new EntityFetchException($e->getMessage(), $e->getCode(), $e);
Expand All @@ -109,7 +112,8 @@ public function findAll($filters = [], $pageSize = 10, $page = 1)
try {
$response = $this->httpClient->get($this->getPath(), [
'headers' => $this->getHeaders(),
'query' => array_merge(compact('pageSize', 'page'), $filters)
'query' => array_merge(compact('pageSize', 'page'), $filters),
'connect_timeout' => 1
]);
} catch (BadResponseException $e) {
throw new EntityFetchException($e->getMessage(), $e->getCode(), $e);
Expand All @@ -130,6 +134,7 @@ public function getByGivenPath(string $path): array
try {
$response = $this->httpClient->get($path, [
'headers' => $this->getHeaders(),
'connect_timeout' => 1
]);
} catch (BadResponseException $e) {
throw new EntityFetchException($e->getMessage(), $e->getCode(), $e);
Expand All @@ -146,7 +151,8 @@ protected function getHeaders($patch = false): array
{
$headers = [
'x-api-key' => $this->credentials['api_key'],
'content-type' => 'application/json'
'content-type' => 'application/json',
'connection' => 'close'
];

if ($patch) {
Expand Down

0 comments on commit 2727ed3

Please sign in to comment.