Moves current API under JSON namespace
This commit is contained in:
35
lib/API/JSON/Endpoint.php
Normal file
35
lib/API/JSON/Endpoint.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace MailPoet\API\JSON;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
abstract class Endpoint {
|
||||
|
||||
public $permissions = array();
|
||||
|
||||
function successResponse(
|
||||
$data = array(), $meta = array(), $status = Response::STATUS_OK
|
||||
) {
|
||||
return new SuccessResponse($data, $meta, $status);
|
||||
}
|
||||
|
||||
function errorResponse(
|
||||
$errors = array(), $meta = array(), $status = Response::STATUS_NOT_FOUND
|
||||
) {
|
||||
if(empty($errors)) {
|
||||
$errors = array(
|
||||
Error::UNKNOWN => __('An unknown error occurred.', 'mailpoet')
|
||||
);
|
||||
}
|
||||
return new ErrorResponse($errors, $meta, $status);
|
||||
}
|
||||
|
||||
function badRequest($errors = array(), $meta = array()) {
|
||||
if(empty($errors)) {
|
||||
$errors = array(
|
||||
Error::BAD_REQUEST => __('Invalid request parameters', 'mailpoet')
|
||||
);
|
||||
}
|
||||
return new ErrorResponse($errors, $meta, Response::STATUS_BAD_REQUEST);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user