Moves current API under JSON namespace

This commit is contained in:
Vlad
2017-05-09 20:17:29 -04:00
parent b727ba423e
commit 398d7d3d80
38 changed files with 86 additions and 86 deletions

View File

@ -0,0 +1,42 @@
<?php
namespace MailPoet\API\JSON\Endpoints\v1;
use MailPoet\API\JSON\Endpoint as APIEndpoint;
use MailPoet\API\JSON\Error as APIError;
use MailPoet\Mailer\MailerLog;
if(!defined('ABSPATH')) exit;
class Mailer extends APIEndpoint {
function send($data = array()) {
try {
$mailer = new \MailPoet\Mailer\Mailer(
(isset($data['mailer'])) ? $data['mailer'] : false,
(isset($data['sender'])) ? $data['sender'] : false,
(isset($data['reply_to'])) ? $data['reply_to'] : false
);
$extra_params = array(
'test_email' => true
);
$result = $mailer->send($data['newsletter'], $data['subscriber'], $extra_params);
} catch(\Exception $e) {
return $this->errorResponse(array(
$e->getCode() => $e->getMessage()
));
}
if($result['response'] === false) {
$error = sprintf(
__('The email could not be sent: %s', 'mailpoet'),
$result['error_message']
);
return $this->errorResponse(array(APIError::BAD_REQUEST => $error));
} else {
return $this->successResponse(null);
}
}
function resumeSending() {
MailerLog::resumeSending();
return $this->successResponse(null);
}
}