]> git.stg.codes - stg.git/blobdiff - doc/xmlrpc.php
Документация помещена в каталог doc
[stg.git] / doc / xmlrpc.php
diff --git a/doc/xmlrpc.php b/doc/xmlrpc.php
new file mode 100644 (file)
index 0000000..6edce81
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+
+// Call helper
+
+function __call($method, $params = null)
+{
+    $request = xmlrpc_encode_request($method, $params, array('escaping' => 'markup', 'encoding' => 'utf-8'));
+    $context = stream_context_create(
+            array('http' => array(
+                        'method' => 'POST',
+                        'header' => 'Content-Type: text/xml',
+                        'content' => $request)));
+
+    $file = file_get_contents('http://localhost:8080/RPC2', false, $context);
+    $response = xmlrpc_decode($file);
+
+    if (is_array($response) && xmlrpc_is_fault($response)) {
+        trigger_error("xmlrpc: {$response['faultString']} ({$response['faultCode']})");
+    }
+
+    return $response;
+}
+
+// Usage samples
+
+print_r(__call('stargazer.info'));
+$data = __call('stargazer.login', array('admin', '123456'));
+if (isset($data['cookie'])) {
+    $cookie = $data['cookie'];
+    print_r($data);
+    print_r(__call('stargazer.get_tariffs', array($cookie)));
+    print_r(__call('stargazer.logout', array($data['cookie'])));
+}
+
+?>
+