Skip to content

Commit

Permalink
Merge pull request #61 from boryn/key-wrong-length
Browse files Browse the repository at this point in the history
added pushoverKeyHasWrongLength() check
  • Loading branch information
Kovah committed Mar 11, 2024
2 parents f0d6d9e + e23fe7f commit 13e1819
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Exceptions/CouldNotSendNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,15 @@ public static function serviceRespondedWithAnError(ResponseInterface $response,

return new static($exceptionMessage, $statusCode);
}

public static function pushoverKeyHasWrongLength($notifiable)
{
$exceptionMessage = sprintf(
"Pushover key has wrong length for notifiable '%s' with id '%s'. It needs to be 30 characters long.",
get_class($notifiable),
$notifiable->getKey()
);

return new static($exceptionMessage);
}
}
7 changes: 7 additions & 0 deletions src/PushoverChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Notifications\Events\NotificationFailed;
use Illuminate\Notifications\Notification;
use NotificationChannels\Pushover\Exceptions\CouldNotSendNotification;
use NotificationChannels\Pushover\Exceptions\ServiceCommunicationError;

class PushoverChannel
Expand Down Expand Up @@ -41,6 +42,12 @@ public function send($notifiable, Notification $notification)
}

if (is_string($pushoverReceiver)) {
// From https://pushover.net/api:
// "User and group identifiers are 30 characters long, ..."
if (strlen($pushoverReceiver) !== 30) {
throw CouldNotSendNotification::pushoverKeyHasWrongLength($notifiable);
}

$pushoverReceiver = PushoverReceiver::withUserKey($pushoverReceiver);
}

Expand Down

0 comments on commit 13e1819

Please sign in to comment.