- Updates constant names
This commit is contained in:
@ -10,13 +10,13 @@ class API {
|
||||
public $endpoint;
|
||||
public $action;
|
||||
public $data;
|
||||
const API_NAME = 'mailpoet_api';
|
||||
const NAME = 'mailpoet_api';
|
||||
const ENDPOINT_NAMESPACE = '\MailPoet\API\Endpoints\\';
|
||||
const API_RESPONSE_CODE_ERROR = 404;
|
||||
const RESPONSE_ERROR = 404;
|
||||
|
||||
function __construct($api_data = false) {
|
||||
$api_data = ($api_data) ? $api_data : $_GET;
|
||||
$this->api_request = isset($api_data[self::API_NAME]);
|
||||
$this->api_request = isset($api_data[self::NAME]);
|
||||
$this->endpoint = isset($api_data['endpoint']) ?
|
||||
Helpers::underscoreToCamelCase($api_data['endpoint']) :
|
||||
false;
|
||||
@ -32,7 +32,7 @@ class API {
|
||||
$endpoint = self::ENDPOINT_NAMESPACE . ucfirst($this->endpoint);
|
||||
if(!$this->api_request) return;
|
||||
if(!$this->endpoint || !class_exists($endpoint)) {
|
||||
$this->terminateRequest(self::API_RESPONSE_CODE_ERROR, __('Invalid API endpoint.'));
|
||||
$this->terminateRequest(self::RESPONSE_ERROR, __('Invalid API endpoint.'));
|
||||
}
|
||||
$this->callEndpoint(
|
||||
$endpoint,
|
||||
@ -43,7 +43,7 @@ class API {
|
||||
|
||||
function callEndpoint($endpoint, $action, $data) {
|
||||
if(!method_exists($endpoint, $action)) {
|
||||
$this->terminateRequest(self::API_RESPONSE_CODE_ERROR, __('Invalid API action.'));
|
||||
$this->terminateRequest(self::RESPONSE_ERROR, __('Invalid API action.'));
|
||||
}
|
||||
call_user_func(
|
||||
array(
|
||||
@ -58,7 +58,7 @@ class API {
|
||||
$data = base64_decode($data);
|
||||
return (is_serialized($data)) ?
|
||||
unserialize($data) :
|
||||
self::terminateRequest(self::API_RESPONSE_CODE_ERROR, __('Invalid API data format.'));
|
||||
self::terminateRequest(self::RESPONSE_ERROR, __('Invalid API data format.'));
|
||||
}
|
||||
|
||||
static function encodeRequestData($data) {
|
||||
@ -68,7 +68,7 @@ class API {
|
||||
static function buildRequest($endpoint, $action, $data) {
|
||||
$data = self::encodeRequestData($data);
|
||||
$params = array(
|
||||
self::API_NAME => '',
|
||||
self::NAME => '',
|
||||
'endpoint' => $endpoint,
|
||||
'action' => $action,
|
||||
'data' => $data
|
||||
|
@ -45,7 +45,7 @@ class Url {
|
||||
}
|
||||
|
||||
$params = array(
|
||||
API::API_NAME,
|
||||
API::NAME,
|
||||
'endpoint='.Subscription::ENDPOINT,
|
||||
'action='.$action,
|
||||
'data='.API::encodeRequestData($data)
|
||||
|
Reference in New Issue
Block a user