API test for WDS66-API integrated
[mailer.git] / inc / libs / wernis_functions.php
index 8dff531395a50d113505ea7b95e4acf584e499c0..ea3840079e516a1162d0db17721d7642e1db9c16 100644 (file)
@@ -37,6 +37,28 @@ if (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) {
        require($INC);
 }
 
+// Sets a status message and code
+function WERNIS_STATUS_MESSAGE ($msg, $status) {
+       global $WERNIS;
+       $WERNIS['message'] = $msg;
+       $WERNIS['status'] = $status;
+}
+
+// Get the status message
+function WERNIS_ERROR_MESSAGE () {
+       global $WERNIS;
+       if (isset($WERNIS['message'])) {
+               // Use raw message
+               return $WERNIS['message'];
+       } elseif (isset($WERNIS['status'])) {
+               // Fall-back to status
+               return sprintf(WERNIS_ERROR_STATUS, $WERNIS['status']);
+       } else {
+               // Something bad happend
+               return WERNIS_UNKNOWN_ERROR;
+       }
+}
+
 // Sends out a request to the API and returns it's result
 function WERNIS_SEND_REQUEST ($scriptName, $requestData =  array()) {
        global $CONFIG;
@@ -126,11 +148,21 @@ function WERNIS_SEND_REQUEST ($scriptName, $requestData =  array()) {
 function WERNIS_TEST_API () {
        // Get config first
        global $CONFIG;
+       $result = false;
 
-       // Prepare the request to the API
+       // Return the result from the lower functions
        $return = WERNIS_SEND_REQUEST("balance.php");
 
-       die("<pre>".print_r($return, true)."</pre>");
+       if ($return['status'] == "OK") {
+               // All fine!
+               $result = true;
+       } else {
+               // Status failture text
+               WERNIS_STATUS_MESSAGE($return['message'], $return['status']);
+       }
+
+       // Return result
+       return $result;
 }
 
 //