Exemplo n.º 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');
}
Exemplo n.º 2
0
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 [];
}