|
@@ -101,12 +101,15 @@ abstract class BaseApiRepository implements LoggerAwareInterface
|
|
|
* returns the records as an array (members)
|
|
* returns the records as an array (members)
|
|
|
*
|
|
*
|
|
|
* @param array $params
|
|
* @param array $params
|
|
|
|
|
+ * @param string|null $forceUri
|
|
|
* @return ApiPagedCollection
|
|
* @return ApiPagedCollection
|
|
|
* @throws ApiRequestException
|
|
* @throws ApiRequestException
|
|
|
*/
|
|
*/
|
|
|
- protected function getApiRecords($params = []): ApiPagedCollection
|
|
|
|
|
|
|
+ protected function getApiRecords(array $params = [], ?string $forceUri = null): ApiPagedCollection
|
|
|
{
|
|
{
|
|
|
- $body = $this->getJsonDecoded($this->getApiUri(), $params);
|
|
|
|
|
|
|
+ $uri = $forceUri ?? $this->getApiUri();
|
|
|
|
|
+
|
|
|
|
|
+ $body = $this->getJsonDecoded($uri, $params);
|
|
|
|
|
|
|
|
$page = (int)($params['page'] ?? 1);
|
|
$page = (int)($params['page'] ?? 1);
|
|
|
|
|
|
|
@@ -133,24 +136,25 @@ abstract class BaseApiRepository implements LoggerAwareInterface
|
|
|
/**
|
|
/**
|
|
|
* -- Needs to be reimplemented in subclasses --
|
|
* -- Needs to be reimplemented in subclasses --
|
|
|
* Convert response's members record to an actual Domain's object
|
|
* Convert response's members record to an actual Domain's object
|
|
|
- * @param array $member
|
|
|
|
|
|
|
+ * @param array $record
|
|
|
* @return object
|
|
* @return object
|
|
|
*/
|
|
*/
|
|
|
- abstract protected function memberToObject(array $member);
|
|
|
|
|
|
|
+ abstract protected function memberToObject(array $record);
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Send a request to the API and
|
|
* Send a request to the API and
|
|
|
* returns the first record (member)
|
|
* returns the first record (member)
|
|
|
*
|
|
*
|
|
|
* @param array $params
|
|
* @param array $params
|
|
|
|
|
+ * @param string|null $forceUri
|
|
|
* @return object
|
|
* @return object
|
|
|
* @throws ApiRequestException
|
|
* @throws ApiRequestException
|
|
|
*/
|
|
*/
|
|
|
- protected function getApiFirstRecord($params = []): object
|
|
|
|
|
|
|
+ protected function getApiFirstRecord($params = [], ?string $forceUri = null)
|
|
|
{
|
|
{
|
|
|
$params['page'] = '1';
|
|
$params['page'] = '1';
|
|
|
$params['totalItems'] = '1';
|
|
$params['totalItems'] = '1';
|
|
|
- $collection = $this->getApiRecords($params);
|
|
|
|
|
|
|
+ $collection = $this->getApiRecords($params, $forceUri);
|
|
|
return $collection->getMembers()[0];
|
|
return $collection->getMembers()[0];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -163,7 +167,7 @@ abstract class BaseApiRepository implements LoggerAwareInterface
|
|
|
* @return array
|
|
* @return array
|
|
|
* @throws ApiRequestException
|
|
* @throws ApiRequestException
|
|
|
*/
|
|
*/
|
|
|
- protected function getJsonDecoded(string $uri, $params = [])
|
|
|
|
|
|
|
+ protected function getJsonDecoded(string $uri, $params = []): array
|
|
|
{
|
|
{
|
|
|
return json_decode($this->getBody($uri, $params),true);
|
|
return json_decode($this->getBody($uri, $params),true);
|
|
|
}
|
|
}
|
|
@@ -191,7 +195,7 @@ abstract class BaseApiRepository implements LoggerAwareInterface
|
|
|
* @return ResponseInterface
|
|
* @return ResponseInterface
|
|
|
* @throws ApiRequestException
|
|
* @throws ApiRequestException
|
|
|
*/
|
|
*/
|
|
|
- protected function getResponse(string $uri, $params = [])
|
|
|
|
|
|
|
+ protected function getResponse(string $uri, $params = []): ResponseInterface
|
|
|
{
|
|
{
|
|
|
$uri = $uri . '?_format=json';
|
|
$uri = $uri . '?_format=json';
|
|
|
if(!isset($params['itemsPerPage'])) {
|
|
if(!isset($params['itemsPerPage'])) {
|
|
@@ -201,7 +205,7 @@ abstract class BaseApiRepository implements LoggerAwareInterface
|
|
|
$uri = $uri . '&' . http_build_query($params);
|
|
$uri = $uri . '&' . http_build_query($params);
|
|
|
}
|
|
}
|
|
|
try {
|
|
try {
|
|
|
- if ($this->context->isDevelopment() || $this->context->isTesting()) {
|
|
|
|
|
|
|
+ if ($this->context->isDevelopment()) {
|
|
|
$this->logger->info('API Call: ' . $uri);
|
|
$this->logger->info('API Call: ' . $uri);
|
|
|
}
|
|
}
|
|
|
return $this->client->request(static::HTTP_METHOD, $uri);
|
|
return $this->client->request(static::HTTP_METHOD, $uri);
|