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