PHP code example of cruide / starline-openapi-laravel

1. Go to this page and download the library: Download cruide/starline-openapi-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/ */

    

cruide / starline-openapi-laravel example snippets


use Cruide\StarlineLaravel\Facades\Starline;

// Profile + devices (typed DTOs)
$info = Starline::user()->info();   // UserInfo
$userId = Starline::user()->id();   // int

$devices = Starline::user()->devices(); // Device[]
foreach ($devices as $device) {
    echo $device->alias();   // "Car A"
    echo $device->isOnline() ? 'online' : 'offline';

    // Live state
    $state = Starline::devices()->state($device->id()); // DeviceState
    echo $state->isArmed() ? 'armed' : 'disarmed';
    echo $state->interiorTemperature();  // °C
    echo $state->batteryVoltage();       // V
    echo $state->latitude(), $state->longitude(); // GPS
    echo $state->mileage();              // km
}

// Commands
Starline::devices()->arm($deviceId);
Starline::devices()->disarm($deviceId);
Starline::devices()->startEngine($deviceId);
Starline::devices()->stopEngine($deviceId);
Starline::devices()->setParam($deviceId, ['webasto' => ['start' => true]]);

// Events & tracks
$events = Starline::devices()->events($deviceId, $periodStart, $periodEnd);
$track  = Starline::devices()->ways($deviceId, $begin, $end);
$types  = Starline::devices()->eventTypes();

// Any endpoint from the docs
Starline::get('/json/v3/device/'.$deviceId.'/data');
Starline::post('/json/v1/device/'.$deviceId.'/set_param', ['security' => ['arm' => true]]);

use Cruide\StarlineLaravel\Client;

class StarlineController
{
    public function __construct(private Client $starline)
    {
    }
}