2017 © Pedro Peláez
 

library client

A client for HaveAPI based APIs

image

haveapi/client

A client for HaveAPI based APIs

  • Tuesday, September 12, 2017
  • by aither
  • Repository
  • 6 Watchers
  • 0 Stars
  • 25 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 15 Versions
  • 4 % Grown

The README.md

haveapi-client-php

haveapi-client-php is a PHP client for HaveAPI based APIs., (*1)

Requirements

Installation

haveapi-client-php can be installed with composer, add haveapi/client to your composer.json:, (*2)

{
    "require": {
        "haveapi/client": "*"
    }
}

You can also clone this repository and use a PSR-4 compatible autoloader, or include bootstrap.php, which loads all necessary classes. When using the repository, you have to install Httpful yourself., (*3)

Usage

First check out the API documentation, see how it works and what resources/actions are available., (*4)

Create a client instance:, (*5)

$api = new \HaveAPI\Client("http://your.api.tld");

Authenticate with HTTP basic:, (*6)

$api->authenticate('basic', ['user' => 'yourname', 'password' => 'password']);

Authenticate with token:, (*7)

$api->authenticate('token', ['user' => 'yourname', 'password' => 'password']);

When using the token authentication, it is usually necessary to save the token for later use:, (*8)

$token = $api->getAuthenticationProvider()->getToken();

Next time, authenticate with the previously received token:, (*9)

$api->authenticate('token', ['token' => $token]);

Access resources and actions as array indexes

$api['vps']['index']->call();
$api['vps']['show']->call(101);

or, (*10)

$api['vps.index']->call();
$api['vps.show']->call(101);

Access resources and actions as properties/methods

$api->vps->list();

Arguments can be supplied to resources and/or to the action., (*11)

$api->vps->find(101);
$api->vps->ip_address->delete(101, 10);

$api->vps(101)->find();
$api->vps(101)->ip_address(10)->delete();
$api->vps(101)->ip_address->delete(10);

Parameters

Parameters are given as an array to action. It is the last argument given to action. Object IDs must be in front of it., (*12)

$api->vps->create([
    'hostname' => 'myhostname',
    'template' => 1
]);

$api->vps->ip_address->create(101, ['version' => 4]);
$api->vps(101)->ip_address->create(['version' => 4]);

Object-like behaviour

Fetch existing resource:, (*13)

$vps = $api->vps->find(101);
echo $vps->id . "<br>";
echo $vps->hostname . "<br>";
$vps->hostname = 'gotcha';
$vps->save();

Create a new instance:, (*14)

$vps = $api->vps->newInstance();
$vps->hostname = 'new vps';
$vps->save();
echo $vps->id . "<br>";

List of resources:, (*15)

$vpses = $api->vps->list();

foreach($vpses as $vps) {
    echo $vps->id ." = ". $vps->hostname ."<br>";
}

Response

If the action does not return object or object list, \HaveAPI\Client\Response class is returned instead., (*16)

$vps = $api->vps->find(101);
$response = $vps->custom_action();

print_r($response->getResponse());

Parameters can be accessed directly as:, (*17)

echo $response['hostname'];

Error handling

If an action fails, exception \HaveAPI\Client\Exception\ActionFailed is thrown. Authentication errors result in exception \HaveAPI\Client\Exception\AuthenticationFailed., (*18)

try {
    $api->vps->create();

} catch(\HaveAPI\Client\Exception\ActionFailed $e) {
    echo $e->getMessage();
    print_r($e->getErrors());
}

When trying to access a resource or an action that does not exist, \HaveAPI\Client\Exception\ObjectNotFound is thrown. Also, invoking an action without all necessary arguments (object IDs) results in \HaveAPI\Client\Exception\UnresolvedArguments exception., (*19)

All exceptions thrown by the client are a subclass of \HaveAPI\Client\Exception\Base., (*20)

Documentation

https://projects.vpsfree.cz/haveapi-client-php/ref/, (*21)

License

haveapi-client-php is released under the MIT license., (*22)

The Versions

12/09 2017

dev-master

9999999-dev https://github.com/vpsfreecz/haveapi-client-php

A client for HaveAPI based APIs

  Sources   Download

MIT

The Requires

 

by Jakub Skokan

12/09 2017

0.10.0

0.10.0.0 https://github.com/vpsfreecz/haveapi-client-php

A client for HaveAPI based APIs

  Sources   Download

MIT

The Requires

 

by Jakub Skokan

22/04 2017

0.9.0

0.9.0.0 https://github.com/vpsfreecz/haveapi-client-php

A client for HaveAPI based APIs

  Sources   Download

MIT

The Requires

 

by Jakub Skokan

10/02 2017

0.8.0

0.8.0.0 https://github.com/vpsfreecz/haveapi-client-php

A client for HaveAPI based APIs

  Sources   Download

MIT

The Requires

 

by Jakub Skokan

26/11 2016

0.7.1

0.7.1.0 https://github.com/vpsfreecz/haveapi-client-php

A client for HaveAPI based APIs

  Sources   Download

MIT

The Requires

 

by Jakub Skokan

24/11 2016

0.7.0

0.7.0.0 https://github.com/vpsfreecz/haveapi-client-php

A client for HaveAPI based APIs

  Sources   Download

MIT

The Requires

 

by Jakub Skokan

18/10 2016

0.6.0

0.6.0.0 https://github.com/vpsfreecz/haveapi-client-php

A client for HaveAPI based APIs

  Sources   Download

MIT

The Requires

 

by Jakub Skokan

03/03 2016

0.5.2

0.5.2.0 https://github.com/vpsfreecz/haveapi-client-php

A client for HaveAPI based APIs

  Sources   Download

MIT

The Requires

 

by Jakub Skokan

26/02 2016

0.5.1

0.5.1.0 https://github.com/vpsfreecz/haveapi-client-php

A client for HaveAPI based APIs

  Sources   Download

MIT

The Requires

 

by Jakub Skokan

09/02 2016

0.5.0

0.5.0.0 https://github.com/vpsfreecz/haveapi-client-php

A client for HaveAPI based APIs

  Sources   Download

MIT

The Requires

 

by Jakub Skokan

24/01 2016

0.4.2

0.4.2.0 https://github.com/vpsfreecz/haveapi-client-php

A client for HaveAPI based APIs

  Sources   Download

MIT

The Requires

 

by Jakub Skokan

24/01 2016

0.4.1

0.4.1.0 https://github.com/vpsfreecz/haveapi-client-php

A client for HaveAPI based APIs

  Sources   Download

MIT

The Requires

 

by Jakub Skokan

20/01 2016

dev-devel

dev-devel https://github.com/vpsfreecz/haveapi-client-php

A client for HaveAPI based APIs

  Sources   Download

MIT

The Requires

 

by Jakub Skokan

20/01 2016

0.4.0

0.4.0.0 https://github.com/vpsfreecz/haveapi-client-php

A client for HaveAPI based APIs

  Sources   Download

MIT

The Requires

 

by Jakub Skokan

24/07 2015

0.3.0

0.3.0.0 https://github.com/vpsfreecz/haveapi-client-php

A client for HaveAPI based APIs

  Sources   Download

MIT

The Requires

 

by Jakub Skokan