Adds method to get subscriber
This commit is contained in:
@ -164,6 +164,15 @@ class API {
|
||||
return $new_list->asArray();
|
||||
}
|
||||
|
||||
function getSubscriber($subscriber_email) {
|
||||
$subscriber = Subscriber::findOne($subscriber_email);
|
||||
// throw exception when subscriber does not exist
|
||||
if(!$subscriber) {
|
||||
throw new \Exception(__('This subscriber does not exist.', 'mailpoet'));
|
||||
}
|
||||
return $subscriber->withCustomFields()->withSubscriptions()->asArray();
|
||||
}
|
||||
|
||||
protected function _sendConfirmationEmail(Subscriber $subscriber) {
|
||||
return $subscriber->sendConfirmationEmail();
|
||||
}
|
||||
|
@ -350,6 +350,32 @@ class APITest extends \MailPoetTest {
|
||||
expect($result['name'])->equals($segment['name']);
|
||||
}
|
||||
|
||||
function testItGetsSubscriber() {
|
||||
$subscriber = Subscriber::create();
|
||||
$subscriber->hydrate(Fixtures::get('subscriber_template'));
|
||||
$subscriber->save();
|
||||
$segment = Segment::createOrUpdate(
|
||||
array(
|
||||
'name' => 'Default',
|
||||
'type' => Segment::TYPE_DEFAULT
|
||||
)
|
||||
);
|
||||
API::MP(self::VERSION)->subscribeToList($subscriber->id, $segment->id);
|
||||
|
||||
// successful response
|
||||
$result = API::MP(self::VERSION)->getSubscriber($subscriber->email);
|
||||
expect($result['email'])->equals($subscriber->email);
|
||||
expect($result['subscriptions'][0]['segment_id'])->equals($segment->id);
|
||||
|
||||
// error response
|
||||
try {
|
||||
API::MP(self::VERSION)->getSubscriber('some_fake_email');
|
||||
$this->fail('Subscriber does not exist exception should have been thrown.');
|
||||
} catch(\Exception $e) {
|
||||
expect($e->getMessage())->equals('This subscriber does not exist.');
|
||||
}
|
||||
}
|
||||
|
||||
function _after() {
|
||||
\ORM::raw_execute('TRUNCATE ' . Subscriber::$_table);
|
||||
\ORM::raw_execute('TRUNCATE ' . CustomField::$_table);
|
||||
|
Reference in New Issue
Block a user