public function process($f3, $params) { $client = new JsonRpcClient($this->has_server); $server_method = $params['module'] . "." . $params['method']; $response = $client->call(new RpcRequest($server_method, $f3->get("GET"))); if (property_exists($response, 'result')) { echo $response->result; } elseif (property_exists($response, 'error')) { echo $response->error->message; } else { echo print_r($response); } }
public function process($f3, $params) { //Uncomment next 2 lines to dropbox verification //echo $_GET['challenge']; //die(); $client = new JsonRpcClient($this->has_server); $response = $client->call(new RpcRequest('queue.process', array())); if (property_exists($response, 'result')) { echo $response->result; } elseif (property_exists($response, 'error')) { echo $response->error->message; } else { echo print_r($response); } }
public function __construct($rpcUrl, $username, $password) { parent::__construct($rpcUrl); $this->_username = $username; $this->_password = $password; $this->authenticate(); }
#!/usr/bin/php <?php require "../lib/jsonRpcClient.php"; $jsonrpc = new JsonRpcClient(); $jsonrpc->setHost('127.0.0.1'); $jsonrpc->setPort(3000); $jsonrpc->setPrefix('test.'); $jsonrpc->setReconnect(true); $jsonrpc->setDebug(true); $call = ""; try { $call = $jsonrpc->Test(7, 8); } catch (Exception $e) { print_r($e); exit(1); } echo "Succes\n"; print_r($call); exit(0);
<?php include '../JsonRpcClient.php'; $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $serverUrl = substr($url, 0, strpos($url, 'client.php')) . 'server.php'; $client = new JsonRpcClient($serverUrl); try { // Call in context of server $params = new StdClass(); $params->minuend = 42; $params->subtrahend = 23; $response = $client->subtract($params, 1); var_dump($response); $params = array('subtrahend' => 42, 'minuend' => 23); $response = $client->subtract($params, 2); var_dump($response); // Simple call $response = $client->call('subtract', array(42, 23), 3); var_dump($response); $response = $client->call('subtract', array('subtrahend' => 23, 'minuend' => 42), 4); var_dump($response); // Raw call $response = $client->rawcall('{"jsonrpc":"2.0","method":"subtract","params":{"subtrahend":23,"minuend":42},"id":5}'); var_dump($response); // Batch call $requests = array(); $requests[] = $client->prepare('subtract', 2, 1); $requests[] = $client->prepare('subtract', array(23, 52), 2); $requests[] = $client->prepare('subtract', array(45, 52), 3); $requests[] = $client->prepare('subtract', array(7, 52), 4); $requests[] = $client->prepare('foobar', array(7, 52), 5);
<?php include '../../JsonRpcClient.php'; $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $serverUrl = substr($url, 0, strpos($url, 'tests')) . 'server.php'; $client = new JsonRpcClient($serverUrl); function json_prettify($str) { $result = ''; $len = strlen($str); $pos = 0; $indent = ' '; $prev = ''; $newline = "\r\n"; for ($i = 0; $i < $len; $i++) { if ($str[$i] === '[' || $str[$i] === '{') { $pos++; if ($prev !== ',' && $prev !== '[' && $prev !== '' && $prev !== ':') { $result .= $newline . str_repeat($indent, $pos - 1); } $result .= $str[$i] . $newline . str_repeat($indent, $pos); } elseif ($str[$i] === ':') { $result .= $str[$i] . ' '; } elseif ($str[$i] === ',') { $result .= $str[$i] . $newline . str_repeat($indent, $pos); } elseif ($str[$i] === ']' || $str[$i] === '}') { $pos--; $result .= $newline . str_repeat($indent, $pos) . $str[$i]; } else { $result .= $str[$i]; }
public function addContactToGR($apikey, $campaign_id, $first_name = null, $last_name = null, $email, $customs) { // required params if (empty($apikey) || empty($campaign_id) || empty($email)) { return false; } try { $client = new JsonRpcClient($this->api_url); $name = !empty($first_name) ? $first_name . ' ' . $last_name : 'Friend'; $cycle_day = '0'; $check_cycle_day = $client->get_contacts($apikey, array('campaigns' => array($campaign_id), 'email' => array('EQUALS' => $email))); if (!empty($check_cycle_day) && isset($check_cycle_day[$campaign_id]['cycle_day'])) { $cycle_day = $check_cycle_day[$campaign_id]['cycle_day']; } $params = array('campaign' => $campaign_id, 'name' => $name, 'email' => $email, 'cycle_day' => $cycle_day, 'customs' => $customs); $result = $client->add_contact($apikey, $params); return $result; } catch (Exception $e) { return false; } }