/** * @api {post} /verticals POST /verticals * @apiExample Example usage: * curl -i -X POST "http://apibeta.compargo.com/v1/verticals/?countryCode=ph&language=en" * -H "X-COMPARE-REST-API-KEY: 1234567890" * -d "name=Telco&description=Telco&status=1" * * @apiDescription Create a new Vertical * @apiName Post * @apiGroup Verticals * * @apiHeader {String} X-COMPARE-REST-API-KEY Vertical unique access-key. * * @apiParam {String} language Mandatory Language. * @apiParam {String} countryCode Mandatory Country code. * @apiParam {String} name Mandatory Name of the Vertical. * @apiParam {String} [description] Optional Description of the Vertical. * @apiParam {String} [alias] Optional Alias of the Vertical. * @apiParam {String} [status=0] Optional Status of the Vertical. * @apiParam {String} [createdBy] Optional ID of the User who created the Vertical. * @apiParam {String} [modifiedBy] Optional ID of the User who modified the Vertical. * * @apiSuccess {String} id The new Vertical-ID. * * @apiSuccessExample Success-Response: * HTTP/1.1 200 OK * { * "id": "d49188a6-1d4e-11e4-b32d-eff91066cccf" * } * * @apiError BadInputParameter The request cannot be fulfilled due to bad syntax. * * @apiErrorExample Error-Response: * HTTP/1.1 400 * { * "error": "BadInputParameter" * } * * @apiError InvalidAccessToken The access token is invalid. * * @apiErrorExample Error-Response: * HTTP/1.1 401 Unauthorized * { * "error": "InvalidAccessToken" * } * * @apiError MissingAuthenticationCredentials The authentication credentials are missing. * * @apiErrorExample Error-Response: * HTTP/1.1 401 Unauthorized * { * "error": "MissingAuthenticationCredentials" * } * * @apiError RouteNotFound That route was not found on the server. * * @apiErrorExample Error-Response: * HTTP/1.1 404 * { * "error": "RouteNotFound" * } */ public function post() { $results = array(); $request = $this->di->get('request'); $data = $request->getPost(); if (!empty($data)) { $vertical = new Verticals(); $data['id'] = $vertical->id; $data['name'] = isset($data['name']) ? $data['name'] : ''; $data['description'] = isset($data['description']) ? $data['description'] : ''; $data['status'] = isset($data['status']) ? $data['status'] : 0; if (isset($data['status'])) { $data['active'] = $data['status'] != Verticals::ACTIVE ? 0 : 1; } $data['createdBy'] = isset($data['createdBy']) ? $data['createdBy'] : ''; $data['modifiedBy'] = isset($data['modifiedBy']) ? $data['modifiedBy'] : ''; if ($vertical->save($data)) { $results['id'] = $vertical->id; } else { throw new HTTPException("Request unable to be followed due to semantic errors", 422, array('dev' => $vertical->getMessages(), 'internalCode' => 'P1000', 'more' => '')); } } else { throw new HTTPException("The request cannot be fulfilled due to bad syntax.", 400, array('dev' => 'A required field is missing.', 'internalCode' => 'P1000', 'more' => '')); } return $results; }