Skip to content
Snippets Groups Projects
Commit 0bba2280 authored by bewe's avatar bewe
Browse files

feat: fetch gems from soap

parent b24a6461
Branches
No related merge requests found
......@@ -16,7 +16,7 @@ function submitQuiz($exerciseId, $selectedOption)
var_dump($exerciseId);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://172.20.10.2:5000/exercise/result/" . $exerciseId);
curl_setopt($ch, CURLOPT_URL, "http://express:5000/exercise/result/" . $exerciseId);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($submitData));
......
......@@ -9,7 +9,7 @@ class Exercise extends Controller
$data["pageTitle"] = "Test your knowledge!";
$data["languages"] = $this->model("LanguageModel")->getAllLanguage();
$baseUrl = 'http://172.20.10.2:5000/exercise';
$baseUrl = 'http://express:5000/exercise';
$ch = curl_init($baseUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
......@@ -35,7 +35,7 @@ class Exercise extends Controller
$data["user_id"] = $_SESSION['user_id'];
$data["exercise_id"] = intval($exerciseId);
$baseUrl = 'http://172.20.10.2:5000/exercise';
$baseUrl = 'http://express:5000/exercise';
$ch = curl_init($baseUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
......@@ -50,7 +50,7 @@ class Exercise extends Controller
}
}
$baseUrl = 'http://172.20.10.2:5000/question/' . $data["exercise_id"];
$baseUrl = 'http://express:5000/question/' . $data["exercise_id"];
$ch = curl_init($baseUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
......@@ -58,7 +58,7 @@ class Exercise extends Controller
$data["question"] = $question['result'][0]; // ini '0' bisa diganti page
$baseUrl = 'http://172.20.10.2:5000/option/' . $data["question"]["question_id"];
$baseUrl = 'http://express:5000/option/' . $data["question"]["question_id"];
$ch = curl_init($baseUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
......
......@@ -9,7 +9,7 @@ class Merchandise extends Controller
$data["pageTitle"] = "Merch!";
$data["user_id"] = $_SESSION['user_id'];
$baseUrl = 'http://10.97.58.62:8080/gems';
$baseUrl = 'http://soap:8080/gems';
$soapRequest = '<x:Envelope
xmlns:x="http://schemas.xmlsoap.org/soap/envelope/"
......@@ -17,7 +17,7 @@ class Merchandise extends Controller
<x:Header/>
<x:Body>
<ser:getGems>
<arg0>1</arg0>
<arg0>' . $data["user_id"] . '</arg0>
</ser:getGems>
</x:Body>
</x:Envelope>';
......@@ -26,10 +26,14 @@ class Merchandise extends Controller
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $soapRequest);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: text/xml',
'SOAPAction: getGems'
)
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
array(
'Content-Type: text/xml',
'SOAPAction: getGems',
'X-api-key: toco_php'
)
);
$response = curl_exec($ch);
......@@ -40,7 +44,12 @@ class Merchandise extends Controller
curl_close($ch);
$data['gems'] = $response;
if (preg_match('/<return>(\d+)<\/return>/', $response, $matches)) {
$data['gems'] = (int)$matches[1];
} else {
echo 'Error extracting numeric value from XML response.';
}
$this->view('header/index', $data);
$this->view('navbar/index');
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment