You've already forked laravel-push
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 00ea95cc8d | |||
| a076368f51 |
@@ -2,5 +2,6 @@
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'api_key' => env('PUSH_API_KEY', null),
|
'api_key' => env('PUSH_API_KEY', null),
|
||||||
'api_url' => env('PUSH_API_URL', null)
|
'api_url' => env('PUSH_API_URL', null),
|
||||||
|
'test_mode' => env('PUSH_TEST_MODE', false),
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace Bluesquare\Push;
|
|||||||
use Bluesquare\Push\PushTemplate;
|
use Bluesquare\Push\PushTemplate;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Psr\Http\Message\StreamInterface;
|
use Psr\Http\Message\StreamInterface;
|
||||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||||
|
|
||||||
@@ -17,9 +18,17 @@ class PushApi
|
|||||||
*/
|
*/
|
||||||
private $api_key;
|
private $api_key;
|
||||||
|
|
||||||
public function __construct(string $api_key)
|
/**
|
||||||
|
* Test mode
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $test_mode;
|
||||||
|
|
||||||
|
public function __construct(string $api_key, bool $test_mode = false)
|
||||||
{
|
{
|
||||||
$this->api_key = $api_key;
|
$this->api_key = $api_key;
|
||||||
|
$this->test_mode = $test_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -28,7 +37,7 @@ class PushApi
|
|||||||
* @return \Psr\Http\Message\StreamInterface
|
* @return \Psr\Http\Message\StreamInterface
|
||||||
* @throws PushException
|
* @throws PushException
|
||||||
*/
|
*/
|
||||||
public function send($template, $notifiable): StreamInterface
|
public function send($template, $notifiable): StreamInterface|false
|
||||||
{
|
{
|
||||||
$url = config('push.api_url') ?? 'https://push.bluesquare.io/api/send';
|
$url = config('push.api_url') ?? 'https://push.bluesquare.io/api/send';
|
||||||
|
|
||||||
@@ -51,6 +60,17 @@ class PushApi
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->test_mode) {
|
||||||
|
if (! empty($this->api_key)) {
|
||||||
|
$template->testMode();
|
||||||
|
} else {
|
||||||
|
Log::debug("Push test mode: API key missing, discarding notification", $template->toArray());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} elseif (empty($this->api_key)) {
|
||||||
|
throw new PushException('Push API key is required');
|
||||||
|
}
|
||||||
|
|
||||||
$multipart_form = [];
|
$multipart_form = [];
|
||||||
|
|
||||||
foreach ($template as $key => $value) {
|
foreach ($template as $key => $value) {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class PushChannel
|
|||||||
* @return \Psr\Http\Message\StreamInterface
|
* @return \Psr\Http\Message\StreamInterface
|
||||||
* @throws PushException
|
* @throws PushException
|
||||||
*/
|
*/
|
||||||
public function send($notifiable, Notification $notification): StreamInterface
|
public function send($notifiable, Notification $notification): StreamInterface|false
|
||||||
{
|
{
|
||||||
$template = $notification->toTemplate($notifiable);
|
$template = $notification->toTemplate($notifiable);
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class PushServiceProvider extends ServiceProvider
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->app->singleton(PushApi::class, function ($app) {
|
$this->app->singleton(PushApi::class, function ($app) {
|
||||||
return new PushApi($app['config']['push']['api_key']);
|
return new PushApi($app['config']['push']['api_key'], $app['config']['push']['test_mode']);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,10 +78,6 @@ class PushTemplate implements \JsonSerializable
|
|||||||
public function __construct(string $template_id)
|
public function __construct(string $template_id)
|
||||||
{
|
{
|
||||||
$this->template_id = $template_id;
|
$this->template_id = $template_id;
|
||||||
|
|
||||||
if (env('PUSH_TEST_MODE', false)) {
|
|
||||||
$this->testMode();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -89,7 +85,7 @@ class PushTemplate implements \JsonSerializable
|
|||||||
* @param string|null $name
|
* @param string|null $name
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function sender(string $email, string $name = null): PushTemplate
|
public function sender(string $email, ?string $name = null): PushTemplate
|
||||||
{
|
{
|
||||||
$this->sender['email'] = $email;
|
$this->sender['email'] = $email;
|
||||||
|
|
||||||
@@ -104,7 +100,7 @@ class PushTemplate implements \JsonSerializable
|
|||||||
* @param string|null $name
|
* @param string|null $name
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function replyTo(string $email, string $name = null): PushTemplate
|
public function replyTo(string $email, ?string $name = null): PushTemplate
|
||||||
{
|
{
|
||||||
$this->replyTo['email'] = $email;
|
$this->replyTo['email'] = $email;
|
||||||
|
|
||||||
@@ -160,7 +156,7 @@ class PushTemplate implements \JsonSerializable
|
|||||||
* @param string|null $unsubscribe_url
|
* @param string|null $unsubscribe_url
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function addRecipient(string $email, string $name = null, array $parameters = [], string $unsubscribe_url = null, string $locale = null): PushTemplate
|
public function addRecipient(string $email, ?string $name = null, array $parameters = [], ?string $unsubscribe_url = null, ?string $locale = null): PushTemplate
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
'email' => $email
|
'email' => $email
|
||||||
@@ -216,7 +212,7 @@ class PushTemplate implements \JsonSerializable
|
|||||||
* @param $filename
|
* @param $filename
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function addAttachment($file, $filename = null)
|
public function addAttachment($file, ?string $filename = null)
|
||||||
{
|
{
|
||||||
$file = is_object($file) && method_exists($file, 'getRealPath') ? $file->getRealPath() : $file;
|
$file = is_object($file) && method_exists($file, 'getRealPath') ? $file->getRealPath() : $file;
|
||||||
|
|
||||||
@@ -266,14 +262,14 @@ class PushTemplate implements \JsonSerializable
|
|||||||
* @param string|null $locale
|
* @param string|null $locale
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function locale(string $locale = null)
|
public function locale(?string $locale = null)
|
||||||
{
|
{
|
||||||
$this->locale = $locale;
|
$this->locale = $locale;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function unsubscribeUrl($url = null)
|
public function unsubscribeUrl(?string $url = null)
|
||||||
{
|
{
|
||||||
$this->unsubscribe_url = $url;
|
$this->unsubscribe_url = $url;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user