-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from mailjet/contacts-v4-endpoint
allowed contacts removing
- Loading branch information
Showing
4 changed files
with
138 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
|
||
namespace Mailjet\LaravelMailjet\Contracts; | ||
|
||
interface ContactsV4Contract | ||
{ | ||
public function delete($id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Mailjet\LaravelMailjet\Providers; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
use Mailjet\LaravelMailjet\Contracts\ContactsV4Contract; | ||
use Mailjet\LaravelMailjet\Services\ContactsV4Service; | ||
use Mailjet\LaravelMailjet\Services\MailjetService; | ||
|
||
class ContactsServiceProvider extends ServiceProvider | ||
{ | ||
protected $defer = true; | ||
|
||
/** | ||
* Bootstrap the application services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* Register the application services. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
$this->app->bind(ContactsV4Service::class, function($app) { | ||
$config = $this->app['config']->get('services.mailjet', []); | ||
$call = $this->app['config']->get('services.mailjet.v4.call', true); | ||
$options = $this->app['config']->get('services.mailjet.v4.options', []); | ||
|
||
$mailjetService = new MailjetService($config['key'], $config['secret'], $call, $options); | ||
|
||
return new ContactsV4Service($mailjetService); | ||
}); | ||
} | ||
|
||
/** | ||
* Get the services provided by the provider. | ||
* | ||
* @return array | ||
*/ | ||
public function provides() | ||
{ | ||
return [ContactsV4Service::class]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Mailjet\LaravelMailjet\Services; | ||
|
||
use Mailjet\LaravelMailjet\Contracts\ContactsV4Contract; | ||
use \Mailjet\Resources; | ||
use Mailjet\LaravelMailjet\Exception\MailjetException; | ||
|
||
/** | ||
* https://dev.mailjet.com/email/guides/contact-management/#gdpr-delete-contacts | ||
*/ | ||
class ContactsV4Service implements ContactsV4Contract | ||
{ | ||
/** | ||
* Mailjet client | ||
* @var MailjetService | ||
*/ | ||
protected $mailjet; | ||
|
||
/** | ||
* @param MailjetService $mailjet | ||
*/ | ||
public function __construct(MailjetService $mailjet) | ||
{ | ||
$this->mailjet = $mailjet; | ||
} | ||
|
||
/** | ||
* Delete a Contact | ||
* @param int $id | ||
* @return bool | ||
*/ | ||
public function delete($id) | ||
{ | ||
$response = $this->mailjet->delete(['contacts', ''], ['id' => $id]); | ||
|
||
if (!$response->success()) { | ||
throw new MailjetException(0, "ContactsV4Service:delete() failed", $response); | ||
} | ||
|
||
return 200 === $response->getStatus(); | ||
} | ||
} |