diff --git a/src/Helpers/Api.php b/src/Helpers/Api.php index 363b8e1..dfea682 100644 --- a/src/Helpers/Api.php +++ b/src/Helpers/Api.php @@ -22,6 +22,7 @@ public static function endpoints() : array if ( str_contains($path, '{parentId}') || str_contains($path, 'EntityInformation') || + str_contains($path, 'entityInformation') || str_contains($path, 'Modules') || str_contains($path, 'ThresholdInformation') || str_contains($path, 'Version') || diff --git a/templates/Package/API/Paginator.php.twig b/templates/Package/API/Paginator.php.twig index 36f8a29..1a05bd3 100644 --- a/templates/Package/API/Paginator.php.twig +++ b/templates/Package/API/Paginator.php.twig @@ -20,19 +20,24 @@ class {{ entityName.singular }}Paginator /** @var PageEntity Page data transfer object. */ protected PageEntity $page; + /** @var array Search params for POST /query request */ + protected $postParams; + /** * Sets up the paginator. * * @param HttpClient $client Http client for retrieving pages. * @param Response $response Response from Http client. + * @param array $postParams Search params for POST /query request * * @author Aidan Casey */ - public function __construct(HttpClient $client, $response) + public function __construct(HttpClient $client, $response, $postParams = null) { $this->client = $client; $this->collection = {{ entityName.singular }}Collection::fromResponse($response); $this->page = PageEntity::fromResponse($response); + $this->postParams = $postParams; } /** @@ -70,7 +75,12 @@ class {{ entityName.singular }}Paginator */ public function nextPage(): {{ entityName.singular }}Paginator { - $response = $this->client->getClient()->get($this->page->nextPageUrl); + if(is_null($this->postParams)){ + $response = $this->client->getClient()->get($this->page->nextPageUrl); + }else{ + $response = $this->client->getClient()->post($this->page->nextPageUrl, ['json' => $this->postParams]); + } + return new static($this->client, $response); } @@ -81,7 +91,12 @@ class {{ entityName.singular }}Paginator */ public function prevPage (): {{ entityName.singular }}Paginator { - $response = $this->client->getClient()->get($this->page->prevPageUrl); + if(is_null($this->postParams)){ + $response = $this->client->getClient()->get($this->page->prevPageUrl); + }else{ + $response = $this->client->getClient()->post($this->page->prevPageUrl, ['json' => $this->postParams]); + } + return new static($this->client, $response); } } diff --git a/templates/Package/API/QueryBuilder.php.twig b/templates/Package/API/QueryBuilder.php.twig index 5ef9f17..abeb42e 100644 --- a/templates/Package/API/QueryBuilder.php.twig +++ b/templates/Package/API/QueryBuilder.php.twig @@ -22,6 +22,8 @@ class {{ entityName.singular }}QueryBuilder /** @var int The maximum number of records to be returned. */ protected int $records; + private const GET_LIMIT = 1800; + /** * Sets up the class to perform a query. * @@ -42,9 +44,13 @@ class {{ entityName.singular }}QueryBuilder */ public function count(): int { - $response = $this->client->get("{{ entityName.plural }}/query/count", [ - 'search' => json_encode( $this->toArray() ) - ]); + if (strlen($this->__toString()) >= self::GET_LIMIT) { + $response = $this->client->post("{{ entityName.plural }}/query/count", $this->toArray()); + }else{ + $response = $this->client->get("{{ entityName.plural }}/query/count", [ + 'search' => json_encode( $this->toArray() ) + ]); + } $responseArray = json_decode($response->getBody(), true); @@ -84,9 +90,13 @@ class {{ entityName.singular }}QueryBuilder */ public function get(): {{ entityName.singular }}Collection { - $response = $this->client->get("{{ entityName.plural }}/query", [ - 'search' => json_encode( $this->toArray() ) - ]); + if (strlen($this->__toString()) >= self::GET_LIMIT) { + $response = $this->client->post("{{ entityName.plural }}/query", $this->toArray()); + }else{ + $response = $this->client->get("{{ entityName.plural }}/query", [ + 'search' => json_encode( $this->toArray() ) + ]); + } return {{ entityName.singular }}Collection::fromResponse($response); } @@ -96,11 +106,15 @@ class {{ entityName.singular }}QueryBuilder */ public function paginate(): {{ entityName.singular }}Paginator { - $response = $this->client->get("{{ entityName.plural }}/query", [ - 'search' => json_encode($this->toArray()) - ]); - - return new {{ entityName.singular }}Paginator($this->client, $response); + if (strlen($this->__toString()) >= self::GET_LIMIT) { + $response = $this->client->post("{{ entityName.plural }}/query", $this->toArray()); + return new {{ entityName.singular }}Paginator($this->client, $response, $this->toArray()); + }else{ + $response = $this->client->get("{{ entityName.plural }}/query", [ + 'search' => json_encode( $this->toArray() ) + ]); + return new {{ entityName.singular }}Paginator($this->client, $response); + } } /** diff --git a/templates/Package/API/Service.php.twig b/templates/Package/API/Service.php.twig index a1ad86c..ab1e3f9 100644 --- a/templates/Package/API/Service.php.twig +++ b/templates/Package/API/Service.php.twig @@ -20,7 +20,6 @@ class {{ entityName.singular }}Service { /** @var Client An HTTP client for making requests to the Autotask API. */ protected HttpClient $client; - /** * Instantiates the class. *