Alukard_X
Grand Guru
- Joined
- Oct 3, 2020
- Messages
- 825
PHP:
<?php
class AdMavenAPI {
private $baseUrl = "https://advertisers.ad-maven.com";
private $sessionToken = null;
private $apiToken = null;
public function authenticate($username, $password) {
$url = $this->baseUrl . "/api/user";
$data = json_encode([
"username" => $username,
"password" => $password
]);
$headers = [
"accept: application/json, text/plain, */*",
"content-type: application/json",
"cache-control: no-cache",
"pragma: no-cache",
"referer: https://advertisers.ad-maven.com/user-login"
];
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $data,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_TIMEOUT => 30
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);
if ($error) {
throw new Exception("cURL Error: " . $error);
}
$responseData = json_decode($response, true);
if ($responseData['type'] === 'created') {
$this->sessionToken = $responseData['message']['token'];
$this->apiToken = $responseData['message']['api_user_token'];
return true;
} else {
throw new Exception("Authentication failed: " . json_encode($responseData));
}
}
public function manageCampaign($campaignId, $enable) {
if (!$this->sessionToken) {
throw new Exception("Not authenticated. Please call authenticate() first.");
}
$url = $this->baseUrl . "/api/campaign?campaign_id=" . $campaignId;
$data = '[{"_id":' . $campaignId . ',"enable":' . ($enable ? 'true' : 'false') . '}]';
$headers = [
"accept: application/json, text/plain, */*",
Last edited: