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

added pushoverKeyHasWrongLength() check #61

Merged
Merged
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
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
Loading