DigitalOceanPHP / Client

DigitalOcean API v2 client for PHP
MIT License
709 stars 205 forks source link

Ability to Add per_page and Other Parameters to API Functions #334

Closed delirehberi closed 4 weeks ago

delirehberi commented 2 months ago

Issue:

Currently, there is no built-in way to add per_page or other parameters to some functions within the library. This limitation might be problematic for users who need finer control over their API requests.

Temporary Workaround:

As a temporary solution, you can create a new API class that extends the abstract API class. In this new class, you can define the functions with the desired parameters. After that, you can instantiate this new class with your client and use it as needed.

Request:

It would be beneficial to add support for parameters like per_page in the official API functions in a future release of the library.

//usage
        $dropletS = new Droplet($this->client);//$this->client->droplet();

        $droplets = $dropletS->getAll("staging",['per_page'=>200]);
<?php

namespace App\DigitalOceanPHP\Api ;

use DigitalOceanV2\Api\AbstractApi;

use DigitalOceanV2\Entity\Droplet as DropletEntity;

class Droplet extends AbstractApi{

    /**

     * @param string|null $tag

     *

     * @throws ExceptionInterface

     *

     * @return DropletEntity[]

     */

    public function getAll(?string $tag = null,array $params=[])

    {

      if($tag){

        $params['tag_name'] = $tag;

      }

      $droplets = $this->get('droplets', $params);

      return \array_map(function ($droplet) {

        return new DropletEntity($droplet);

      }, $droplets->droplets);

    }

}
GrahamCampbell commented 4 weeks ago

The expected usage is to use the result pager class. Please see the example in the readme: https://github.com/DigitalOceanPHP/Client?tab=readme-ov-file#examples.