/** * DO NOT USE, PRIVATE METHOD! must be public for unittests * @param string $uid scheduler.unique_id * @param array $params hash keys (all optional): page, per_page * @return Hypercharge\RecurringScheduler */ static function index($uid, $params = array()) { Helper::validateUniqueId($uid); JsonSchema::validate('scheduler_transactions_index', $params); $factory = Config::getFactory(); $url = $factory->createUrl(array('scheduler', $uid, 'transactions'), $params); $response = $factory->createHttpsClient()->jsonGet($url); if ($response->entries_base_type != 'PaymentTransaction') { throw new Errors\ResponseFormatError('entries_base_type expected "PaymentTransaction" but was: ' . $response->entries_base_type, $response); } return $response; }
<?php require_once 'JsonSchema.php'; require_once 'JsonSchemaUndefined.php'; Dbg::$quietMode = true; if ($_REQUEST['schema']) { $schema = json_decode($_REQUEST['schema']); if (!$schema) { trigger_error('Could not parse the SCHEMA object.', E_USER_ERROR); } } else { $schema = null; } $json = json_decode($_REQUEST['json']); if (!$json) { trigger_error('Could not parse the JSON object.', E_USER_ERROR); } if ($_REQUEST['typeCastMode'] == 'true') { JsonSchema::$checkMode = JsonSchema::CHECK_MODE_TYPE_CAST; } $result = JsonSchema::validate($json, $schema); header('Content-type: application/x-json'); echo json_encode($result);
/** * @param string $uid the scheduler.unique_id * @param array $data key-value-Hash, Scheduler fields to update * @return Hypercharge\Scheduler */ static function update($uid, $data) { Helper::validateUniqueId($uid); JsonSchema::validate('scheduler_update', $data); $factory = Config::getFactory(); $url = $factory->createUrl(array('scheduler', $uid)); $response = $factory->createHttpsClient()->jsonPut($url, $data); return new Scheduler($response); }
public function ValidateJSONMAnifestAgainstShema($json) { include_once dirname(__FILE__) . '/../extensions/JSONShemaValidator/JsonSchema.php'; include_once dirname(__FILE__) . '/../extensions/JSONShemaValidator/JsonSchemaUndefined.php'; $shema = file_get_contents(dirname(__FILE__) . '/../extensions/JSONShemaValidator/Bober_Interacitve_Task_Object_Shema.json'); $schema = json_decode($shema); if (!$schema) { return array('return' => false, 'error' => 'Could not parse the SCHEMA object.'); } else { $schema = null; } $json = json_decode($json); if (!$json) { switch (json_last_error()) { case JSON_ERROR_NONE: echo ' - No errors'; break; case JSON_ERROR_DEPTH: echo ' - Maximum stack depth exceeded'; break; case JSON_ERROR_STATE_MISMATCH: echo ' - Underflow or the modes mismatch'; break; case JSON_ERROR_CTRL_CHAR: echo ' - Unexpected control character found'; break; case JSON_ERROR_SYNTAX: echo ' - Syntax error, malformed JSON'; break; case JSON_ERROR_UTF8: echo ' - Malformed UTF-8 characters, possibly incorrectly encoded'; break; default: echo ' - Unknown error'; break; } return array('return' => false, 'error' => 'Could not parse the JSON object.'); } $result = json_decode(json_encode(JsonSchema::validate($json, $schema)), true); return array('return' => $result['valid'], 'error' => implode("\n", $result['errors'])); }