Implement support for additional endpoints in Free API [PREMIUM-4]

This commit is contained in:
Alexey Stoletniy
2017-02-22 11:19:35 +03:00
parent 063cc9edc3
commit 6c7cc5de0d

View File

@ -9,9 +9,14 @@ class API {
private $_method; private $_method;
private $_token; private $_token;
private $_endpoint_namespaces = array();
private $_endpoint_class; private $_endpoint_class;
private $_data = array(); private $_data = array();
function __construct() {
$this->addEndpointNamespace(__NAMESPACE__ . "\\Endpoints");
}
function init() { function init() {
// Admin Security token // Admin Security token
add_action( add_action(
@ -33,6 +38,8 @@ class API {
} }
function setupAjax() { function setupAjax() {
do_action('mailpoet_api_setup', array($this));
$this->getRequestData(); $this->getRequestData();
if($this->checkToken() === false) { if($this->checkToken() === false) {
@ -71,9 +78,12 @@ class API {
); );
$error_response->send(); $error_response->send();
} else { } else {
$this->_endpoint_class = ( foreach($this->_endpoint_namespaces as $namespace) {
__NAMESPACE__."\\Endpoints\\".ucfirst($this->_endpoint) $class_name = $namespace . "\\" . ucfirst($this->_endpoint);
); if(class_exists($class_name)) {
$this->_endpoint_class = $class_name;
}
}
$this->_data = isset($_POST['data']) $this->_data = isset($_POST['data'])
? stripslashes_deep($_POST['data']) ? stripslashes_deep($_POST['data'])
@ -149,4 +159,8 @@ class API {
$global .= '</script>'; $global .= '</script>';
echo $global; echo $global;
} }
function addEndpointNamespace($namespace) {
$this->_endpoint_namespaces[] = $namespace;
}
} }