PHP code example of hampel / binarylane-api-laravel
1. Go to this page and download the library: Download hampel/binarylane-api-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
'per_page' => env('BINARYLANE_PER_PAGE'), // 1 to 200; null uses the API's default of 20
'base_uri' => env('BINARYLANE_API_URL'), // null uses BinaryLane's own host
'timeout' => 10,
'connect_timeout' => 5,
use Hampel\BinaryLane\Api\Laravel\Facades\BinaryLane;
$account = BinaryLane::verify(); // does this token work, and is the account usable?
$servers = BinaryLane::servers()->list(); // the first page - 20 unless configured otherwise
$server = BinaryLane::servers()->get(1234);
use Hampel\BinaryLane\Api\Laravel\BinaryLaneManager;
public function __construct(private readonly BinaryLaneManager $binarylane) {}
$this->binarylane->client('reseller')->servers()->list();
use Hampel\BinaryLane\Api\Laravel\Jobs\AwaitAction;
$action = BinaryLane::serverActions()->powerOn(1234);
if ($action !== null) {
dispatch(new AwaitAction($action));
}
new AwaitAction($action, account: 'reseller', timeout: 3600, interval: 10);
use Hampel\BinaryLane\Api\Laravel\Events\ActionBlocked;
use Hampel\BinaryLane\Api\Laravel\Events\ActionCompleted;
use Hampel\BinaryLane\Api\Laravel\Events\ActionFailed;
use Illuminate\Support\Facades\Event;
Event::listen(function (ActionCompleted $event) {
// $event->action->resourceId is the server; $event->action->type is what was done to it
});
Event::listen(function (ActionFailed $event) {
// $event->action->failureReason() when BinaryLane gave one - often it did not
});
Event::listen(function (ActionBlocked $event) {
// answer with actions()->proceed(), or pay invoice $event->action->blockingInvoiceId,
// then dispatch a new AwaitAction if the outcome still matters
});
use Hampel\BinaryLane\Api\Exception\NotAuthenticatedException;
use Hampel\BinaryLane\Api\Exception\NotFoundException;
use Hampel\BinaryLane\Api\Exception\ValidationException;
try {
$server = BinaryLane::servers()->get($id);
} catch (NotFoundException $e) {
// no such server on this account
} catch (NotAuthenticatedException $e) {
// the token is no good. A configuration error, not an empty result.
}