]> git.stg.codes - stg.git/blob - doc/xmlrpc.php
Ticket 37. The TARIFF::CHANGE_POLICY changePolicy object added in the
[stg.git] / doc / xmlrpc.php
1 <?php
2
3 // Call helper
4
5 function __call($method, $params = null)
6 {
7     $request = xmlrpc_encode_request($method, $params, array('escaping' => 'markup', 'encoding' => 'utf-8'));
8     $context = stream_context_create(
9             array('http' => array(
10                         'method' => 'POST',
11                         'header' => 'Content-Type: text/xml',
12                         'content' => $request)));
13
14     $file = file_get_contents('http://localhost:8080/RPC2', false, $context);
15     $response = xmlrpc_decode($file);
16
17     if (is_array($response) && xmlrpc_is_fault($response)) {
18         trigger_error("xmlrpc: {$response['faultString']} ({$response['faultCode']})");
19     }
20
21     return $response;
22 }
23
24 // Usage samples
25
26 print_r(__call('stargazer.info'));
27 $data = __call('stargazer.login', array('admin', '123456'));
28 if (isset($data['cookie'])) {
29     $cookie = $data['cookie'];
30     print_r($data);
31     print_r(__call('stargazer.get_tariffs', array($cookie)));
32     print_r(__call('stargazer.logout', array($data['cookie'])));
33 }
34
35 ?>
36