updated to HttpAsyncRequest Structure

This commit is contained in:
kremsy 2017-03-26 20:21:23 +02:00
parent 8e664879d5
commit da94e8c588
3 changed files with 36 additions and 12 deletions

View File

@ -469,6 +469,7 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
// Update last updated time
$map = $this->getMapByUid($mapInfo->uid);
if (!$map) {
// TODO: improve this - error reports about not existing maps
$this->maniaControl->getErrorHandler()->triggerDebugNotice('Map not in List after Insert!');

View File

@ -3,6 +3,7 @@
namespace ManiaControl\Server;
use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Files\AsyncHttpRequest;
use ManiaControl\Logger;
use ManiaControl\ManiaControl;
use ManiaControl\Utils\Formatter;
@ -81,11 +82,16 @@ class UsageReporter implements TimerListener {
$usageReport = json_encode($properties);
$url = ManiaControl::URL_WEBSERVICE . 'usagereport';
$this->maniaControl->getFileReader()->postData($url, function ($response, $error) {
$asyncRequest = new AsyncHttpRequest($this->maniaControl, $url);
$asyncRequest->setContent($usageReport);
$asyncRequest->setCallable(function ($response, $error) {
$response = json_decode($response);
if ($error || !$response) {
Logger::logError('Error while Sending data: ' . print_r($error, true));
}
}, $usageReport);
});
$asyncRequest->postData();
}
}

View File

@ -12,6 +12,7 @@ use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Files\AsynchronousFileReader;
use ManiaControl\Files\AsyncHttpRequest;
use ManiaControl\Logger;
use ManiaControl\ManiaControl;
use ManiaControl\Maps\Map;
@ -368,16 +369,23 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
}
$content = json_encode($properties);
$this->maniaControl->getFileReader()->postData(self::MX_KARMA_URL . self::MX_KARMA_GET_MAP_RATING . '?sessionKey=' . urlencode($this->mxKarma['session']->sessionKey), function ($json, $error) use (
$url = self::MX_KARMA_URL . self::MX_KARMA_GET_MAP_RATING . '?sessionKey=' . urlencode($this->mxKarma['session']->sessionKey);
$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, $url);
$asyncHttpRequest->setContent($content);
$asyncHttpRequest->setContentType($asyncHttpRequest::CONTENT_TYPE_JSON);
$asyncHttpRequest->setCallable(function ($json, $error) use (
&$player
) {
if ($error) {
$this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error);
$this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error' . $error);
return;
}
$data = json_decode($json);
if (!$data) {
$this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data);
$this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error' . $json);
return;
}
@ -403,10 +411,12 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
if ($data->data->message === 'invalid session') {
unset($this->mxKarma['session']);
} else {
$this->maniaControl->getErrorHandler()->triggerDebugNotice('fetch error', $data->data->message, self::MX_KARMA_GET_MAP_RATING, $this->mxKarma['session']);
$this->maniaControl->getErrorHandler()->triggerDebugNotice('fetch error ' . $data->data->message . self::MX_KARMA_GET_MAP_RATING . $this->mxKarma['session']);
}
}
}, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON);
});
$asyncHttpRequest->postData();
}
/**
@ -483,14 +493,19 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$content = json_encode($properties);
$this->maniaControl->getFileReader()->postData(self::MX_KARMA_URL . self::MX_KARMA_SAVE_VOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($json, $error) {
$url = self::MX_KARMA_URL . self::MX_KARMA_SAVE_VOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey);
$asyncRequest = new AsyncHttpRequest($this->maniaControl, $url);
$asyncRequest->setContent($content);
$asyncRequest->setContentType($asyncRequest::CONTENT_TYPE_JSON);
$asyncRequest->setCallable(function ($json, $error) {
if ($error) {
$this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error);
$this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error ' . $error);
return;
}
$data = json_decode($json);
if (!$data) {
$this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data);
$this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error ' . $json);
return;
}
if ($data->success) {
@ -501,10 +516,12 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
if ($data->data->message === "invalid session") {
unset($this->mxKarma['session']);
} else {
$this->maniaControl->getErrorHandler()->triggerDebugNotice('saving error', $data->data->message, self::MX_KARMA_SAVE_VOTES, $this->mxKarma['session']);
$this->maniaControl->getErrorHandler()->triggerDebugNotice('saving error ' . $data->data->message . self::MX_KARMA_SAVE_VOTES . $this->mxKarma['session']);
}
}
}, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON);
});
$asyncRequest->postData();
}
/**