PHP code example of chrisjohnleah / velocity-fleet-api
1. Go to this page and download the library: Download chrisjohnleah/velocity-fleet-api 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/ */
chrisjohnleah / velocity-fleet-api example snippets
use ChrisJohnLeah\VelocityFleet\VelocityFleet;
$velocity = VelocityFleet::withToken(getenv('VELOCITY_API_TOKEN'));
// Every customer linked to your user — typed.
foreach ($velocity->customers()->list() as $customer) {
printf("%s (#%s) — %s\n", $customer->name, $customer->number, $customer->product);
}
use ChrisJohnLeah\VelocityFleet\VelocityFleet;
$velocity = VelocityFleet::withRefreshToken(
refreshToken: getenv('VELOCITY_REFRESH_TOKEN'),
clientId: getenv('VELOCITY_CLIENT_ID'), // if your OAuth client
$positions = $velocity->devicePositions()->forCustomer($customer->id);
echo "{$positions->deviceCount} devices\n";
foreach ($positions->devices as $device) {
printf(
"%s @ %.5f,%.5f — %d %s, ignition %s, seen %s\n",
$device->vehicleRegistration,
$device->lat ?? 0.0,
$device->lon ?? 0.0,
$device->speed ?? 0,
$device->speedMeasureText ?? '',
$device->ignitionOn() ? 'on' : 'off',
$device->occurredAt()?->format('H:i') ?? 'n/a',
);
}
// The same devices are also grouped:
foreach ($positions->deviceGroups as $group) {
echo "{$group->name}: ".count($group->devices)." devices\n";
}
use ChrisJohnLeah\VelocityFleet\Auth\StoredToken;
use ChrisJohnLeah\VelocityFleet\Contracts\TokenStore;
use ChrisJohnLeah\VelocityFleet\VelocityFleet;
use ChrisJohnLeah\VelocityFleet\VelocityFleetConnector;
final class MyTokenStore implements TokenStore
{
public function get(): ?StoredToken { /* load access/refresh/expiresAt */ }
public function put(StoredToken $token): void { /* overwrite */ }
public function forget(): void { /* delete */ }
}
$velocity = new VelocityFleet(
new VelocityFleetConnector(clientId: '…', clientSecret: '…'),
new MyTokenStore(),
);
use ChrisJohnLeah\VelocityFleet\Exceptions\ApiException;
try {
$velocity->devicePositions()->forCustomer($id);
} catch (ApiException $e) {
report("Velocity API {$e->status}: {$e->getMessage()}");
}
use ChrisJohnLeah\VelocityFleet\Requests\Customers\GetCustomers;
$customers = $velocity->send(new GetCustomers())->dto();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.