<?php
// test_api_call.php - teste de chamada direta para a API (rodar só temporariamente)
// NÃO deixe em produção muito tempo

require_once __DIR__ . '/auth.php';

$endpoint = API_BASE_URL . '?token=' . urlencode(API_TOKEN);

echo "Endpoint: $endpoint\n\n";

$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true); // queremos headers + body
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'LOB-Banners-Proxy-Test/1.0');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Accept: application/json']);
$response = curl_exec($ch);
$err = curl_error($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headers = substr($response, 0, $header_size);
$body = substr($response, $header_size);
curl_close($ch);

echo "HTTP code: $http_code\n";
echo "cURL error: " . ($err ?: '(none)') . "\n\n";
echo "HEADERS:\n$headers\n";
echo "\nBODY:\n$body\n";