<?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'); }
// do we have an inventory reservation already? // check from newest reservation to oldest $haveReservation = false; $reservations = array_reverse(TestRecords::getRecords()); foreach ($reservations as $reservation) { if (($reservation['conditions'] & $bitmask) == $bitmask) { $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);
<?php namespace samples; if (!class_exists(__NAMESPACE__ . '\\Loader')) { require_once realpath(__DIR__ . '/loader.php'); } use api; $api = new api\AVRSAPI(); $api->setURL('/api/v1.5/apiauthkeys/'); $api->setMethod('POST'); $api->addPayload('passphrase', md5('this is my unhashed passphrase')); $api->send(); Writer::writeRequestResponse($api); $response = json_decode($api->getResult(), true); $api->resetPayload(); $api->setMethod('DELETE'); $api->addPayload('id', $response['keys'][0]['id']); $api->send(); Writer::writeRequestResponse($api);
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 []; }
<?php namespace samples; if (!class_exists(__NAMESPACE__ . '\\Loader')) { require_once realpath(__DIR__ . '/loader.php'); } use api; $api = new api\AVRSAPI(); $api->setURL('/api/v1/test-records/'); $api->send(); Writer::writeRequestResponse($api); var_export(json_decode($api->getResult(), true));