krystal/katapult

v3.0.2 2024-02-08 11:34 UTC

This package is auto-updated.

Last update: 2024-05-08 12:06:56 UTC


README

Katapult logo

Latest Version on Packagist Total Downloads

A PHP library for integrating with Katapult

Version constraints

  • v1.x supports PHP 5.6
  • v2.x supports PHP 7.4
  • v3.x supports PHP 8.1

Installation

You can install the package via Composer:

composer require krystal/katapult

Usage

It will use PSR HTTP discovery to locate an imlpementation of the PSR ClientInterface.

If you need control over this, you can call setHttpClient in ClientFactory.

The usage sample below emits the IPv4 and IPv6 addresses for each VM in your Organization.

use Krystal\Katapult\KatapultAPI\ClientFactory;

$katapult = (new ClientFactory('your-katapult-api-token'))->create();

$virtualMachines = $katapult->getOrganizationVirtualMachines([
    'organization[id]' => 'your-katapult-org-id',
])->getVirtualMachines();

foreach ($virtualMachines as $virtualMachine) {
    echo $virtualMachine->getHostname() . PHP_EOL;
    foreach ($virtualMachine->getIpAddresses() as $ipAddress) {
        $prefix = filter_var($ipAddress->getAddress(), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ? 'ipv4' : 'ipv6';
        echo '  ' . $prefix . ': ' . $ipAddress->getAddress() . PHP_EOL;
    }
}

Output

example
  ipv4: 93.184.216.34
  ipv6: 2606:2800:220:1:248:1893:25c8:1946