Beispiel #1
0
 public static function writeResponse(api\AVRSAPI $api, $prefix = null, $suffix = 'json')
 {
     if (!isset($prefix)) {
         $prefix = date(self::$prefixFormat);
     }
     $fh = fopen(__DIR__ . '/' . $prefix . 'response.' . $suffix, 'w');
     fwrite($fh, $api->getResult());
     fclose($fh);
 }
        $haveReservation = true;
        break;
    }
}
if (!$haveReservation) {
    $reservation = TestRecords::reserveRecord($bitmask);
}
// create a deal with the required fields and immediately request fees
$api = new AVRSAPI();
$api->setURL('/api/v1/deals/');
$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');
function createApiKey(array $keyDetails)
{
    $api = new AVRSAPI();
    $api->setMethod('POST');
    $api->setURL('/api/v1.5/apiauthkeys/');
    foreach ($keyDetails as $key => $value) {
        $api->addPayload($key, $value);
    }
    $api->send();
    $httpInfo = $api->getInfo();
    $results = json_decode($api->getResult(), true);
    if ($httpInfo['http_code'] != 200) {
        print_r($results);
        throw new \Exception('Unable to create API key.  Received http error code: ' . $httpInfo['http_code']);
    }
    if (isset($results['keys'][0]) && is_array($results['keys'][0])) {
        return $results['keys'][0];
    }
    return [];
}