public function validate()
{
if (strlen($this->_csdl) == 0) {
throw new DataSift_Exception_InvalidData('Cannot validate an empty definition.');
}
try {
$res = $this->_user->post('validate', array('csdl' => $this->_csdl));
if (isset($res['created_at'])) {
$this->_created_at = strtotime($res['created_at']);
} else {
throw new DataSift_Exception_CompileFailed('Compiled successfully but no created_at in the response');
}
if (isset($res['dpu'])) {
$this->_total_dpu = $res['dpu'];
} else {
throw new DataSift_Exception_CompileFailed('Compiled successfully but no DPU in the response');
}
} catch (DataSift_Exception_APIError $e) {
// Reset the hash
$this->clearHash();
switch ($e->getCode()) {
case 400:
// Compilation failed, we should have an error message
if (!empty($res['error'])) {
throw new DataSift_Exception_CompileFailed($res['error']);
} else {
throw new DataSift_Exception_CompileFailed('No error message was provided');
}
break;
default:
throw new DataSift_Exception_CompileFailed('Unexpected APIError code: ' . $e->getCode() . ' [' . $e->getMessage() . ']');
}
}
}