Skip to content

Commit

Permalink
Convert functions to use the APIResponse class to manage responses fr…
Browse files Browse the repository at this point in the history
…om API.
  • Loading branch information
LswaN58 committed Jun 5, 2024
1 parent f8a3ee1 commit 70a63a4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 7 additions & 4 deletions site/gamedata.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_once 'includes/app_config.php';
require_once 'includes/services.php';
require_once 'models/APIResponse.php';
require_once 'models/game.php';
require_once 'models/game_file_info.php';
require_once 'components/pipeline_button.php';
Expand Down Expand Up @@ -45,10 +46,12 @@
$response_obj = services\getGameFileInfoByMonth($game_id);

if (isset($response_obj)) {
if ($response_obj->{'status'} == "SUCCESS") {
$game_files = GameFileInfo::fromObj($response_obj->{'val'});
$api_response = APIResponse::fromObj($response_obj);

if ($api_response->Status() == "SUCCESS") {
$game_files = GameFileInfo::fromObj($api_response->Value());
if (!isset($game_files) || $game_files == null) {
$err_str = "Got empty game_files from request that had status=".$response_obj->{'status'}." and val=".json_encode($response_obj->{'val'});
$err_str = "Got empty game_files from request that had status=".$api_response->Status()." and val=".json_encode($api_response->Value());
error_log($err_str);
}

Expand Down Expand Up @@ -79,7 +82,7 @@
$feature_files = $game_files->getFeatureFiles() ? $game_files->getFeatureFiles(): [];
}
else {
$err_str = "getGameFileInfoByMonth request, with year=null and month=null, was unsuccessful:\n".$response_obj->{'msg'}."\nDamn, maybe the authors shouldn't have written in a request for a specific month's data, but failed to supply a month! Who'd have thought?!?";
$err_str = "getGameFileInfoByMonth request, with year=null and month=null, was unsuccessful:\n".$api_response->Message()."\nDamn, maybe the authors shouldn't have written in a request for a specific month's data, but failed to supply a month! Who'd have thought?!?";
error_log($err_str);
}
}
Expand Down
8 changes: 5 additions & 3 deletions site/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_once 'includes/app_config.php';
require_once 'includes/services.php';
require_once 'models/APIResponse.php';
require_once 'models/game.php';
require_once 'models/game_usage.php';
require_once 'models/game_card.php';
Expand All @@ -18,11 +19,12 @@
$response_obj = services\getGameUsage($key);
$game_usage = null;
if (isset($response_obj)) {
if ($response_obj->{'status'} == "SUCCESS") {
$game_usage = GameUsage::fromObj($response_obj->{'val'});
$api_response = APIResponse::fromObj($response_obj);
if ($api_response->Status() == "SUCCESS") {
$game_usage = GameUsage::fromObj($api_response->Value());
}
else {
$err_str = "getGameUsage request, with game id=".$key.", was unsuccessful:\n".$response_obj->{'msg'};
$err_str = "getGameUsage request, with game id=".$key.", was unsuccessful:\n".$api_response->Message();
error_log($err_str);
}
}
Expand Down

0 comments on commit 70a63a4

Please sign in to comment.