-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_test.php
35 lines (30 loc) · 1.1 KB
/
api_test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
function buildApiUrl($command, $args = array()) {
$param = "";
foreach($args as $k => $v) {
$param = "&".$k."=".$v;
} // foreach end
return "http://localhost/ticketing_api/api_prototype/api_prototype.php?command=" . $command . $param;
}
function getApiResponse($command, $args = array()) {
$url = buildApiUrl($command, $args);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url
));
$result = curl_exec($curl);
echo $result;
return json_decode($result);
}
function checkIfApiIs($command, $args, $expectedMessage, $verbose = true) {
echo '<fieldset><legend>' . buildApiUrl($command, $args) . '</legend>';
$result = getApiResponse($command, $args);
echo '<div><pre>' . print_r($expectedMessage, 1) . '</pre></div>';
echo '<div><pre>' . print_r($result->Message, 1) . '</pre></div>';
echo '<div>' . ($expectedMessage == $result->Message ? "Ok" : "Error") . '</div>';
echo '</div>';
}
// Ping should return pong! as message
checkIfApiIs("ping", array(), "pong!", true);
?>