Files
Wrench-ApiTester/public/wrenchboard_class.php
T
dev-chiefworks 7d830711b3 New files
2023-04-30 20:25:08 -04:00

158 lines
5.0 KiB
PHP

<?php
include_once('def.php');
class wrenchboard_class{
public $REACT_APP_AUX_ENDPOINT = "http://10.204.5.100:9083/en/wrench/api/v1"; //"https://apigate.lotus.g1.wrenchboard.com/svs/user";
public $REACT_APP_USERS_ENDPOINT = "http://10.204.5.100:9083/en/wrench/api/v1"; // "https://apigate.lotus.g1.wrenchboard.com/svs/user";
function __construct() {
}
/*
$endpoints = array(
'apigate' => array('POST'),
'generics' => array('POST'),
'createuser' => array('POST'),
'createmobileuser' => array('POST'),
'completemobileuser' => array('POST'),
'startresetpasword' => array('POST'),
'userlogin' => array('POST'),
'startjoblist' => array('POST'),
'dashdata' => array('POST'),
'getjobsdata' => array('POST'),
'offerslist' => array('POST'),
'activejoblist' => array('POST'),
'loadprofile' => array('POST'),
'account' => array('POST'),
'message' => array('POST'),
'pendingjob' => array('POST'),
'paymenthx' => array('POST'),
'getjob' => array('POST'),
'mybanklist' => array('POST'),
'sendmoney' => array('POST'),
'sendinterest' => array('POST'),
'sendmoneyfee' => array('POST'),
'getpendingjobs' => array('POST'),
'taskmessage' => array('POST'),
'sendtaskmessage' => array('POST'),
'getwallets' => array('POST'),
'sitecontact' => array('POST'),
'signupcountry' => array('POST'),
'userscards' => array('POST'),
'blogdata' => array('POST'),
'blogitem' => array('POST'),
'couponhx' => array('POST'),
'couponpending' => array('POST'),
'couponredeem' => array('POST'),
'sendinterestmessage' => array('POST'),
'replyinterestmessage' => array('POST')
);
*/
private function baseUrlPath($in)
{
$pathName = '';
switch ($in['action']) {
case WRENCHBOARD_ACCOUNT_LOGIN:
$pathName = 'userlogin';
break;
case WRENCHBOARD_ACCOUNT_PENDING:
$pathName = 'createuser';
break;
case WRENCHBOARD_CARDS_GETCARDLIST:
$pathName = 'userscards';
break;
case WRENCHBOARD_CARDS_GETCARDLIST:
$pathName = 'startjoblist';
break;
case WRENCHBOARD_MOBILE_ACTIVEJOB:
$pathName = 'activejoblist';
break;
case WRENCHBOARD_ACCOUNT_WALLETS:
$pathName ='getwallets';
break;
case WRENCHBOARD_START_JOBLIST:
$pathName="startjoblist";
break;
}
return $pathName;
}
public function wrenchboard_api($in, &$out = array()) {
$ret = 0;
$urlPath = $this->baseUrlPath($in);
$local_url = $this->REACT_APP_USERS_ENDPOINT;
$url = $local_url ."/".$urlPath; //"/generics";
$data = $in;
$content = json_encode($data);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type" => "application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($status != 200) {
echo ("Error: call to URL $url failed with status $status, response $json_response, | curl_error " . curl_error($curl) . ", | curl_errno " . curl_errno($curl));
}
curl_close($curl);
$response = json_decode($json_response, true);
$this->showResult($url, $in, $response);
$out = $response;
return $response["internal_return"];
}
private function showResult($url, $in,$out){
echo "<table>
<tr><td colspan='3'><b>TARGET ENDPOINT[POST]</b>".$url."</td></tr>
<tr>
<td>".var_dump($in)."</td>
<td style='background-color:yellow'>".var_dump($out)."</td>
<td></td>
</tr>
</table>";
//$response['result_list']
if ( isset($out['result_list']) && is_array($out['result_list']) && count($out['result_list']) > 0 ){
$arr = $out['result_list'];
$myHeaders = array_keys($arr[0]);
var_dump( $myHeaders);
$tableHead = '<tr>';
foreach ($myHeaders as $hd){
$tableHead .= "<th>".$hd."</th>";
}
$tableHead .= '</tr>';
$tableBody = '';
foreach ($arr as $item) {
$tableBody .= '<tr>';
$backColor ='white';
foreach ($myHeaders as $hd){
$backColor = ($backColor=='aliceblue')?'white': 'aliceblue';
$tableBody .= "<td style='background-color:$backColor'>".$item[$hd]."</td>";
}
$tableBody .= '</tr>';
}
echo "<table>".$tableHead.$tableBody."</table>";
}
}
}
?>