<?php
var $url = "http://api.panaceamobile.com/json";
var $curl = false;
var $debug = true;
var $error = null;
var $username = null;
var $password = null;
var $performActionsImmediately = true;
var $queuedActions = array();
function __construct() {
if(($ver[0] >= 5)) {
$this->debug("Version OK ".
implode(".", $ver));
$this->debug("You need the json_encode and json_decode functions to use this Class, JSON is available in PHP 5.2.0 and up for alternatives please see http://json.org");
$this->debug("Your PHP version is ".
implode(".", $ver).
" ".__FILE__
);
die();
}
} else {
$this->debug("You need at least PHP 5 to use this Class ".__FILE__);
die();
}
}
function debug($str, $nl = true) {
if($this->debug) {
echo $str;
if($nl) {
echo "\n";
}
}
}
function call_api($url) {
if($this->curl === FALSE) {
} else {
}
curl_setopt($this->curl, CURLOPT_HTTPHEADER, array("Connection: keep-alive"));
$request_headers =
curl_getinfo($this->curl, CURLINFO_HEADER_OUT);
$response_headers =
substr($result, 0, $size);
$result =
substr($result, $size);
$this->debug("--- HTTP Request trace --- ");
$this->debug($request_headers, false);
$this->debug($response_headers, false);
$this->debug($result);
if($result !== FALSE) {
return json_decode($result, true);
}
return false;
} else {
$this->debug("You need cURL to use this API Library");
}
return FALSE;
}
function call_api_action($method, $params, $authenticate = true) {
if($this->performActionsImmediately) {
$url =
$this->url.
"?action=".
urlencode($method->getName());
if($authenticate) {
$url .=
"&username=".
urlencode($this->username);
$url .=
"&password=".
urlencode($this->password);
} else {
$this->debug("You need to specify your username and password using setUsername() and setPassword()");
return FALSE;
}
}
$parameters = $method->getParameters();
for($i=
0;$i<
count($params);$i++
) {
}
}
return $this->call_api($url);
} else {
$this->debug("You need to specify your username and password using setUsername() and setPassword() to perform bulk actions");
return FALSE;
}
$action = array(
'command' => $method->getName(),
'params' => array()
);
$parameters = $method->getParameters();
for($i=
0;$i<
count($params);$i++
) {
$action['params'][$parameters[$i]->getName()] = $params[$i];
}
$this->queuedActions[] = $action;
return TRUE;
}
}
if($this->curl === FALSE) {
} else {
}
$url = $this->url . "?action=execute_multiple";
$url .=
"&username=".
urlencode($this->username);
$url .=
"&password=".
urlencode($this->password);
curl_setopt($this->curl, CURLOPT_HTTPHEADER, array("Connection: keep-alive"));
$request_headers =
curl_getinfo($this->curl, CURLINFO_HEADER_OUT);
$response_headers =
substr($result, 0, $size);
$result =
substr($result, $size);
$this->debug("--- HTTP Request trace --- ");
$this->debug($request_headers,false);
$this->debug("\n");
$this->debug($response_headers, false);
$this->debug($result);
if($result !== FALSE) {
return json_decode($result, true);
}
return false;
} else {
$this->debug("You need cURL to use this API Library");
}
return FALSE;
}
function setUsername($username) {
$this->username = $username;
}
function setPassword($password) {
$this->password = $password;
}
function performActionsImmediately($state) {
$this->performActionsImmediately = $state;
}
function message_send($to, $text, $from =
null, $report_mask =
19, $report_url =
null, $charset =
null, $data_coding =
null, $message_class = -
1, $auto_detect_encoding =
null) {
return $this->call_api_action(new ReflectionMethod(__CLASS__, __FUNCTION__), $args);
}
return $this->call_api_action(new ReflectionMethod(__CLASS__, __FUNCTION__), $args);
}
return $this->call_api_action(new ReflectionMethod(__CLASS__, __FUNCTION__), $args);
}
return $this->call_api_action(new ReflectionMethod(__CLASS__, __FUNCTION__), $args);
}
return $this->call_api_action(new ReflectionMethod(__CLASS__, __FUNCTION__), $args);
}
return $this->call_api_action(new ReflectionMethod(__CLASS__, __FUNCTION__), $args);
}
return $this->call_api_action(new ReflectionMethod(__CLASS__, __FUNCTION__), $args);
}
return $this->call_api_action(new ReflectionMethod(__CLASS__, __FUNCTION__), $args);
}
return $this->call_api_action(new ReflectionMethod(__CLASS__, __FUNCTION__), $args);
}
return $this->call_api_action(new ReflectionMethod(__CLASS__, __FUNCTION__), $args);
}
return $this->call_api_action(new ReflectionMethod(__CLASS__, __FUNCTION__), $args);
}
return $this->call_api_action(new ReflectionMethod(__CLASS__, __FUNCTION__), $args);
}
return $this->call_api_action(new ReflectionMethod(__CLASS__, __FUNCTION__), $args);
}
return $this->call_api_action(new ReflectionMethod(__CLASS__, __FUNCTION__), $args);
}
return $this->call_api_action(new ReflectionMethod(__CLASS__, __FUNCTION__), $args, false);
}
return $this->call_api_action(new ReflectionMethod(__CLASS__, __FUNCTION__), $args, false);
}
return $this->call_api_action(new ReflectionMethod(__CLASS__, __FUNCTION__), $args);
}
function batch_create($name, $file, $throughput =
0, $filter =
false, $file_type =
'csv', $start_time =
null) {
/* This function has special requirements in terms of streaming raw data, hence it calls the API directly */
if($this->curl === FALSE) {
} else {
}
$this->debug("File {$file} does not exist");
return FALSE;
}
if($file_type != 'zip') {
} else {
}
$url = $this->url . "?action=batch_create";
$url .=
"&username=".
urlencode($this->username);
$url .=
"&password=".
urlencode($this->password);
$url .= "&filter=".($filter ? 'true' : 'false');
$url .= "&throughput=".$throughput;
$url .=
"&start_time=".
urlencode($start_time);
}
curl_setopt($this->curl, CURLOPT_HTTPHEADER, array("Connection: keep-alive"));
$request_headers =
curl_getinfo($this->curl, CURLINFO_HEADER_OUT);
$response_headers =
substr($result, 0, $size);
$result =
substr($result, $size);
$this->debug("--- HTTP Request trace --- ");
$this->debug($request_headers, false);
$this->debug($response_headers, false);
$this->debug($result);
if($result !== FALSE) {
return json_decode($result, true);
}
return false;
} else {
$this->debug("You need cURL to use this API Library");
}
return false;
}
function ok($result) {
if($result['status'] >= 0) {
return TRUE;
}
$this->error = $result['message'];
}
} else {
if($result === TRUE) {
$this->error = "Command queued";
return TRUE;
}
$this->error = "Error communicating with API";
}
return FALSE;
}
function getError() {
return $this->error;
}
}