TestAbstract.php
2.05 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
abstract class TestAbstract
{
abstract public function getAPI();
abstract public function getParams();
abstract public function getDescription();
abstract protected function checkRESTResult($result);
abstract protected function checkSOAPResult($result);
protected function needRESTAuth() {
return FALSE;
}
public function getWSTypes() {
return array("REST", "SOAP");
}
public function runREST($base_url) {
$params = $this->getParams();
if ($this->needRESTAuth()) {
$url = $base_url . '/php/rest/auth.php';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$token = curl_exec($curl);
if (curl_errno($curl) || empty($token)) {
echo "[ERROR] Cannot retrieve REST token".PHP_EOL;
return array(
'success' => FALSE,
'message' => "Cannot retrieve REST token",
);
}
curl_close($curl);
$params['token'] = $token;
}
$url = $base_url . '/php/rest/' . $this->getAPI() . '.php';
if (!empty($params)) {
$url .= "?" . http_build_query($params);
}
$curl = curl_init();
//ProxyUtils::addProxyForCurl($curl);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
if (curl_errno($curl)) {
return array(
'success' => FALSE,
'message' => 'Request error: '.curl_error($curl),
);
}
$exec_time = curl_getinfo($curl, CURLINFO_TOTAL_TIME);
curl_close($curl);
return $this->checkRESTResult($result);
}
public function runSOAP($base_url) {
$wsdl_url = $base_url . '/help/Methods_AMDA.xml';
try {
$client = new SoapClient($wsdl_url, array(
//'proxy_host' => "localhost",
//'proxy_port' => 8080,
//'proxy_login' => "some_name",
//'proxy_password' => "some_password"
));
$result = $client->__soapCall($this->getAPI(), array($this->getParams()));
}
catch (SoapFault $exception) {
return array(
'success' => FALSE,
'message' => 'SOAP error: '.$exception->getMessage(),
);
}
return $this->checkSOAPResult($result);
}
}
?>