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