updated mailer endpoint
This commit is contained in:
@ -1,11 +1,12 @@
|
||||
<?php
|
||||
namespace MailPoet\API\Endpoints;
|
||||
use MailPoet\API\Endpoint as APIEndpoint;
|
||||
use MailPoet\API\Error as APIError;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Mailer {
|
||||
function send($data) {
|
||||
$response = array();
|
||||
class Mailer extends APIEndpoint {
|
||||
function send($data = array()) {
|
||||
try {
|
||||
$mailer = new \MailPoet\Mailer\Mailer(
|
||||
(isset($data['mailer'])) ? $data['mailer'] : false,
|
||||
@ -14,10 +15,17 @@ class Mailer {
|
||||
);
|
||||
$result = $mailer->send($data['newsletter'], $data['subscriber']);
|
||||
} catch(\Exception $e) {
|
||||
$result = false;
|
||||
$response['errors'] = array($e->getMessage());
|
||||
return $this->errorResponse(array(
|
||||
$e->getCode() => $e->getMessage()
|
||||
));
|
||||
}
|
||||
|
||||
if($result === false) {
|
||||
return $this->errorResponse(array(
|
||||
APIError::BAD_REQUEST => __("The email could not be sent. Please check your settings.")
|
||||
));
|
||||
} else {
|
||||
return $this->successResponse(null);
|
||||
}
|
||||
$response['result'] = ($result) ? true : false;
|
||||
return $response;
|
||||
}
|
||||
}
|
@ -27,7 +27,7 @@ abstract class Response {
|
||||
if(!empty($this->meta)) {
|
||||
$response['meta'] = $this->meta;
|
||||
}
|
||||
if(!empty($data)) {
|
||||
if($data !== null) {
|
||||
$response = array_merge($response, $data);
|
||||
}
|
||||
|
||||
|
@ -6,12 +6,14 @@ if(!defined('ABSPATH')) exit;
|
||||
class SuccessResponse extends Response {
|
||||
public $data;
|
||||
|
||||
function __construct($data = array(), $meta = array(), $status = self::STATUS_OK) {
|
||||
function __construct($data = null, $meta = null, $status = self::STATUS_OK) {
|
||||
parent::__construct($status, $meta);
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
function getData() {
|
||||
if($this->data === null) return null;
|
||||
|
||||
return array(
|
||||
'data' => $this->data
|
||||
);
|
||||
|
Reference in New Issue
Block a user