Example #1
0
<?php

namespace samples;

if (!class_exists(__NAMESPACE__ . '\\Loader')) {
    require_once realpath(__DIR__ . '/loader.php');
}
use api\AVRSAPI;
$json = json_encode(array('_gte' => '-2 hours', '_lte' => 'now'));
$url = '/api/v1/deals/?pdf=1&accept-time=' . urlencode($json);
$api = new AVRSAPI();
$api->enableDebug();
$api->setURL($url);
$api->send();
Writer::writeRequest($api);
if ($api->getInfo('http_code') == 200) {
    Writer::writeResponse($api, null, 'pdf');
} else {
    Writer::writeResponse($api, null, 'txt');
}
$api->setMethod('POST');
$api->addPayload('vehicles', array(array('vin' => $reservation['vin'], 'plate' => $reservation['plate'], 'insurance' => 'Y')));
$api->addPayload('status', 'QF');
$api->addPayload('transaction-type', 6);
$api->send();
$response = json_decode($api->getResult(), true);
while ($retryAttempts++ < $retryMax && $response['deals'][0]['error-code'] == 'CADMV/Q023') {
    error_log('DMV Retry Code Encountered');
    sleep($retryDelayBase * pow(2, $retryAttempts));
    $api->send();
    $response = json_decode($api->getResult(), true);
}
Writer::writeRequestResponse($api);
if (empty($response['deals'][0]['error-code'])) {
    sleep(1);
    // just to be sure that we don't overwrite the first request/response pair
    $retryAttempts = 0;
    $api->resetPayload();
    $api->setMethod('PUT');
    $api->addPayload('id', $response['deals'][0]['id']);
    $api->addPayload('status', 'QA');
    $api->send();
    $response = json_decode($api->getResult(), true);
    while ($retryAttempts++ < $retryMax && $response['deals'][0]['error-code'] == 'CADMV/Q023') {
        error_log('DMV Retry Code Encountered');
        sleep($retryDelayBase * pow(2, $retryAttempts));
        $api->send();
        $response = json_decode($api->getResult(), true);
    }
    Writer::writeRequestResponse($api);
}