Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pilvo v4 support #39

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"illuminate/notifications": "~6.0 || ~7.0 || ~8.0",
"illuminate/support": "~6.0 || ~7.0 || ~8.0",
"illuminate/events": "~6.0 || ~7.0 || ~8.0",
"plivo/plivo-php": "^1.1"
"plivo/plivo-php": "^1.1 || ^4.0"
},
"require-dev": {
"mockery/mockery": "^1.3",
Expand Down
4 changes: 2 additions & 2 deletions src/Plivo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace NotificationChannels\Plivo;

use Plivo\RestAPI as PlivoRestApi;
use Plivo\RestClient;

class Plivo extends PlivoRestApi
class Plivo extends RestClient
{
/** @var string */
protected $auth_id;
Expand Down
25 changes: 14 additions & 11 deletions src/PlivoChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use Illuminate\Notifications\Notification;
use NotificationChannels\Plivo\Exceptions\CouldNotSendNotification;
use Plivo\Resources\Message\MessageCreateResponse;

class PlivoChannel
{
/**
* @var \NotificationChannels\Plivo\Plivo;
* @var Plivo;
*/
protected $plivo;

Expand All @@ -31,15 +32,16 @@ public function __construct(Plivo $plivo)
/**
* Send the given notification.
*
* @param mixed $notifiable
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
*
* @throws \NotificationChannels\Plivo\Exceptions\CouldNotSendNotification
* @return MessageCreateResponse|null
* @throws CouldNotSendNotification
*/
public function send($notifiable, Notification $notification)
{
if (! $to = $notifiable->routeNotificationFor('plivo')) {
return;
if (!$to = $notifiable->routeNotificationFor('plivo')) {
return null;
}

$message = $notification->toPlivo($notifiable);
Expand All @@ -48,13 +50,14 @@ public function send($notifiable, Notification $notification)
$message = new PlivoMessage($message);
}

$response = $this->plivo->send_message([
'src' => $message->from ?: $this->from,
'dst' => $to,
'text' => trim($message->content),
]);
/** @var MessageCreateResponse $response */
$response = $this->plivo->messages->create(
$message->from ?: $this->from,
$to,
trim($message->content)
);

if ($response['status'] !== 202) {
if ($response->getStatusCode() > 400) {
throw CouldNotSendNotification::serviceRespondedWithAnError($response);
}

Expand Down