Adds method to ping Bridge

This commit is contained in:
Vlad
2017-12-02 20:29:50 -05:00
parent 8d7289e8ba
commit aa4d78b1c9
2 changed files with 16 additions and 0 deletions

View File

@ -26,6 +26,8 @@ class Bridge {
const CHECK_ERROR_UNAVAILABLE = 503;
const CHECK_ERROR_UNKNOWN = 'unknown';
const BRIDGE_URL = 'https://bridge.mailpoet.com';
public $api;
static function isMPSendingServiceEnabled() {
@ -48,6 +50,15 @@ class Bridge {
return !empty($key);
}
static function pingBridge() {
$params = array(
'blocking' => true,
'timeout' => 10
);
$result = wp_remote_get(self::BRIDGE_URL, $params);
return wp_remote_retrieve_response_code($result) === 200;
}
function initApi($api_key) {
if($this->api) {
$this->api->setKey($api_key);

View File

@ -247,6 +247,11 @@ class BridgeTest extends \MailPoetTest {
$bridge->onSettingsSave($settings);
}
function testItPingsBridge() {
if(getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') return;
expect(Bridge::pingBridge())->true();
}
private function setMailPoetSendingMethod() {
Setting::setValue(
Mailer::MAILER_CONFIG_SETTING_NAME,