Appearance
Usage
Getting a client
php
use Anikeen\Console\Facades\AnikeenConsole;
$console = AnikeenConsole::forUser($user); // the user's stored token, refreshed when needed
$console = AnikeenConsole::withToken($token); // a fixed token, e.g. a personal access token in a scriptThe shared AnikeenConsole instance keeps no token: forUser() and withToken() return copies.
Tokens
forUser($user)reads the tokensanikeen/idstores on the user.- A token that expires within a minute is refreshed through
AnikeenId::refreshToken()before the request. A401refreshes it and sends the request once more (with the same headers, so the same Idempotency-Key). - The new pair is saved on the user (only those two columns).
- Refreshes are locked per user through the cache, and a pair another process stored meanwhile is used instead of refreshing again (refresh tokens are single-use).
- When the refresh fails, an
AuthenticationExceptionasks you to send the user through the Anikeen ID login again. A user without any token throwsanikeen/id'sRequestRequiresAuthenticationException. withToken($token)never refreshes.
App team
php
$team = $console->appTeam(); // GET /app-team: {id, name, app, created_at}, created on the first callSee The app team.
Catalog
php
$catalog = $console->catalog($team); // a Team, its id, or null for list prices
$catalog->families(); // the families in the catalog
$catalog->family('container'); // one family (stdClass) or null
$plans = $catalog->products('container'); // its products
$locations = $catalog->options('container')->locations;
$catalog->vatRate(); // e.g. 19.0Filters
php
// only GPU plans, NVIDIA, at most 150 € net per month, cheapest first
$gpuPlans = $console->catalog($team, [
'gpu' => true,
'gpu_vendor' => 'nvidia', // nvidia | amd | intel
'max_price' => 150, // on monthly_price: net, the team's price, hourly plans at their monthly cap
'sort' => 'price', // price | -price
])->products('container');All filters are optional and applied by the Console; families left without products are left out. Booleans are sent as true/false, lists comma-separated.
| Filter | |
|---|---|
family | alias or list |
gpu | true / false |
gpu_vendor | nvidia, amd, intel |
gpu_model | substring |
gpu_mode | shared, exclusive |
gpu_min_vram_gb, gpu_min_count | integers |
min_vcores, min_memory_mb, min_disk_gb | integers |
min_price, max_price | on each product's monthly_price: what a month costs at most, net, at the team's price |
sort | price, -price |
A bad value throws ValidationFailedException. Details: Catalog filters.
Lists
Lists return a BaseCollection of resources:
php
$containers = $console->containers()->list();
foreach ($containers as $container) { … }
$containers->count();
$containers->first();
$containers->all();
$containers->total(); // across all pages
$containers->currentPage();
$containers->lastPage();
$containers->hasMorePages();
$next = $containers->nextPage(); // the next page, or null
$prev = $containers->previousPage();
$containers->paginate(); // the raw ResultResources
Resources (Order, Container, Team, Catalog, Product, …) expose the API's fields as properties:
- nested objects are
stdClass, - unknown fields read as
null, toArray()and JSON serialization work,$resource->resultholds the response.
Resources from webhooks have no API client; bind one to act on them:
php
$event->object->withClient(AnikeenConsole::forUser($user))->power('start');Other endpoints
Areas without an SDK wrapper yet (servers, domains, DNS zones, web hosting, load balancers) can be called through the same client - with token refresh and exceptions:
php
$result = $console->call('GET', 'zones', query: ['name' => 'example.com']);
$zones = $result->data;call() throws the matching exception on failure; send() returns the Result also for 4xx/5xx. A Result has status, body, data and paginator, plus success(), message(), errorCode(), retryAfter() and header().