fleetlog-php
Fleetlog API wrapper, (*1)
- Include the class in your PHP code
- Set your access_token to FleetlogAPI
- Make request
Installation
Normally: Include TwitterAPIExchange.php in your application., (*2)
Composer: Add to your composer.json file to have FleetlogAPI.php automatically imported into your vendors folder:, (*3)
{
"require": {
"fleetlog/fleetlog-php": "dev-master"
}
}
Of course, you'll then need to run php composer.phar update
., (*4)
How To Use
Include the class file
require_once('FleetlogAPI.php');
Obtain an access token (client_credentials grant)
$body = array(
'grant_type' => 'client_credentials',
'client_id' => 'yourCLientId',
'client_secret' => 'yourClientSecret'
);
$customHeaders = ['Content-type: application/x-www-form-urlencoded'];
$fleetlog = new \FleetlogAPI();
$resultBody = $fleetlog->request('token', 'POST', $body, $customHeaders);
echo json_encode($resultBody);
$fleetlog->setAccessToken($resultBody->access_token);
$vehicles = $fleetlog->request('vehicles', 'GET');
echo json_encode($vehicles);
GET Request Example
[GET] https://api.fleetlog.com.au/v2/vehicles/222, (*5)
$settings = array(
'oauth_access_token' => "your_access_token",
);
$requestMethod = 'GET';
$fleetlog = new FleetlogAPI($settings);
echo json_encode($fleetlog->request('vehicles/222', 'GET'));
[GET] https://api.fleetlog.com.au/v2/vehicles/222/positions, (*6)
$settings = array(
'oauth_access_token' => "your_access_token",
);
$requestMethod = 'GET';
$fleetlog = new FleetlogAPI($settings);
echo json_encode($fleetlog->request('vehicles/222/positions', 'GET'));