Skip to content

Commit 0430a8e

Browse files
authored
Merge pull request #47 from mailjet/ref
Ref
2 parents 322ede7 + 8abe575 commit 0430a8e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1549
-1217
lines changed

composer.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,23 @@
3636
},
3737
"autoload": {
3838
"psr-4": {
39-
"Mailjet\\LaravelMailjet\\": "src/"
39+
"Mailjet\\LaravelMailjet\\": "src"
40+
}
41+
},
42+
"autoload-dev": {
43+
"psr-4": {
44+
"Mailjet\\LaravelMailjet\\Tests\\": "tests"
45+
}
46+
},
47+
"extra": {
48+
"laravel": {
49+
"providers": [
50+
"Mailjet\\LaravelMailjet\\MailjetServiceProvider",
51+
"Mailjet\\LaravelMailjet\\MailjetMailServiceProvider"
52+
],
53+
"aliases": {
54+
"Mailjet": "Mailjet\\LaravelMailjet\\Facades\\Mailjet"
55+
}
4056
}
4157
},
4258
"config": {

src/Contracts/CampaignContract.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Mailjet\LaravelMailjet\Contracts;
46

57
use Mailjet\LaravelMailjet\Model\Campaign;
68

79
interface CampaignContract
810
{
9-
1011
public function getAllCampaigns(array $filters = null);
1112

12-
public function findByCampaignId($CampaignId);
13+
public function findByCampaignId(string $id);
1314

14-
public function findByNewsletterId($NewsletterId);
15+
public function findByNewsletterId(string $id);
1516

16-
public function updateCampaign($CampaignId, Campaign $campaign);
17-
}
17+
public function updateCampaign(string $id, Campaign $campaign);
18+
}
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Mailjet\LaravelMailjet\Contracts;
46

57
use Mailjet\LaravelMailjet\Model\CampaignDraft;
68

79
interface CampaignDraftContract
810
{
9-
1011
public function getAllCampaignDrafts(array $filters = null);
1112

12-
public function findByCampaignDraftId($CampaignId);
13+
public function findByCampaignDraftId(string $id);
1314

1415
public function create(CampaignDraft $campaignDraft);
1516

16-
public function update($CampaignId, CampaignDraft $campaignDraft);
17+
public function update(string $id, CampaignDraft $campaignDraft);
1718

18-
public function getDetailContent($id);
19+
public function getDetailContent(string $id);
1920

20-
public function createDetailContent($id, $contentData);
21+
public function createDetailContent(string $id, array $content);
2122

22-
public function getSchedule($CampaignId);
23+
public function getSchedule(string $id);
2324

24-
public function scheduleCampaign($CampaignId, $date);
25+
public function scheduleCampaign(string $id, string $date);
2526

26-
public function updateCampaignSchedule($CampaignId, $date);
27+
public function updateCampaignSchedule(string $id, string $date);
2728

28-
public function removeSchedule($CampaignId);
29+
public function removeSchedule(string $id);
2930

30-
public function sendCampaign($CampaignId);
31+
public function sendCampaign(string $id);
3132

32-
public function testCampaign($CampaignId, $recipients);
33+
public function testCampaign(string $id, array $recipients);
3334

34-
public function getCampaignStatus($CampaignId);
35-
}
35+
public function getCampaignStatus(string $id);
36+
}
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
<?php
2-
/*
3-
* To change this license header, choose License Headers in Project Properties.
4-
* To change this template file, choose Tools | Templates
5-
* and open the template in the editor.
6-
*/
2+
3+
declare(strict_types=1);
74

85
namespace Mailjet\LaravelMailjet\Contracts;
96

107
use Mailjet\LaravelMailjet\Model\ContactMetadata;
118

129
interface ContactMetadataContract
1310
{
14-
1511
public function getAll();
1612

17-
public function get($id);
13+
public function get(string $id);
1814

19-
public function create(ContactMetadata $contactMetadata);
15+
public function create(ContactMetadata $metadata);
2016

21-
public function update($id, ContactMetadata $contactMetadata);
17+
public function update(string $id, ContactMetadata $metadata);
2218

23-
public function delete($id);
24-
}
19+
public function delete(string $id);
20+
}
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Mailjet\LaravelMailjet\Contracts;
46

57
use Mailjet\LaravelMailjet\Model\Contact;
68
use Mailjet\LaravelMailjet\Model\ContactsList;
79

810
interface ContactsListContract
911
{
12+
public function create(string $id, Contact $contact, $action = Contact::ACTION_ADDFORCE): array;
1013

11-
public function create($listId, Contact $contact,
12-
$action = Contact::ACTION_ADDFORCE);
13-
14-
public function update($listId, Contact $contact,
15-
$action = Contact::ACTION_ADDNOFORCE);
14+
public function update(string $id, Contact $contact, $action = Contact::ACTION_ADDNOFORCE): array;
1615

17-
public function subscribe($listId, Contact $contact, $force = true);
16+
public function subscribe(string $id, Contact $contact, bool $force = true): array;
1817

19-
public function unsubscribe($listId, Contact $contact);
18+
public function unsubscribe(string $id, Contact $contact): array;
2019

21-
public function delete($listId, Contact $contact);
20+
public function delete(string $id, Contact $contact): array;
2221

23-
public function updateEmail($listId, Contact $contact, $oldEmail);
22+
public function updateEmail(string $id, Contact $contact, string $oldEmail): array;
2423

25-
public function uploadManyContactsList(ContactsList $contactsList);
26-
}
24+
public function uploadManyContactsList(ContactsList $list): array;
25+
}
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Mailjet\LaravelMailjet\Contracts;
46

57
use Mailjet\LaravelMailjet\Model\EventCallbackUrl;
68

79
interface EventCallbackUrlContract
810
{
11+
public function getAll(): array;
912

10-
public function getAll();
11-
12-
public function get($id);
13+
public function get(string $id): array;
1314

14-
public function create(EventCallbackUrl $eventCallbackUrl);
15+
public function create(EventCallbackUrl $url): array;
1516

16-
public function update($id, EventCallbackUrl $eventCallbackUrl);
17+
public function update(string $id, EventCallbackUrl $url): array;
1718

18-
public function delete($id);
19-
}
19+
public function delete(string $id): array;
20+
}
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Mailjet\LaravelMailjet\Contracts;
46

7+
use Mailjet\Client;
8+
use Mailjet\Response;
9+
510
interface MailjetServiceContract
611
{
12+
public function post(array $resource, array $args = [], array $options = []): Response;
713

8-
public function post($resource, array $args = [], array $options = []);
9-
10-
public function get($resource, array $args = [], array $options = []);
14+
public function get(array $resource, array $args = [], array $options = []): Response;
1115

12-
public function put($resource, array $args = [], array $options = []);
16+
public function put(array $resource, array $args = [], array $options = []): Response;
1317

14-
public function delete($resource, array $args = [], array $options = []);
18+
public function delete(array $resource, array $args = [], array $options = []): Response;
1519

16-
public function getClient();
17-
}
20+
public function getClient(): Client;
21+
}
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Mailjet\LaravelMailjet\Contracts;
46

57
use Mailjet\LaravelMailjet\Model\Template;
68

79
interface TemplateServiceContract
810
{
11+
public function getAll(array $filters = null): array;
912

10-
public function getAll(array $filters = null);
11-
12-
public function get($id);
13+
public function get(string $id): array;
1314

14-
public function create(Template $Template);
15+
public function create(Template $template): array;
1516

16-
public function update($id, Template $Template);
17+
public function update(string $id, Template $template): array;
1718

18-
public function delete($id);
19+
public function delete(string $id): array;
1920

20-
public function getDetailContent($id);
21+
public function getDetailContent(string $id): array;
2122

22-
public function createDetailContent($id, $contentData);
23+
public function createDetailContent(string $id, array $content): array;
2324

24-
public function deleteDetailContent($id);
25-
}
25+
public function deleteDetailContent(string $id): array;
26+
}

src/Exception/MailjetException.php

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,55 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
namespace Mailjet\LaravelMailjet\Exception;
36

7+
use Throwable;
48
use \Mailjet\Response;
59

6-
/**
7-
* Handle Mailjet API errors
8-
*/
910
class MailjetException extends \Exception
1011
{
11-
/**
12-
* @var int
13-
*/
14-
private $statusCode;
1512
/**
1613
* @var string
1714
*/
1815
private $errorInfo;
16+
1917
/**
2018
* @var string
2119
*/
2220
private $errorMessage;
21+
2322
/**
2423
* @var string
2524
*/
2625
private $errorIdentifier;
26+
2727
/**
2828
* https://dev.mailjet.com/guides/#about-the-mailjet-restful-api
29+
*
2930
* @param Response $response
3031
* @param \Throwable $previous
3132
*/
32-
public function __construct($statusCode=0, $message=null, Response $response=null, \Throwable $previous=null)
33+
public function __construct($statusCode = 0, $message = null, Response $response = null, Throwable $previous = null)
3334
{
34-
// if you pass a Mailjet\Response
3535
if ($response) {
3636
$statusCode = $response->getStatus();
37-
$message = sprintf('%s: %s', $message, $response->getReasonPhrase());
37+
$message = "{$message}: {$response->getReasonPhrase()}";
38+
3839
$this->setErrorFromResponse($response);
3940
}
41+
4042
parent::__construct($message, $statusCode, $previous);
4143
}
4244
/**
43-
* Configure MailjetException from Mailjet\Response
44-
* @method setErrorFromResponse
45+
* Configure MailjetException from Mailjet\Response.
46+
*
4547
* @param Response $response
4648
*/
47-
private function setErrorFromResponse(Response $response)
49+
private function setErrorFromResponse(Response $response): void
4850
{
49-
$this->statusCode = $response->getStatus();
5051
$body = $response->getBody();
52+
5153
if (isset($body['ErrorInfo'])) {
5254
$this->errorInfo = $body['ErrorInfo'];
5355
}
@@ -58,24 +60,27 @@ private function setErrorFromResponse(Response $response)
5860
$this->errorIdentifier = $body['ErrorIdentifier'];
5961
}
6062
}
63+
6164
/**
6265
* @return string
6366
*/
64-
public function getErrorInfo()
67+
public function getErrorInfo(): string
6568
{
6669
return $this->errorInfo;
6770
}
71+
6872
/**
6973
* @return string
7074
*/
71-
public function getErrorMessage()
75+
public function getErrorMessage(): string
7276
{
7377
return $this->errorMessage;
7478
}
79+
7580
/**
7681
* @return string
7782
*/
78-
public function getErrorIdentifier()
83+
public function getErrorIdentifier(): string
7984
{
8085
return $this->errorIdentifier;
8186
}

src/Facades/Mailjet.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Mailjet\LaravelMailjet\Facades;
46

57
use Illuminate\Support\Facades\Facade;
68

79
class Mailjet extends Facade
810
{
9-
protected static function getFacadeAccessor()
11+
protected static function getFacadeAccessor(): string
1012
{
1113
return 'Mailjet';
1214
}

0 commit comments

Comments
 (0)