/** * Recebe um JSON no formato: * { * "nome":"valor", * "sobrenome":"valor" * } */ private function insertContato() { if ($this->get_request_method() !== 'POST') { $this->response('', API::STATUS_NOT_ACCEPTABLE); } $json = json_decode(file_get_contents("php://input"), true); if (!empty($json)) { $objeto = DBJson::jsonToContato($json); $objeto->correctNullFields(); $objeto = DBObject::insertContato($objeto); if (!is_null($objeto)) { $success = array('status' => 'Sucesso', 'msg' => 'Contato criado com sucesso.', 'data' => DBJson::contatoToJson($objeto)); $this->response($this->json($success), API::STATUS_OK); } else { $this->response('', API::STATUS_INTERNAL_SERVER_ERROR); } } else { $this->response('', API::STATUS_NO_CONTENT); } }