Example #1
0
<?php

if (PHP_SAPI !== 'cli') {
    die("Testscript may only run in CLI-mode");
}
set_include_path(get_include_path() . PATH_SEPARATOR . '..');
require_once 'Services.php';
#$str_json = '{"domain_name":"bla.com","name":"bla.com","type":"A","content":"1.1.1.1","ttl":"86400","prio":""}';
$str_json = '{"domain_id":"3","name":"bla.com","type":"AA","content":"1.1.1.1","ttl":"86400","prio":""}';
$Obj_json = json_decode($str_json);
$data = json_encode($Obj_json);
#print $str_json->domain_name;
print $Obj_json->domain_name;
print "\n";
var_dump($data);
print "\n";
var_dump($Obj_json);
print "\n";
print "Output from JSONRPC: \n";
#var_dump(JSONRPC::record_add($Obj_json));
try {
    var_dump(JSONRPC::queue_record_add($Obj_json));
} catch (Exception $e) {
    print $e->getMessage();
}
<?php

/**
 * manages jingle packages and their contents
 * 
 */
$jsonrpc = new JSONRPC();
switch ($jsonrpc->get_method()) {
    case 'info':
        if (!isset($jsonrpc->params['id'])) {
            $jsonrpc->error('invalid package ID');
        }
        $package = JinglePackages::get_by_id($jsonrpc->params['id']);
        if ($package == null) {
            $jsonrpc->error('invalid package');
        }
        $jingles = array();
        foreach ($package->get_jingles() as $jingle) {
            $jingles[] = array('id' => $jingle->get_id(), 'title' => $jingle->get_title());
        }
        $jsonrpc->output(array('package' => array('id' => $package->get_id(), 'name' => $package->get_name(), 'description' => $package->get_description()), 'jingles' => $jingles));
        break;
    case 'delete_from':
        if (!isset($jsonrpc->params['package_id']) || !isset($jsonrpc->params['jingle_id'])) {
            $jsonrpc->error('invalid jingle or package');
        }
        $package = JinglePackages::get_by_id($jsonrpc->params['package_id']);
        $jingle = Jingles::get_by_id($jsonrpc->params['jingle_id']);
        $result = $package->delete_jingle($jingle);
        if ($result == true) {
            $jsonrpc->output('ok');