Skip to content

Commit 13e1819

Browse files
authored
Merge pull request #61 from boryn/key-wrong-length
added pushoverKeyHasWrongLength() check
2 parents f0d6d9e + e23fe7f commit 13e1819

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Exceptions/CouldNotSendNotification.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,15 @@ public static function serviceRespondedWithAnError(ResponseInterface $response,
2929

3030
return new static($exceptionMessage, $statusCode);
3131
}
32+
33+
public static function pushoverKeyHasWrongLength($notifiable)
34+
{
35+
$exceptionMessage = sprintf(
36+
"Pushover key has wrong length for notifiable '%s' with id '%s'. It needs to be 30 characters long.",
37+
get_class($notifiable),
38+
$notifiable->getKey()
39+
);
40+
41+
return new static($exceptionMessage);
42+
}
3243
}

src/PushoverChannel.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Contracts\Events\Dispatcher;
66
use Illuminate\Notifications\Events\NotificationFailed;
77
use Illuminate\Notifications\Notification;
8+
use NotificationChannels\Pushover\Exceptions\CouldNotSendNotification;
89
use NotificationChannels\Pushover\Exceptions\ServiceCommunicationError;
910

1011
class PushoverChannel
@@ -41,6 +42,12 @@ public function send($notifiable, Notification $notification)
4142
}
4243

4344
if (is_string($pushoverReceiver)) {
45+
// From https://pushover.net/api:
46+
// "User and group identifiers are 30 characters long, ..."
47+
if (strlen($pushoverReceiver) !== 30) {
48+
throw CouldNotSendNotification::pushoverKeyHasWrongLength($notifiable);
49+
}
50+
4451
$pushoverReceiver = PushoverReceiver::withUserKey($pushoverReceiver);
4552
}
4653

0 commit comments

Comments
 (0)