Add subscriber count reporting on Sending Service key validation [MAILPOET-804]

This commit is contained in:
Alexey Stoletniy
2017-02-01 15:58:49 +03:00
parent 6575d1579d
commit be0c9b71d8
3 changed files with 33 additions and 4 deletions

View File

@ -15,6 +15,7 @@ class API {
public $url_me = 'https://bridge.mailpoet.com/api/v0/me';
public $url_messages = 'https://bridge.mailpoet.com/api/v0/messages';
public $url_bounces = 'https://bridge.mailpoet.com/api/v0/bounces/search';
public $url_stats = 'https://bridge.mailpoet.com/api/v0/stats';
function __construct($api_key) {
$this->setKey($api_key);
@ -70,7 +71,7 @@ class API {
function checkBounces(array $emails) {
$result = wp_remote_post(
$this->url,
$this->url_bounces,
$this->request($emails)
);
if(wp_remote_retrieve_response_code($result) === 200) {
@ -79,6 +80,17 @@ class API {
return false;
}
function updateSubscriberCount($count) {
$result = wp_remote_post(
$this->url_stats,
$this->request(array('subscriber_count' => (int)$count), 'PUT')
);
if(wp_remote_retrieve_response_code($result) === 204) {
return true;
}
return false;
}
function setKey($api_key) {
$this->api_key = $api_key;
}
@ -91,11 +103,11 @@ class API {
return 'Basic ' . base64_encode('api:' . $this->api_key);
}
private function request($body) {
private function request($body, $method = 'POST') {
return array(
'timeout' => 10,
'httpversion' => '1.0',
'method' => 'POST',
'method' => $method,
'headers' => array(
'Content-Type' => 'application/json',
'Authorization' => $this->auth()