Skip to content

Commit 9b606c7

Browse files
Laravel package improvements.
1 parent 572a827 commit 9b606c7

File tree

6 files changed

+165
-89
lines changed

6 files changed

+165
-89
lines changed

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ Please also set your email from address and name.
2929
]
3030
```
3131

32+
## Laravel 11.0+
33+
In the file `example-app/bootstrap/providers.php`
34+
```php
35+
use Mailjet\LaravelMailjet\MailjetServiceProvider;
36+
37+
return [
38+
App\Providers\AppServiceProvider::class,
39+
MailjetServiceProvider::class,
40+
];
41+
````
42+
3243
* In the aliases array:
3344

3445
```php
@@ -128,7 +139,3 @@ public function handle(ContactsV4Service $contactsV4Service)
128139
...
129140
}
130141
```
131-
132-
## ToDo
133-
134-
* Add additional unit tests to increase code coverage.

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
],
3232
"require": {
3333
"php": "^7.1.3|^8.0",
34-
"laravel/framework": "~5.1|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
34+
"laravel/framework": "^9.0|^10.0|^11.0",
3535
"mailjet/mailjet-apiv3-php": "^1.5.6|^1.5",
36+
"symfony/http-client": "^7.1",
3637
"symfony/mailjet-mailer": "^6.0"
3738
},
3839
"require-dev": {

src/Contracts/CampaignContract.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,28 @@
88

99
interface CampaignContract
1010
{
11-
public function getAllCampaigns(array $filters = null);
11+
/**
12+
* @param array|null $filters
13+
* @return array
14+
*/
15+
public function getAllCampaigns(array $filters = null): array;
1216

13-
public function findByCampaignId(string $id);
17+
/**
18+
* @param string $id
19+
* @return array
20+
*/
21+
public function findByCampaignId(string $id): array;
1422

15-
public function findByNewsletterId(string $id);
23+
/**
24+
* @param string $id
25+
* @return array
26+
*/
27+
public function findByNewsletterId(string $id): array;
1628

17-
public function updateCampaign(string $id, Campaign $campaign);
29+
/**
30+
* @param string $id
31+
* @param Campaign $campaign
32+
* @return array
33+
*/
34+
public function updateCampaign(string $id, Campaign $campaign): array;
1835
}

src/Contracts/CampaignDraftContract.php

Lines changed: 82 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,86 @@
88

99
interface CampaignDraftContract
1010
{
11-
public function getAllCampaignDrafts(array $filters = null);
12-
13-
public function findByCampaignDraftId(string $id);
14-
15-
public function create(CampaignDraft $campaignDraft);
16-
17-
public function update(string $id, CampaignDraft $campaignDraft);
18-
19-
public function getDetailContent(string $id);
20-
21-
public function createDetailContent(string $id, array $content);
22-
23-
public function getSchedule(string $id);
24-
25-
public function scheduleCampaign(string $id, string $date);
26-
27-
public function updateCampaignSchedule(string $id, string $date);
28-
29-
public function removeSchedule(string $id);
30-
31-
public function sendCampaign(string $id);
32-
33-
public function testCampaign(string $id, array $recipients);
34-
35-
public function getCampaignStatus(string $id);
11+
/**
12+
* @param array|null $filters
13+
* @return array
14+
*/
15+
public function getAllCampaignDrafts(array $filters = null): array;
16+
17+
/**
18+
* @param string $id
19+
* @return array
20+
*/
21+
public function findByCampaignDraftId(string $id): array;
22+
23+
/**
24+
* @param CampaignDraft $campaignDraft
25+
* @return array
26+
*/
27+
public function create(CampaignDraft $campaignDraft): array;
28+
29+
/**
30+
* @param string $id
31+
* @param CampaignDraft $campaignDraft
32+
* @return array
33+
*/
34+
public function update(string $id, CampaignDraft $campaignDraft): array;
35+
36+
/**
37+
* @param string $id
38+
* @return array
39+
*/
40+
public function getDetailContent(string $id): array;
41+
42+
/**
43+
* @param string $id
44+
* @param array $content
45+
* @return array
46+
*/
47+
public function createDetailContent(string $id, array $content): array;
48+
49+
/**
50+
* @param string $id
51+
* @return array
52+
*/
53+
public function getSchedule(string $id): array;
54+
55+
/**
56+
* @param string $id
57+
* @param string $date
58+
* @return array
59+
*/
60+
public function scheduleCampaign(string $id, string $date): array;
61+
62+
/**
63+
* @param string $id
64+
* @param string $date
65+
* @return array
66+
*/
67+
public function updateCampaignSchedule(string $id, string $date): array;
68+
69+
/**
70+
* @param string $id
71+
* @return array
72+
*/
73+
public function removeSchedule(string $id): array;
74+
75+
/**
76+
* @param string $id
77+
* @return array
78+
*/
79+
public function sendCampaign(string $id): array;
80+
81+
/**
82+
* @param string $id
83+
* @param array $recipients
84+
* @return array
85+
*/
86+
public function testCampaign(string $id, array $recipients): array;
87+
88+
/**
89+
* @param string $id
90+
* @return array
91+
*/
92+
public function getCampaignStatus(string $id): array;
3693
}

src/Services/CampaignDraftService.php

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public function __construct(MailjetService $mailjet)
2727

2828
/**
2929
* List campaign draft resources available for this apikey.
30-
*
30+
* @param array|null $filters
3131
* @return array
32-
* @throws \Mailjet\LaravelMailjet\Exception\MailjetException
32+
* @throws MailjetException
3333
*/
3434
public function getAllCampaignDrafts(array $filters = null): array
3535
{
@@ -44,12 +44,11 @@ public function getAllCampaignDrafts(array $filters = null): array
4444

4545
/**
4646
* Access a given CampaignDraft resource.
47-
*
4847
* @param string $id
49-
*
5048
* @return array
49+
* @throws MailjetException
5150
*/
52-
public function findByCampaignDraftId(string $id)
51+
public function findByCampaignDraftId(string $id): array
5352
{
5453
$response = $this->mailjet->get(Resources::$Campaigndraft,
5554
['id' => $id]);
@@ -63,10 +62,10 @@ public function findByCampaignDraftId(string $id)
6362

6463
/**
6564
* create a new fresh CampaignDraft
66-
*
6765
* @param Campaigndraft $campaignDraft
66+
* @throws MailjetException
6867
*/
69-
public function create(CampaignDraft $campaignDraft)
68+
public function create(CampaignDraft $campaignDraft): array
7069
{
7170
$response = $this->mailjet->post(Resources::$Campaigndraft,
7271
['body' => $campaignDraft->format()]);
@@ -79,11 +78,12 @@ public function create(CampaignDraft $campaignDraft)
7978

8079
/**
8180
* Update one specific campaigndraft resource
82-
*
83-
* @param int $id
81+
* @param string $id
8482
* @param Campaigndraft $campaignDraft
83+
* @return array
84+
* @throws MailjetException
8585
*/
86-
public function update($id, CampaignDraft $campaignDraft)
86+
public function update(string $id, CampaignDraft $campaignDraft): array
8787
{
8888
$response = $this->mailjet->put(Resources::$Campaigndraft,
8989
['id' => $id, 'body' => $campaignDraft->format()]);
@@ -96,12 +96,11 @@ public function update($id, CampaignDraft $campaignDraft)
9696

9797
/**
9898
* Return the text and html contents of the campaigndraft
99-
*
10099
* @param string $id
101-
*
102100
* @return array
101+
* @throws MailjetException
103102
*/
104-
public function getDetailContent(string $id)
103+
public function getDetailContent(string $id): array
105104
{
106105
$response = $this->mailjet->get(Resources::$CampaigndraftDetailcontent,
107106
['id' => $id]);
@@ -115,12 +114,12 @@ public function getDetailContent(string $id)
115114

116115
/**
117116
* Creates the content of a campaigndraft
118-
*
119117
* @param string $id
120-
*
118+
* @param array $contentData
121119
* @return array
120+
* @throws MailjetException
122121
*/
123-
public function createDetailContent($id, $contentData)
122+
public function createDetailContent(string $id, array $contentData): array
124123
{
125124
$response = $this->mailjet->post(Resources::$CampaigndraftDetailcontent,
126125
['id' => $id, 'body' => $contentData]);
@@ -134,12 +133,11 @@ public function createDetailContent($id, $contentData)
134133

135134
/**
136135
* Return the date of the scheduled sending of the campaigndraft
137-
*
138-
* @param string Campaign $id
139-
*
136+
* @param string $id
140137
* @return array
138+
* @throws MailjetException
141139
*/
142-
public function getSchedule(string $id)
140+
public function getSchedule(string $id): array
143141
{
144142
$response = $this->mailjet->get(Resources::$CampaigndraftSchedule,
145143
['id' => $id]);
@@ -153,13 +151,12 @@ public function getSchedule(string $id)
153151

154152
/**
155153
* Schedule when the campaigndraft will be sent
156-
*
157154
* @param string $id
158155
* @param string $date (RFC3339 format "Y-m-d\TH:i:sP")
159-
*
160156
* @return array
157+
* @throws MailjetException
161158
*/
162-
public function scheduleCampaign(string $id, string $date)
159+
public function scheduleCampaign(string $id, string $date): array
163160
{
164161
$response = $this->mailjet->post(Resources::$CampaigndraftSchedule,
165162
['id' => $id, 'body' => $date]);
@@ -173,13 +170,12 @@ public function scheduleCampaign(string $id, string $date)
173170

174171
/**
175172
* Update the date when the campaigndraft will be sent
176-
*
177-
* @param string Campaign $id
178-
* @param string Schedule $date
179-
*
173+
* @param string $id
174+
* @param string $date
180175
* @return array
176+
* @throws MailjetException
181177
*/
182-
public function updateCampaignSchedule($id, $date)
178+
public function updateCampaignSchedule(string $id, string $date): array
183179
{
184180
$response = $this->mailjet->put(Resources::$CampaigndraftSchedule,
185181
['id' => $id, 'body' => $date]);
@@ -193,12 +189,11 @@ public function updateCampaignSchedule($id, $date)
193189

194190
/**
195191
* Cancel a future sending
196-
*
197-
* @param string Campaign $id
198-
*
192+
* @param string $id
199193
* @return array
194+
* @throws MailjetException
200195
*/
201-
public function removeSchedule(string $id)
196+
public function removeSchedule(string $id): array
202197
{
203198
$response = $this->mailjet->delete(Resources::$CampaigndraftSchedule,
204199
['id' => $id]);
@@ -212,12 +207,11 @@ public function removeSchedule(string $id)
212207

213208
/**
214209
* Send the campaign immediately
215-
*
216-
* @param string Campaign $id
217-
*
210+
* @param string $id
218211
* @return array
212+
* @throws MailjetException
219213
*/
220-
public function sendCampaign(string $id)
214+
public function sendCampaign(string $id): array
221215
{
222216
$response = $this->mailjet->post(Resources::$CampaigndraftSend,
223217
['id' => $id]);
@@ -231,12 +225,11 @@ public function sendCampaign(string $id)
231225

232226
/**
233227
* Return the status of a CampaignDraft
234-
*
235-
* @param string Campaign $id
236-
*
228+
* @param string $id
237229
* @return array
230+
* @throws MailjetException
238231
*/
239-
public function getCampaignStatus(string $id)
232+
public function getCampaignStatus(string $id): array
240233
{
241234
$response = $this->mailjet->get(Resources::$CampaigndraftStatus,
242235
['id' => $id]);
@@ -250,13 +243,12 @@ public function getCampaignStatus(string $id)
250243

251244
/**
252245
* An action to test a CampaignDraft.
253-
*
254-
* @param string Campaign $id
255-
* @param array of $recipients
256-
*
246+
* @param string $id
247+
* @param array $recipients
257248
* @return array
249+
* @throws MailjetException
258250
*/
259-
public function testCampaign($id, $recipients)
251+
public function testCampaign(string $id, array $recipients): array
260252
{
261253
$response = $this->mailjet->post(Resources::$CampaigndraftTest,
262254
['id' => $id, 'body' => $recipients]);
@@ -268,7 +260,12 @@ public function testCampaign($id, $recipients)
268260
return $response->getData();
269261
}
270262

271-
private function throwError($title, Response $response)
263+
/**
264+
* @param $title
265+
* @param Response $response
266+
* @throws MailjetException
267+
*/
268+
private function throwError($title, Response $response): void
272269
{
273270
throw new MailjetException(0, $title, $response);
274271
}

0 commit comments

Comments
 (0)