Skip to content

Commit

Permalink
feat: handle populate filters
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepimpao committed May 27, 2024
1 parent f6fba6d commit 51bd5b6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 312 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"require": {
"php": ">=8.1",
"myclabs/deep-copy": "^1.11",
"programmatordev/php-api-sdk": "^0.2.0",
"programmatordev/php-api-sdk": "^0.3.0",
"programmatordev/yet-another-php-validator": "^1.1"
},
"require-dev": {
Expand Down
232 changes: 0 additions & 232 deletions src/Endpoint/AbstractEndpoint.php

This file was deleted.

25 changes: 23 additions & 2 deletions src/SportMonksFootball.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Http\Message\Authentication\QueryParam;
use ProgrammatorDev\Api\Api;
use ProgrammatorDev\Api\Event\PostRequestEvent;
use ProgrammatorDev\Api\Event\PreRequestEvent;
use ProgrammatorDev\Api\Event\ResponseContentsEvent;
use ProgrammatorDev\SportMonksFootball\Entity\Response\Error;
use ProgrammatorDev\SportMonksFootball\Exception\BadRequestException;
Expand Down Expand Up @@ -250,7 +251,27 @@ private function configureApi(): void
$this->addQueryDefault('timezone', $this->options['timezone']);
$this->addQueryDefault('locale', $this->options['language']);

$this->addPostRequestHandler(function(PostRequestEvent $event) {
$this->addPreRequestListener(function (PreRequestEvent $event) {
$request = $event->getRequest();
$uri = $request->getUri();

\parse_str($uri->getQuery(), $query);

// removes "per_page" query parameter if "populate" filter exists,
// otherwise it would be ignored
if (!empty($query['filters']) && $query['filters'] === 'populate') {
if (!empty($query['per_page'])) {
unset($query['per_page']);

$uri = $uri->withQuery(\http_build_query($query));
$request = $request->withUri($uri);

$event->setRequest($request);
}
}
});

$this->addPostRequestListener(function(PostRequestEvent $event) {
$response = $event->getResponse();
$statusCode = $response->getStatusCode();

Expand Down Expand Up @@ -307,7 +328,7 @@ private function configureApi(): void
}
});

$this->addResponseContentsHandler(function(ResponseContentsEvent $event) {
$this->addResponseContentsListener(function(ResponseContentsEvent $event) {
// decode json string response into an array
$contents = $event->getContents();
$contents = \json_decode($contents, true);
Expand Down
77 changes: 0 additions & 77 deletions tests/VenueEndpointTest_.php

This file was deleted.

0 comments on commit 51bd5b6

Please # to comment.