From: Roland Häder Date: Sun, 10 Feb 2008 17:03:19 +0000 (+0000) Subject: API test for WDS66-API integrated X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=commitdiff_plain;h=816b0a4a62c6034558d471430d936223ef5cabca API test for WDS66-API integrated --- diff --git a/inc/extensions/ext-wernis.php b/inc/extensions/ext-wernis.php index 8c2d64d032..e8cb4a10aa 100644 --- a/inc/extensions/ext-wernis.php +++ b/inc/extensions/ext-wernis.php @@ -114,5 +114,9 @@ $EXT_LANG_PREFIX = "wernis"; // Extension is always active? $EXT_ALWAYS_ACTIVE = 'N'; +// Init array +global $WERNIS; +$WERNIS = array(); + // ?> diff --git a/inc/language/wernis_de.php b/inc/language/wernis_de.php index a57ab71099..5ba4027ee6 100644 --- a/inc/language/wernis_de.php +++ b/inc/language/wernis_de.php @@ -57,5 +57,9 @@ define('WERNIS_API_REQUEST_ERROR', "Abfragefehler: %s"); define('WERNIS_API_REQUEST_FAILED', "Unbekannter Fehler %s von API erhalten! Bitte im [Forum melden], den Fehlercode nennen und wie es dazu gekommen ist."); define('WERNIS_API_REQUEST_FAILED_AUTH', "Authorisierung an API fehlgeschlagen! Bitte API-ID und Key überprüfen. [Hier] direkt zum Export-Account. Sie benötigen Ihren Usernamen und Passwort!"); +// Error messages +define('WERNIS_ERROR_STATUS', "Fehler-Status %s erhalten."); +define('WERNIS_UNKNOWN_ERROR', "Unbekannter Fehler aufgetreten!"); + // ?> diff --git a/inc/libs/wernis_functions.php b/inc/libs/wernis_functions.php index 8dff531395..ea3840079e 100644 --- a/inc/libs/wernis_functions.php +++ b/inc/libs/wernis_functions.php @@ -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("
".print_r($return, true)."
"); + if ($return['status'] == "OK") { + // All fine! + $result = true; + } else { + // Status failture text + WERNIS_STATUS_MESSAGE($return['message'], $return['status']); + } + + // Return result + return $result; } //