PHP code example of automile / automile-php

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

    

automile / automile-php example snippets






$userModel = AutomileClient::signUp('username@example.com');
echo $userModel->toPHP();

\Automile\Sdk\Config::setUsername('username@example.com');
\Automile\Sdk\Config::setPassword('*****');
\Automile\Sdk\Config::setApiClient('*****.automile.com');
\Automile\Sdk\Config::setApiSecret('*****');

// import ile\Sdk\AutomileClient;
use Automile\Sdk\Config;
use Automile\Sdk\Types;
use Automile\Sdk\Models;

// path to the token
define('AUTOMILE_TOKEN', '/path/to/storage/automile-token.json');

// Automile account credentials
// see also Sign Up section above
Config::setUsername('username@example.com');
Config::setPassword('*****');
Config::setApiClient('*****.automile.com');
Config::setApiSecret('*****');

// initialize the client from saved token
// if the token is missing, a new one will be created using the credentials above
$client = AutomileClient::fromSavedToken(AUTOMILE_TOKEN);

// provide the path to the token storage file in case the new token is created, or old one refreshed
$client->saveToken(AUTOMILE_TOKEN);

// confirm everything's been set up correctly
$isValid = $client->validateToken();
var_dump($isValid);

$vehicles = $client->getVehicles();

$vehicleDetails = $client->getVehicleById(33553);

$vehicleStatus = $client->getStatusForVehicles();

$client->checkInToVehicle(new Models\Vehicle\CheckIn([
    "ContactId" => 2,
    "VehicleId" => 33553,
    "DefaultTripType" => Types\TripType::AUTO, // Use the users schedule, place or other automation rules
    "CheckOutAtUtc" = (new \DateTime('now', 'UTC'))->add(new \DateInterval('P3D')) // Use to schedule future auto-checkout, leave empty for permanent check-in
}));

$client->checkOut();

$trips = $client->getTrips(3); // number of days

$tripOverview = $client->getTripById(31826384);

$tripStartStopPosition = $client->getTripStartStopLatitudeLongitude(31826384);

$tripPositions = $client->geoTripLatitudeLongitude(31826384);

$tripDetails = $client->getCompletedTripDetails(31826384);

$tripAdvanced = $client->getCompletedTripDetailsAdvanced(31826384);

$rpmValues = $client->getTripRPM(31826384);

$ambientTemperatures = $client->getTripAmbientTemperature(31826384);

$coolantTemperatures = $client->getTripEngineCoolantTemperature(31826384);

$fuelLevels = $client->getTripFuelLevel(31826384);

$client->editTrip(new Models\Trip([
    "TripId" => 31826384,
    "TripTags" => ['note 1', 'note 2'],
    "TripType" => Types\TripType::BUSINESS
]));

$client->setDriverOnTrip(31826384, 2);

$contacts = $client->getContacts();

$contactDetail = $client->getContactById(2);

$me = $client->getMe();

$geofences = $client->getGeofences();

$geofenceDetails = $client->getGeofenceById(881);

$polygon = new Models\GeofencePolygon([
    ["Latitude" => 37.44666232, "Longitude" => -122.16905397],
    ["Latitude" => 37.4536707, "Longitude" => -122.16150999],
    ["Latitude" => 37.4416096, "Longitude" => -122.16112375]
]);
$client->createGeofence(new Models\Geofence([
    'Name' => 'My Palo Alto geofence',
    'Description' => 'Outside main offfice',
    'VehicleId' => 33553,
    'GeofencePolygon' => $polygon,
    'GeofenceType' => Types\GeofenceType::OUTSIDE
]));

$polygon = new Models\GeofencePolygon([
    ["Latitude" => 37.44666232, "Longitude" => -122.16905397],
    ["Latitude" => 37.4536707, "Longitude" => -122.16150999],
    ["Latitude" => 37.44873066, "Longitude" => -122.15365648],
    ["Latitude" => 37.4416096, "Longitude" => -122.16112375]
]);
$client->createGeofence(new Models\Geofence([
    'GeofenceId' => 3319,
    'Name' => 'Another name',
    'Description' => 'Outside main offfice',
    'GeofencePolygon' => $polygon,
    'GeofenceType' => Types\GeofenceType::OUTSIDE
]));

$client->deleteGeofence(881);

$notifications = $client->getNotifications();

$notificationDetails = $client->getNotificationById(25173);

$newNotification = $client->createNotification(new Models\Trigger([
    "IMEIConfigId" => 28288, // What is this ?
	// IMEIConfigId is today called DeviceId and is the device identifier 
	// connected to the vehicle, you can get this id from the vehicle (GetVehicleById method)
    "TriggerType" => Types\TriggerType::ACCIDENT,
    "DestinationType" => Types\DestinationType::SMS,
    "DestinationData" => "+14158320378"
]));

$client->editNotification(new Models\Trigger([
    "TriggerId" => 190914,
    "IMEIConfigId => 28288, // See note above, this is the DeviceId
    "TriggerType" => Types\TriggerType::ACCIDENT,
    "DestinationType" = Types\DestinationType::SMS,
    "DestinationData" = "+14158320378"
]));

$client->muteNotification(190913, 60*60); // mutes for 1 hour

$client->unmuteNotification(190913);

$client->deleteNotification(190913);

$notificationMessages = $client->getNotificationMessages();

$forSpecificNotification = $client->getNotificationMessagesByNotificationId(148638);

$places = $client->getPlaces();

$placeDetails = $client->getPlaceById(10977);

$newPlace = $client->createPlace(new Models\Place([
    "Name" => "My place",
    "Description" => "My home",
    "PositionPoint" => new Models\GeographicPosition([ "Latitude" => 37.445368, "Longitude" => -122.166608 ]),
    "Radius" => 100, //metric meters
	//This will whenever the vehicle starts at this location set it to business
    "TripType" => Types\TripType::BUSINESS,
    "TripTypeTrigger" => Types\TripTypeTriggerType::START,
    "VehicleId" => 33553
]));

$client->editPlace(new Models\Place([
    "PlaceId" => 11968,
    "Name" => "My place - edited",
    "PositionPoint" => new Models\GeographicPosition([ "Latitude" => 37.445368, "Longitude" => -122.166608 ])
]));

$client->deletePlace(11968);

$devices = $client->getDevices();

$deviceDetails = $client->getDeviceById(28288);

$newDevice = $client->createDevice(new Models\Device([
    "IMEI" => "353466072332998",
    "SerialNumber" => "6070763210",
    "VehicleId" => 33553,
    "IMEIDeviceType" = null // no need if you register a box
]));

$client->editDevice(new Models\Device([
    "IMEIConfigId" => 28288,
    "VehicleId" => 33553
]));

$client->deleteDevice(11968);

$fleets = $client->getFleets();

$fleetDetails = $client->getFleetById(3331);

$newFleet = $client->createFleet(new Models\Company([
    "CreateRelationshipToContactId" => 2,
    "Description" => "Some good description for the fleet",
    "RegisteredCompanyName" => "My new fleet"
]));

$client->editFleet(new Models\Company([
{
    "CompanyId" => 3331,
    "Description" => "Test",
    "RegisteredCompanyName" => "Automile Palo Alto Fleet"
});

$client->deleteFleet(3331);

$vehicleGeofencesRelationships = $client->getVehicleGeofencesByGeofenceId(3276);

$vehicleGeofenceRelationships = $client->getVehicleGeofenceById(44251);

$newVehicleGeofenceRelationship = $client->createVehicleGeofence(new Models\Vehicle\Geofence([
    "GeofenceId" => 3276,
    "VehicleId" => 33553,
	// Restrict when this geofence should be valid from and to if needed
    "ValidFrom" => null,
    "ValidTo" => null
]));

$dateTime = new \DateTime('now', new \DateTimeZone('UTC'));
$client->editVehicleGeofence(new Models\Vehicle\Geofence([
    "VehicleGeofenceId" => 44251,
	"ValidFrom" => $dateTime->format('Y-m-d'),
	"ValidTo" => $dateTime->add(new \DateInterval('P7D'))->format('Y-m-d')
}));

$client->deleteVehicleGeofence(44251);

$vehiclePlacesRelationships = $client->getVehiclePlaceById(10977);

$vehiclePlaceRelationships = $client->getVehiclePlacesByPlaceId(44251);

$newVehiclePlace = $client->createVehiclePlace(new Models\Vehicle\Place([
    "PlaceId" => 10977,
    "VehicleId" => 33553,
    "Description" => "Some description",
    "Radius" => 100,
    "TripType" => Types\TripType::BUSINESS,
    "TripTypeTrigger" => Types\TripTypeTriggerType::START
]));

$client->editVehiclePlace(new Models\Vehicle\Place([
    "VehiclePlaceId" => 30567,
    "Description" => "Some description",
    "Radius" => 100,
    "TripType" => Types\TripType::BUSINESS,
    "TripTypeTrigger" => Types\TripTypeTriggerType::DRIVES_BETWEEN,
    "DrivesBetweenAnotherPlaceId" => 10979
}));

$client->deleteVehiclePlace(36405);

$allFleetDrivers = $client->getFleetContacts();

$specificDriverRelationship = $client->getFleetContactById(2);

$allDriversForSpecificFleet = $client->getFleetContactsByFleetId(10);

$newFleetContact = $client->createFleetContact(new Models\CompanyContact([
    "CompanyId" => 10,
    "ContactId" => 2
]));

$client->editFleetContact(new Models\CompanyContact([
    "CompanyContactId" => 10398,
    "CompanyId" => 11,
    "ContactId" => 2
]));

$client->deleteFleetContact(10398);

$deviceEvents = $client->getDeviceEvents();

$deviceStatusEvent = $client->getDeviceEventStatusById(1138161);

$deviceMILEvent = $client->getDeviceEventMILById(1138162);

$deviceDTCEvent = $client->getDeviceEventDTCById(1138213);

$publishSubscribeRecords = $client->getPublishSubscribe();

$detailsPublishSubscribeRecord = $client->getPublishSubscribeById(1);

$newSubscription = $client->createPublishSubscribe("http://requestb.in/pwimfapw");

$newSubscription = $client->createPublishSubscribe("http:/your_basic_auth_endpoint", new Models\PublishSubscribeAuthentication\Basic([
    "Username" => "username",
    "Password" => "password"
]));

$client->deletePublishSubscribe(1);

composer 
json
{
  "PublishMessageType": 1,
  "PublishMessageDateTimeUtc": "2017-02-11T04:04:36.926967Z",
  "TripId": 32575162,
  "VehicleId": 33553,
  "DriverContactId": null,
  "TripStartDateTime": "2017-02-11T01:14:44",
  "TripStartTimeZone": -8,
  "TripEndDateTime": "2017-02-11T01:21:40",
  "TripEndTimeZone": -8,
  "TripStartFormattedAddress": "2809-2811 Middlefield Rd, Palo Alto, CA 94306, USA",
  "TripEndFormattedAddress": "829 Thornwood Dr, Palo Alto, CA 94303, USA",
  "TripStartCustomAddress": null,
  "TripEndCustomAddress": null,
  "TripLengthInKilometers": 2,
  "TripType": 0,
  "TripTags": null,
  "FuelInLiters": null,
  "IdleTimeInSecondsAllTrip": 123,
  "IdleTimeInSecondsFromStart": 30,
  "CustomCategory": null,
  "TripLengthInMinutes": 7,
  "TripStartLongitude": -122.127766666667,
  "TripStartLatitude": 37.4326833333333,
  "TripEndLongitude": -122.114066666667,
  "TripEndLatitude": 37.4287666666667
}
json
{
  "PublishMessageType": 0,
  "PublishMessageDateTimeUtc": "2017-02-11T03:48:12.0845446Z",
  "TripId": 32575162,
  "VehicleId": 33553,
  "DriverContactId": null,
  "TripStartDateTime": "2017-02-11T01:14:44",
  "TripStartTimeZone": -8,
  "TripStartFormattedAddress": "2809-2811 Middlefield Rd, Palo Alto, CA 94306, USA",
  "TripStartLongitude": -122.127766666667,
  "TripStartLatitude": 37.4326833333333
}