Skip to content

Commit

Permalink
chore(docs): provide usage example
Browse files Browse the repository at this point in the history
  • Loading branch information
bencromwell committed Jan 19, 2024
1 parent b861b71 commit d2751bd
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,37 @@ You can install the package via Composer:
```bash
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.

```php
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
```

0 comments on commit d2751bd

Please sign in to comment.