-
Notifications
You must be signed in to change notification settings - Fork 50
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 #24 from dwightwatson/shortcode
[2.x] Implement shortcode support
- Loading branch information
Showing
5 changed files
with
131 additions
and
18 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Illuminate\Notifications\Channels; | ||
|
||
use Illuminate\Notifications\Notification; | ||
use Nexmo\Message\Client as NexmoClient; | ||
|
||
class NexmoShortcodeChannel | ||
{ | ||
/** | ||
* The Nexmo message client instance. | ||
* | ||
* @var \Nexmo\Message\Client | ||
*/ | ||
protected $nexmo; | ||
|
||
/** | ||
* Create a new channel instance. | ||
* | ||
* @param \Nexmo\Message\Client $nexmo | ||
* @return void | ||
*/ | ||
public function __construct(NexmoClient $nexmo) | ||
{ | ||
$this->client = $nexmo; | ||
} | ||
|
||
/** | ||
* Send the given notification. | ||
* | ||
* @param mixed $notifiable | ||
* @param \Illuminate\Notifications\Notification $notification | ||
* @return void | ||
*/ | ||
public function send($notifiable, Notification $notification) | ||
{ | ||
if (! $to = $notifiable->routeNotificationFor('shortcode', $notification)) { | ||
return; | ||
} | ||
|
||
$shortcode = array_merge(['to' => $to], $notification->toShortcode($notifiable)); | ||
|
||
$this->nexmo->sendShortcode($shortcode); | ||
} | ||
} |
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,53 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Notifications\Channels; | ||
|
||
use Illuminate\Notifications\Channels\NexmoShortcodeChannel; | ||
use Illuminate\Notifications\Notifiable; | ||
use Illuminate\Notifications\Notification; | ||
use Illuminate\Tests\Notifications\TestCase; | ||
use Mockery as m; | ||
use Nexmo\Message\Client; | ||
|
||
class NexmoShortcodeChannelTest extends TestCase | ||
{ | ||
public function testShortcodeIsSentViaNexmo() | ||
{ | ||
$notification = new NotificationNexmoShortcodeChannelTestNotification; | ||
$notifiable = new NotificationNexmoShortcodeChannelTestNotifiable; | ||
|
||
$channel = new NexmoShortcodeChannel( | ||
$nexmo = m::mock(Client::class) | ||
); | ||
|
||
$nexmo->shouldReceive('sendShortcode')->with([ | ||
'type' => 'alert', | ||
'to' => '5555555555', | ||
'custom' => [ | ||
'code' => 'abc123', | ||
], | ||
]); | ||
|
||
$channel->send($notifiable, $notification); | ||
} | ||
} | ||
|
||
class NotificationNexmoShortcodeChannelTestNotifiable | ||
{ | ||
use Notifiable; | ||
|
||
public $phone_number = '5555555555'; | ||
} | ||
|
||
class NotificationNexmoShortcodeChannelTestNotification extends Notification | ||
{ | ||
public function toShortcode($notifiable) | ||
{ | ||
return [ | ||
'type' => 'alert', | ||
'custom' => [ | ||
'code' => 'abc123', | ||
], | ||
]; | ||
} | ||
} |
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,11 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Notifications; | ||
|
||
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; | ||
use PHPUnit\Framework\TestCase as BaseTestCase; | ||
|
||
class TestCase extends BaseTestCase | ||
{ | ||
use MockeryPHPUnitIntegration; | ||
} |