diff --git a/composer.json b/composer.json index d8f8b35..726d3f0 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/Plivo.php b/src/Plivo.php index 7b0b8e0..d3911dc 100644 --- a/src/Plivo.php +++ b/src/Plivo.php @@ -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; diff --git a/src/PlivoChannel.php b/src/PlivoChannel.php index eb36c11..3a43768 100644 --- a/src/PlivoChannel.php +++ b/src/PlivoChannel.php @@ -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; @@ -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); @@ -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); }