<?php require 'kanboard_mailtasks_config.inc.php'; require 'kanboard_mailtasks_helpers.php'; require '../vendor/autoload.php'; use JsonRPC\Client; $projects = array(); $tasks = array(); // Let's call Kanboard $client = new JsonRPC\Client($jsonrpc_url); $client->authentication($jsonrpc_auth_name, $jsonrpc_auth_token); // We need the projects list $projects_tmp = $client->execute('getAllProjects'); // For each project, get identifier (if existing) and numeric ID foreach ($projects_tmp as $proj) { if ($proj['identifier']) { $projects[$proj['identifier']]['id'] = $proj['id']; } } // Now to the mails $imap_client = imap_open($imap_server, $imap_account, $imap_pass); if (!$imap_client) { echo imap_last_error(); exit; } // Give me the unseen mails list $emails_list = imap_search($imap_client, 'UNSEEN'); if ($emails_list) { // One by one we fetch unseen mails foreach ($emails_list as $email_id) { do_debug('Open mail ' . $email_id);
/** * Make a call to Aria2 RPC * * @param string $name * @param array $arguments * * @return mixed */ public function __call($name, $arguments) { if ($this->token) { array_unshift($arguments, 'token:' . $this->token); } return $this->client->execute('aria2.' . $name, $arguments); }
function Run() { $mode = $this->GetParam('mode', 'str'); $server = $this->GetParam('server', 'str'); $title = $this->GetParam('title', 'str'); $message = $this->GetParam('message', 'raw'); $image = $this->GetParam('image', 'str'); $time = $this->GetParam('time', 'float'); $custom = $this->GetParam('custom', 'raw'); $message = str_replace('{custom}', $custom, $message); if ($server) { $server_url = "http://{$server}/jsonrpc"; require_once $this->conf['libs']['jsonrpc_client']; $o_jsonrpc = new Client($server_url); //$o_jsonrpc = new Client($server_url,5,true); //debug } else { $this->DisplayJson(false, array('code' => 500, 'message' => "Server is not set!")); } $result = ''; $p = array(); $missing_parameters = true; if ($mode == 'notify') { if ($title and $message) { $missing_parameters = false; $method = "GUI.ShowNotification"; $p['title'] = $title; $p['message'] = $message; $image and $p['image'] = $image; $time and $p['displaytime'] = round($time * 1000); } } elseif ($mode == 'pause') { $missing_parameters = false; $method = "Player.PlayPause"; $p['playerid'] = 1; } else { $this->DisplayJson(false, array('code' => 404, 'message' => "Invalid mode : {$mode}")); } if ($missing_parameters) { $this->DisplayJson(false, array('code' => 500, 'message' => "Missing some parameters!")); } $result = $o_jsonrpc->execute($method, $p); $data = array("sent_url" => $server_url, "sent_method" => $method, "sent_parameters" => $p, "api_result" => $result); if ($result == 'OK') { $data['code'] = 200; $data['message'] = "Sucessfully sent mode: {$mode}"; $this->DisplayJson(true, $data); } else { $data['code'] = 500; $data['message'] = "Request failed!"; $this->DisplayJson(false, $data); } }
/** * Inits Client Connection based on instance params * @return JsonRPC\Client */ private function connection_init() { $opts = $this->config; // Headers format $headers = []; foreach ($opts['headers'] as $key => $value) { $headers[] = "{$key}: {$value}"; } $connection = new JsonRPC\Client($opts['url'], $opts['timeout'], $headers); $connection->ssl_verify_peer = $opts['ssl_verify_peer']; $connection->debug = $opts['debug']; if (isset($opts['username']) && $opts['username']) { $connection->authentication($opts['username'], $opts['password']); } return $connection; }
public function testBatchRequest() { $client = new Client('http://localhost/'); $batch = $client->batch(); $this->assertInstanceOf('JsonRpc\\Client', $batch); $this->assertTrue($client->is_batch); $batch->random(1, 30); $batch->add(3, 5); $batch->execute('foo', array('p1' => 42, 'p3' => 3)); $this->assertNotEmpty($client->batch); $this->assertEquals(3, count($client->batch)); $this->assertEquals('random', $client->batch[0]['method']); $this->assertEquals('add', $client->batch[1]['method']); $this->assertEquals('foo', $client->batch[2]['method']); $this->assertEquals(array(1, 30), $client->batch[0]['params']); $this->assertEquals(array(3, 5), $client->batch[1]['params']); $this->assertEquals(array('p1' => 42, 'p3' => 3), $client->batch[2]['params']); $batch = $client->batch(); $this->assertInstanceOf('JsonRpc\\Client', $batch); $this->assertTrue($client->is_batch); $this->assertEmpty($client->batch); }
<?php require '../vendor/autoload.php'; // From https://github.com/fguillot/JsonRPC use JsonRPC\Client; $client = new Client('http://geocoding.geo.census.gov/geocoder/geographies'); $client->debug = true; $result = $client->execute('address', array('street' => '210 W 19th terrace', 'city' => 'Kansas City', 'state' => 'MO', 'zip' => '', 'benchmark' => 4, 'vintage' => 4, 'format' => 'json')); var_dump($result);
$trellokey = $argv[3]; $trellotoken = $argv[4]; $trelloboard = $argv[5]; $userId = null; if (isset($argv[6])) { $userId = $argv[6]; } $jsonString = file_get_contents("https://trello.com/1/boards/" . $trelloboard . "?key=" . $trellokey . "&token=" . $trellotoken); $trelloObj = json_decode($jsonString); if (empty($trelloObj)) { printf($jsonString); printf('Unable to parse JSON response, is it valid? %s', json_last_error_msg()); die(1); } //initialize the client $client = new Client($server); $client->authentication('jsonrpc', $token); //verify that we can connect $projects = null; try { $projects = $client->getAllProjects(); } catch (RuntimeException $e) { $projects = null; //explicitly set it to null, to trigger an error } $users = $client->getAllUsers(); foreach ($users as $user) { if ($user['username'] == $userId || $userId == null) { $userId = $user['id']; } }
/** * Submits raw transaction (serialized, hex-encoded) to local node and network. * Returns the transaction hash in hex * * @param $hex * @param bool $allowHighFees * @return mixed */ public function sendRawTransaction($hex, $allowHighFees = false) { return $this->jsonRPCClient->execute("sendrawtransaction", array($hex, $allowHighFees)); }
/** * @param $host * @param $port * @param int $timeout * @param array $headers */ public function __construct($host, $port, $timeout = 5, array $headers = array()) { $url = "http://{$host}:{$port}/"; parent::__construct($url, $timeout, $headers); }
/** * @expectedException \JsonRpc\ClientException * @expectedExceptionCode 0 * @expectedExceptionMessage Unknown error */ public function testUnknownError() { $id = 9; $transport = $this->getTransportMockSendRequest(self::HTTP_CODE_ERROR, "{\"jsonrpc\":\"2.0\",\"error\":{},\"id\":{$id}}"); $client = new Client($transport); $client->call(self::CALL_METHOD, []); }
<pre><?php require './vendor/autoload.php'; use JsonRPC\Client; $client = new Client('http://localhost/server.php'); $result = $client->execute('doSomething', [3, 5]); var_dump($result);
<?php require __DIR__ . '/../vendor/autoload.php'; spl_autoload_register(function ($class) { $prefix = 'wdst\\IcrForms\\'; $base_dir = __DIR__ . '/../src/'; $len = strlen($prefix); if (strncmp($prefix, $class, $len) !== 0) { return; } $relative_class = substr($class, $len); $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php'; if (file_exists($file)) { require $file; } }); use JsonRPC\Client as JsonRPCClient; $Client = new JsonRPCClient('http://api.json/index.php'); $filename = '123.png'; $fb = fopen($filename, 'rb'); $blobdata = fread($fb, filesize($filename)); fclose($fb); //$blobHandle = fbsql_create_blob($blobdata, $link); $guid = uniqid(); try { $res = $Client->saveBlobs($guid, bin2hex($blobdata)); } catch (Exception $e) { print_r($e); } //print_r($res); print $guid . PHP_EOL;
<?php require_once __DIR__ . '/../vendor/autoload.php'; use JsonRPC\Client; $client = new Client('http://127.0.0.1/rpc'); $client->notify('example.notify'); echo 'Notify sended' . PHP_EOL;
protected function _call($method, $params = []) { array_unshift($params, $this->_key); $client = new Client(self::API_PATH); return $client->execute($method, $params); }
<?php // TODO: // * Empty entries // * API rate-limited? require "config.php"; require __DIR__ . '/vendor/autoload.php'; use JsonRPC\Client; try { // Create API connection $client = new Client($BASE_MINIFLUX_URL . '/jsonrpc.php'); $client->authentication('admin', $API_PASSWORD); // Handle mark as read if (!empty($_GET["entry"])) { $client->execute('item.mark_as_read', ['item_id' => $_GET['entry']]); exit('{}'); } if (!empty($_GET["all"])) { $client->execute('item.mark_all_as_read'); exit('{}'); } // Fetch data $feeds = $client->execute('feed.list'); $entries = []; foreach ($feeds as $feed) { if (!$feed["enabled"]) { continue; } // Update old feeds if (time() - $feed["last_checked"] >= 3600) { $client->execute('feed.update', ["feed_id" => $feed["id"]]);
<?php require_once __DIR__ . '/../vendor/autoload.php'; use JsonRPC\Client; use JsonRPC\Exception\RPC as RPCException; use JsonRPC\Exception\Json as JsonException; use JsonRPC\Exception\Curl as CurlException; try { $client = new Client('http://127.0.0.1/rpc'); $response = $client->request('example.method', ['foo' => 'bar'], 100); printf('result: %s' . PHP_EOL, $response->result); } catch (RPCException $e) { printf('RPC Execption: %d - %s' . PHP_EOL, $e->getCode(), $e->getMessage()); } catch (JsonException $e) { printf('JSON Exception %d - %s' . PHP_EOL, $e->getCode(), $e->getMessage()); } catch (CurlException $e) { printf('cURL Exception %d - %s' . PHP_EOL, $e->getCode(), $e->getMessage()); }
function __construct($c) { $this->apiKey = $c["enjinAPIKey"]; $this->c = $c; parent::__construct($c["siteURL"] . "/api/v1/api.php"); }
public function testNotify() { $client = new Client(RPC_URL); $response = $client->notify('method.example', ['foo' => 'bar']); $this->assertEmpty($response); }