Skip to content

Commit 0fb7978

Browse files
authored
Merge pull request #15 from asantibanez/postmark-driver
Added Postmark driver
2 parents 65c137e + c4b1678 commit 0fb7978

File tree

6 files changed

+86
-1
lines changed

6 files changed

+86
-1
lines changed

config/mailbox.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* The driver to use when listening for incoming emails.
77
* It defaults to the mail driver that you are using.
88
*
9-
* Supported drivers: "log", "mailgun", "sendgrid"
9+
* Supported drivers: "log", "mailgun", "sendgrid", "postmark"
1010
*/
1111
'driver' => env('MAILBOX_DRIVER', 'log'),
1212

src/Drivers/Postmark.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace BeyondCode\Mailbox\Drivers;
4+
5+
use Illuminate\Support\Facades\Route;
6+
use BeyondCode\Mailbox\Http\Controllers\PostmarkController;
7+
8+
class Postmark implements DriverInterface
9+
{
10+
public function register()
11+
{
12+
Route::prefix(config('mailbox.path'))->group(function () {
13+
Route::post('/postmark', PostmarkController::class);
14+
});
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace BeyondCode\Mailbox\Http\Controllers;
4+
5+
use BeyondCode\Mailbox\Facades\Mailbox;
6+
use BeyondCode\Mailbox\Http\Requests\PostmarkRequest;
7+
8+
class PostmarkController
9+
{
10+
public function __invoke(PostmarkRequest $request)
11+
{
12+
Mailbox::callMailboxes($request->email());
13+
}
14+
}

src/Http/Requests/PostmarkRequest.php

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace BeyondCode\Mailbox\Http\Requests;
4+
5+
use BeyondCode\Mailbox\InboundEmail;
6+
use Illuminate\Support\Facades\Validator;
7+
use Illuminate\Foundation\Http\FormRequest;
8+
9+
class PostmarkRequest extends FormRequest
10+
{
11+
public function validator()
12+
{
13+
return Validator::make($this->all(), [
14+
'RawEmail' => 'required',
15+
]);
16+
}
17+
18+
public function email()
19+
{
20+
return InboundEmail::fromMessage($this->get('RawEmail'));
21+
}
22+
}

src/MailboxManager.php

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Support\Manager;
66
use BeyondCode\Mailbox\Drivers\Log;
77
use BeyondCode\Mailbox\Drivers\Mailgun;
8+
use BeyondCode\Mailbox\Drivers\Postmark;
89
use BeyondCode\Mailbox\Drivers\SendGrid;
910

1011
class MailboxManager extends Manager
@@ -29,6 +30,11 @@ public function createSendGridDriver()
2930
return new SendGrid;
3031
}
3132

33+
public function createPostmarkDriver()
34+
{
35+
return new Postmark;
36+
}
37+
3238
public function getDefaultDriver()
3339
{
3440
return $this->app['config']['mailbox.driver'];

tests/Controllers/PostmarkTest.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace BeyondCode\Mailbox\Tests\Controllers;
4+
5+
use BeyondCode\Mailbox\Tests\TestCase;
6+
7+
class PostmarkTest extends TestCase
8+
{
9+
protected function getEnvironmentSetUp($app)
10+
{
11+
parent::getEnvironmentSetUp($app);
12+
13+
$app['config']['mailbox.driver'] = 'postmark';
14+
}
15+
16+
/** @test */
17+
public function it_expects_to_receive_raw_email_field()
18+
{
19+
$this->post('/laravel-mailbox/postmark', [
20+
'something' => 'value',
21+
])->assertSessionHasErrors('RawEmail')->assertStatus(302);
22+
23+
$this->post('/laravel-mailbox/postmark', [
24+
'RawEmail' => 'value',
25+
])->assertStatus(200);
26+
}
27+
}

0 commit comments

Comments
 (0)