diff --git a/src/Client.php b/src/Client.php index 0911c50..354ba6e 100644 --- a/src/Client.php +++ b/src/Client.php @@ -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); @@ -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); @@ -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); @@ -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); @@ -119,6 +123,26 @@ public function findAll($filters = [], $pageSize = 10, $page = 1) ->getContents(), true); } + /** + * @param string $path + * + * @return array + * @throws EntityFetchException + */ + 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); + } + + return json_decode($response->getBody()->getContents(), true); + } + /** * @param bool $patch * @return array @@ -127,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) { diff --git a/src/RelationClient.php b/src/RelationClient.php new file mode 100644 index 0000000..47ccf43 --- /dev/null +++ b/src/RelationClient.php @@ -0,0 +1,31 @@ +