Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 9be2ae4

Browse files
committed
feat(NotificationPreferences): Added method to get a list of notifications
Added method to get a list of notifications
1 parent 8b13518 commit 9be2ae4

File tree

5 files changed

+90
-0
lines changed

5 files changed

+90
-0
lines changed

src/Resource/NotificationPreferences.php

+12
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ public function get($notification_id)
103103
return $this->getByPath($this->generatePath('notifications', $notification_id));
104104
}
105105

106+
/**
107+
* Create a new Orders list instance.
108+
*
109+
* @return \Moip\Resource\NotificationPreferencesList
110+
*/
111+
public function getList()
112+
{
113+
$notificationList = new NotificationPreferencesList($this->moip);
114+
115+
return $notificationList->get();
116+
}
117+
106118
/**
107119
* Delete.
108120
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Moip\Resource;
4+
5+
use Moip\Helper\Filters;
6+
use Moip\Helper\Pagination;
7+
use stdClass;
8+
9+
class NotificationPreferencesList extends MoipResource
10+
{
11+
/**
12+
* @const string
13+
*/
14+
const PATH = 'preferences';
15+
16+
public function initialize()
17+
{
18+
$this->data = new stdClass();
19+
}
20+
21+
/**
22+
* Get notifications.
23+
*
24+
* @return array
25+
*/
26+
public function getNotifications()
27+
{
28+
return $this->data;
29+
}
30+
31+
/**
32+
* Get a notification list
33+
*
34+
* @return stdClass
35+
*/
36+
public function get()
37+
{
38+
return $this->getByPath(sprintf('/%s/%s', MoipResource::VERSION, self::PATH));
39+
}
40+
41+
protected function populate(stdClass $response)
42+
{
43+
$notificationsList = clone $this;
44+
45+
$notificationsList->data = new stdClass();
46+
47+
$notificationsList->data->notifications = $response;
48+
49+
return $notificationsList;
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Moip\Tests\Resource;
4+
5+
use Moip\Helper\Filters;
6+
use Moip\Helper\Pagination;
7+
use Moip\Tests\TestCase;
8+
9+
class NotificationPreferencesListTest extends TestCase
10+
{
11+
public function testShouldGetNotificationsList()
12+
{
13+
$this->mockHttpSession($this->body_notification_list);
14+
15+
$orders = $this->moip->notifications()->getList();
16+
17+
$this->assertNotNull($orders->getOrders());
18+
}
19+
}

tests/TestCase.php

+7
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ abstract class TestCase extends PHPUnit_Framework_TestCase
100100
*/
101101
protected $body_order_list;
102102

103+
/**
104+
* @var string response from moip API.
105+
*/
106+
protected $body_notification_list;
107+
103108
/**
104109
* @var string holds the last generated customer ownId. In mock mode it'll be always the default, but it changes on sandbox mode.
105110
*/
@@ -148,6 +153,8 @@ public function __construct()
148153
$this->body_list_webhook_pagination = $this->readJsonFile('jsons/webhooks/get_pagination');
149154

150155
$this->body_list_webhook_all_filters = $this->readJsonFile('jsons/webhooks/get_all_filters');
156+
157+
$this->body_notification_list = $this->readJsonFile('jsons/notification/list');
151158
}
152159

153160
/**

0 commit comments

Comments
 (0)