Skip to content
This repository has been archived by the owner on Feb 25, 2022. It is now read-only.

Required predefined body parametres #38

Open
index0h opened this issue Jul 16, 2014 · 1 comment
Open

Required predefined body parametres #38

index0h opened this issue Jul 16, 2014 · 1 comment
Milestone

Comments

@index0h
Copy link
Contributor

index0h commented Jul 16, 2014

Hi.
In case when api has many simple methods, which differ only one parameter, it could be useful to create multiple methods with that predefined parameter.

For example: DigitalOcean V2 API:
Droplet has many actions like: reboot, power on, power off. They differ only in parameter "type": "reboot", "power_on", "power_off".

Now I could to create method run_action($droplet_id, $type), but it's more easy to use simple methods like: reboot($id), power_on($id), power_off($id)

Best implementation (imho) could be something like this:

public function reboot($id, array $options = array())
{
    $body = (isset($options['body']) ? $options['body'] : array());
    $body['type'] = 'reboot';

    $response = $this->client->post('/droplets/'.rawurlencode($id).'/actions', $body, $options);

    return $response;
}

Regards

@pksunkara
Copy link
Owner

Thank you for the suggestion. I will look into it this weekend.

@pksunkara pksunkara added this to the 1.0.0 milestone Aug 21, 2014
@pksunkara pksunkara modified the milestones: 1.1.0, 1.0.0 Feb 20, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants