Rename checkAPIKey to checkMSSKey (MailPoet Sending Service) [PREMIUM-4]
This commit is contained in:
@ -26,7 +26,7 @@ class Services extends APIEndpoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$result = $this->bridge->checkAPIKey($key);
|
$result = $this->bridge->checkMSSKey($key);
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
return $this->errorResponse(array(
|
return $this->errorResponse(array(
|
||||||
$e->getCode() => $e->getMessage()
|
$e->getCode() => $e->getMessage()
|
||||||
|
@ -87,7 +87,7 @@ class SendingServiceKeyCheck {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$mailer_config = Mailer::getMailerConfig();
|
$mailer_config = Mailer::getMailerConfig();
|
||||||
$result = $this->bridge->checkAPIKey($mailer_config['mailpoet_api_key']);
|
$result = $this->bridge->checkMSSKey($mailer_config['mailpoet_api_key']);
|
||||||
$this->bridge->updateSubscriberCount($result);
|
$this->bridge->updateSubscriberCount($result);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$result = false;
|
$result = false;
|
||||||
|
@ -54,9 +54,9 @@ class Bridge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkAPIKey($api_key) {
|
function checkMSSKey($api_key) {
|
||||||
$this->initApi($api_key);
|
$this->initApi($api_key);
|
||||||
$result = $this->api->checkAPIKey();
|
$result = $this->api->checkMSSKey();
|
||||||
return $this->processAPIKeyCheckResult($result);
|
return $this->processAPIKeyCheckResult($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +157,7 @@ class Bridge {
|
|||||||
$api_key_set = !empty($settings[Mailer::MAILER_CONFIG_SETTING_NAME]['mailpoet_api_key']);
|
$api_key_set = !empty($settings[Mailer::MAILER_CONFIG_SETTING_NAME]['mailpoet_api_key']);
|
||||||
$premium_key_set = !empty($settings['premium']['premium_key']);
|
$premium_key_set = !empty($settings['premium']['premium_key']);
|
||||||
if($api_key_set && self::isMPSendingServiceEnabled()) {
|
if($api_key_set && self::isMPSendingServiceEnabled()) {
|
||||||
$result = $this->checkAPIKey($settings[Mailer::MAILER_CONFIG_SETTING_NAME]['mailpoet_api_key']);
|
$result = $this->checkMSSKey($settings[Mailer::MAILER_CONFIG_SETTING_NAME]['mailpoet_api_key']);
|
||||||
$this->updateSubscriberCount($result);
|
$this->updateSubscriberCount($result);
|
||||||
}
|
}
|
||||||
if($premium_key_set) {
|
if($premium_key_set) {
|
||||||
|
@ -24,7 +24,7 @@ class API {
|
|||||||
$this->setKey($api_key);
|
$this->setKey($api_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkAPIKey() {
|
function checkMSSKey() {
|
||||||
$result = $this->request(
|
$result = $this->request(
|
||||||
$this->url_me,
|
$this->url_me,
|
||||||
array('site' => home_url())
|
array('site' => home_url())
|
||||||
|
@ -20,7 +20,7 @@ class ServicesTest extends MailPoetTest {
|
|||||||
function testItRespondsWithSuccessIfMSSKeyIsValid() {
|
function testItRespondsWithSuccessIfMSSKeyIsValid() {
|
||||||
$this->services_endpoint->bridge = Stub::make(
|
$this->services_endpoint->bridge = Stub::make(
|
||||||
new Bridge(),
|
new Bridge(),
|
||||||
array('checkAPIKey' => array('state' => Bridge::MAILPOET_KEY_VALID)),
|
array('checkMSSKey' => array('state' => Bridge::MAILPOET_KEY_VALID)),
|
||||||
$this
|
$this
|
||||||
);
|
);
|
||||||
$response = $this->services_endpoint->verifyMailPoetKey($this->data);
|
$response = $this->services_endpoint->verifyMailPoetKey($this->data);
|
||||||
@ -30,7 +30,7 @@ class ServicesTest extends MailPoetTest {
|
|||||||
function testItRespondsWithErrorIfMSSKeyIsInvalid() {
|
function testItRespondsWithErrorIfMSSKeyIsInvalid() {
|
||||||
$this->services_endpoint->bridge = Stub::make(
|
$this->services_endpoint->bridge = Stub::make(
|
||||||
new Bridge(),
|
new Bridge(),
|
||||||
array('checkAPIKey' => array('state' => Bridge::MAILPOET_KEY_INVALID)),
|
array('checkMSSKey' => array('state' => Bridge::MAILPOET_KEY_INVALID)),
|
||||||
$this
|
$this
|
||||||
);
|
);
|
||||||
$response = $this->services_endpoint->verifyMailPoetKey($this->data);
|
$response = $this->services_endpoint->verifyMailPoetKey($this->data);
|
||||||
@ -41,7 +41,7 @@ class ServicesTest extends MailPoetTest {
|
|||||||
$date = new DateTime;
|
$date = new DateTime;
|
||||||
$this->services_endpoint->bridge = Stub::make(
|
$this->services_endpoint->bridge = Stub::make(
|
||||||
new Bridge(),
|
new Bridge(),
|
||||||
array('checkAPIKey' => array(
|
array('checkMSSKey' => array(
|
||||||
'state' => Bridge::MAILPOET_KEY_EXPIRING,
|
'state' => Bridge::MAILPOET_KEY_EXPIRING,
|
||||||
'data' => array('expire_at' => $date->format('c'))
|
'data' => array('expire_at' => $date->format('c'))
|
||||||
)),
|
)),
|
||||||
@ -55,7 +55,7 @@ class ServicesTest extends MailPoetTest {
|
|||||||
function testItRespondsWithErrorIfServiceIsUnavailableDuringMSSCheck() {
|
function testItRespondsWithErrorIfServiceIsUnavailableDuringMSSCheck() {
|
||||||
$this->services_endpoint->bridge = Stub::make(
|
$this->services_endpoint->bridge = Stub::make(
|
||||||
new Bridge(),
|
new Bridge(),
|
||||||
array('checkAPIKey' => array('code' => Bridge::CHECK_ERROR_UNAVAILABLE)),
|
array('checkMSSKey' => array('code' => Bridge::CHECK_ERROR_UNAVAILABLE)),
|
||||||
$this
|
$this
|
||||||
);
|
);
|
||||||
$response = $this->services_endpoint->verifyMailPoetKey($this->data);
|
$response = $this->services_endpoint->verifyMailPoetKey($this->data);
|
||||||
@ -66,7 +66,7 @@ class ServicesTest extends MailPoetTest {
|
|||||||
function testItRespondsWithErrorIfMSSCheckThrowsAnException() {
|
function testItRespondsWithErrorIfMSSCheckThrowsAnException() {
|
||||||
$this->services_endpoint->bridge = Stub::make(
|
$this->services_endpoint->bridge = Stub::make(
|
||||||
new Bridge(),
|
new Bridge(),
|
||||||
array('checkAPIKey' => function() { throw new \Exception('test'); }),
|
array('checkMSSKey' => function() { throw new \Exception('test'); }),
|
||||||
$this
|
$this
|
||||||
);
|
);
|
||||||
$response = $this->services_endpoint->verifyMailPoetKey($this->data);
|
$response = $this->services_endpoint->verifyMailPoetKey($this->data);
|
||||||
|
@ -95,7 +95,7 @@ class SendingServiceKeyCheckTest extends MailPoetTest {
|
|||||||
function testItProcesses() {
|
function testItProcesses() {
|
||||||
$this->sskeycheck->bridge = Stub::make(
|
$this->sskeycheck->bridge = Stub::make(
|
||||||
new Bridge,
|
new Bridge,
|
||||||
array('checkAPIKey' => array('code' => Bridge::MAILPOET_KEY_VALID)),
|
array('checkMSSKey' => array('code' => Bridge::MAILPOET_KEY_VALID)),
|
||||||
$this
|
$this
|
||||||
);
|
);
|
||||||
$this->setMailPoetSendingMethod();
|
$this->setMailPoetSendingMethod();
|
||||||
@ -113,7 +113,7 @@ class SendingServiceKeyCheckTest extends MailPoetTest {
|
|||||||
function testItProcessesSendingServiceKeyCheckQueue() {
|
function testItProcessesSendingServiceKeyCheckQueue() {
|
||||||
$this->sskeycheck->bridge = Stub::make(
|
$this->sskeycheck->bridge = Stub::make(
|
||||||
new Bridge,
|
new Bridge,
|
||||||
array('checkAPIKey' => array('code' => Bridge::MAILPOET_KEY_VALID)),
|
array('checkMSSKey' => array('code' => Bridge::MAILPOET_KEY_VALID)),
|
||||||
$this
|
$this
|
||||||
);
|
);
|
||||||
$this->setMailPoetSendingMethod();
|
$this->setMailPoetSendingMethod();
|
||||||
@ -126,7 +126,7 @@ class SendingServiceKeyCheckTest extends MailPoetTest {
|
|||||||
function testItReschedulesCheckOnException() {
|
function testItReschedulesCheckOnException() {
|
||||||
$this->sskeycheck->bridge = Stub::make(
|
$this->sskeycheck->bridge = Stub::make(
|
||||||
new Bridge,
|
new Bridge,
|
||||||
array('checkAPIKey' => function () { throw new \Exception(); }),
|
array('checkMSSKey' => function () { throw new \Exception(); }),
|
||||||
$this
|
$this
|
||||||
);
|
);
|
||||||
$this->setMailPoetSendingMethod();
|
$this->setMailPoetSendingMethod();
|
||||||
@ -140,7 +140,7 @@ class SendingServiceKeyCheckTest extends MailPoetTest {
|
|||||||
function testItReschedulesCheckOnError() {
|
function testItReschedulesCheckOnError() {
|
||||||
$this->sskeycheck->bridge = Stub::make(
|
$this->sskeycheck->bridge = Stub::make(
|
||||||
new Bridge,
|
new Bridge,
|
||||||
array('checkAPIKey' => array('code' => Bridge::CHECK_ERROR_UNAVAILABLE)),
|
array('checkMSSKey' => array('code' => Bridge::CHECK_ERROR_UNAVAILABLE)),
|
||||||
$this
|
$this
|
||||||
);
|
);
|
||||||
$this->setMailPoetSendingMethod();
|
$this->setMailPoetSendingMethod();
|
||||||
|
@ -47,24 +47,24 @@ class BridgeTest extends MailPoetTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testItChecksMSSKey() {
|
function testItChecksMSSKey() {
|
||||||
$result = $this->bridge->checkAPIKey($this->valid_key);
|
$result = $this->bridge->checkMSSKey($this->valid_key);
|
||||||
expect($result)->notEmpty();
|
expect($result)->notEmpty();
|
||||||
expect($result['state'])->equals(Bridge::MAILPOET_KEY_VALID);
|
expect($result['state'])->equals(Bridge::MAILPOET_KEY_VALID);
|
||||||
|
|
||||||
$result = $this->bridge->checkAPIKey($this->invalid_key);
|
$result = $this->bridge->checkMSSKey($this->invalid_key);
|
||||||
expect($result)->notEmpty();
|
expect($result)->notEmpty();
|
||||||
expect($result['state'])->equals(Bridge::MAILPOET_KEY_INVALID);
|
expect($result['state'])->equals(Bridge::MAILPOET_KEY_INVALID);
|
||||||
|
|
||||||
$result = $this->bridge->checkAPIKey($this->expiring_key);
|
$result = $this->bridge->checkMSSKey($this->expiring_key);
|
||||||
expect($result)->notEmpty();
|
expect($result)->notEmpty();
|
||||||
expect($result['state'])->equals(Bridge::MAILPOET_KEY_EXPIRING);
|
expect($result['state'])->equals(Bridge::MAILPOET_KEY_EXPIRING);
|
||||||
expect($result['data']['expire_at'])->notEmpty();
|
expect($result['data']['expire_at'])->notEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItReturnsErrorStateOnEmptyAPIResponseCodeDuringMSSCheck() {
|
function testItReturnsErrorStateOnEmptyAPIResponseCodeDuringMSSCheck() {
|
||||||
$api = Stub::make(new API(null), array('checkAPIKey' => array()), $this);
|
$api = Stub::make(new API(null), array('checkMSSKey' => array()), $this);
|
||||||
$this->bridge->api = $api;
|
$this->bridge->api = $api;
|
||||||
$result = $this->bridge->checkAPIKey($this->valid_key);
|
$result = $this->bridge->checkMSSKey($this->valid_key);
|
||||||
expect($result)->notEmpty();
|
expect($result)->notEmpty();
|
||||||
expect($result['state'])->equals(Bridge::MAILPOET_KEY_CHECK_ERROR);
|
expect($result['state'])->equals(Bridge::MAILPOET_KEY_CHECK_ERROR);
|
||||||
}
|
}
|
||||||
@ -125,7 +125,7 @@ class BridgeTest extends MailPoetTest {
|
|||||||
$api = Stub::make(
|
$api = Stub::make(
|
||||||
new API(null),
|
new API(null),
|
||||||
array(
|
array(
|
||||||
'checkAPIKey' => Stub::once(function() { return array(); }),
|
'checkMSSKey' => Stub::once(function() { return array(); }),
|
||||||
'checkPremiumKey' => Stub::once(function() { return array(); })
|
'checkPremiumKey' => Stub::once(function() { return array(); })
|
||||||
),
|
),
|
||||||
$this
|
$this
|
||||||
|
@ -12,7 +12,7 @@ class MockAPI {
|
|||||||
$this->setKey($api_key);
|
$this->setKey($api_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkAPIKey() {
|
function checkMSSKey() {
|
||||||
// if a key begins with these codes, return them
|
// if a key begins with these codes, return them
|
||||||
$regex = '/^(401|402|503)/';
|
$regex = '/^(401|402|503)/';
|
||||||
$code = preg_match($regex, $this->api_key, $m) ? $m[1] : 200;
|
$code = preg_match($regex, $this->api_key, $m) ? $m[1] : 200;
|
||||||
|
Reference in New Issue
Block a user