- Refactors MailPoet mailer class + tests
- Includes MailPoet mailer inside Mailer router - Adjusts Newsletter router to work with new MailPoet mailer - Updates tests for all mailers
This commit is contained in:
@ -4,11 +4,11 @@ namespace MailPoet\Mailer\API;
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Mandrill {
|
||||
function __construct($api_key, $from_email, $from_name) {
|
||||
function __construct($apiKey, $fromEmail, $fromName) {
|
||||
$this->url = 'https://mandrillapp.com/api/1.0/messages/send.json';
|
||||
$this->api_key = $api_key;
|
||||
$this->from_name = $from_name;
|
||||
$this->from_email = $from_email;
|
||||
$this->apiKey = $apiKey;
|
||||
$this->fromName = $fromName;
|
||||
$this->fromEmail = $fromEmail;
|
||||
}
|
||||
|
||||
function send($newsletter, $subscriber) {
|
||||
@ -18,8 +18,11 @@ class Mandrill {
|
||||
$this->url,
|
||||
$this->request()
|
||||
);
|
||||
if(is_object($result) && get_class($result) === 'WP_Error') return false;
|
||||
return (!preg_match('!invalid!', $result['body']) === true && $result['response']['code'] === 200);
|
||||
return (
|
||||
!is_wp_error($result) === true &&
|
||||
!preg_match('!invalid!', $result['body']) === true &&
|
||||
wp_remote_retrieve_response_code($result) === 200
|
||||
);
|
||||
}
|
||||
|
||||
function processSubscriber($subscriber) {
|
||||
@ -30,20 +33,18 @@ class Mandrill {
|
||||
);
|
||||
}
|
||||
return array(
|
||||
array(
|
||||
'name' => (isset($subscriberData['name'])) ? $subscriberData['name'] : '',
|
||||
'email' => $subscriberData['email']
|
||||
)
|
||||
'email' => $subscriberData['email'],
|
||||
'name' => (isset($subscriberData['name'])) ? $subscriberData['name'] : ''
|
||||
);
|
||||
}
|
||||
|
||||
function getBody() {
|
||||
return array(
|
||||
'key' => $this->api_key,
|
||||
'key' => $this->apiKey,
|
||||
'message' => array(
|
||||
'from_email' => $this->from_email,
|
||||
'from_name' => $this->from_name,
|
||||
'to' => $this->subscriber,
|
||||
'from_email' => $this->fromEmail,
|
||||
'from_name' => $this->fromName,
|
||||
'to' => array($this->subscriber),
|
||||
'subject' => $this->newsletter['subject'],
|
||||
'html' => $this->newsletter['body']['html'],
|
||||
'text' => $this->newsletter['body']['text']
|
||||
|
Reference in New Issue
Block a user