Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
delirehberi opened this issue Aug 15, 2024 · 0 comments
Open

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

delirehberi opened this issue Aug 15, 2024 · 0 comments

Comments

@delirehberi
Copy link

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);

    }

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant