From afcef12052ccaf83e9a7dc649c6f4bf34c64bac6 Mon Sep 17 00:00:00 2001 From: tomaszthreadable Date: Tue, 10 Aug 2021 13:00:52 +0100 Subject: [PATCH 1/3] add timeout option to Guzzle Client --- config/onesignal.php | 12 +++++++++++- src/OneSignalClient.php | 9 ++++++++- src/OneSignalServiceProvider.php | 4 +--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/config/onesignal.php b/config/onesignal.php index 1cf7d92..b1c3b9b 100644 --- a/config/onesignal.php +++ b/config/onesignal.php @@ -19,5 +19,15 @@ | */ 'rest_api_key' => env('ONESIGNAL_REST_API_KEY'), - 'user_auth_key' => env('USER_AUTH_KEY') + 'user_auth_key' => env('USER_AUTH_KEY'), + + /* + |-------------------------------------------------------------------------- + | Guzzle Timeout + |-------------------------------------------------------------------------- + | + | + | + */ + 'guzzle_client_timeout' => env('ONESIGNAL_GUZZLE_CLIENT_TIMEOUT', 0), ); diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index 4d600c6..d4fadbe 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -69,7 +69,13 @@ public function callback(Callable $requestCallback) return $this; } - public function __construct($appId, $restApiKey, $userAuthKey) + /** + * @param $appId + * @param $restApiKey + * @param $userAuthKey + * @param int $guzzleClientTimeout + */ + public function __construct($appId, $restApiKey, $userAuthKey, $guzzleClientTimeout = 0) { $this->appId = $appId; $this->restApiKey = $restApiKey; @@ -77,6 +83,7 @@ public function __construct($appId, $restApiKey, $userAuthKey) $this->client = new Client([ 'handler' => $this->createGuzzleHandler(), + 'timeout' => $guzzleClientTimeout, ]); $this->headers = ['headers' => []]; $this->additionalParams = []; diff --git a/src/OneSignalServiceProvider.php b/src/OneSignalServiceProvider.php index 828219a..ee4f072 100644 --- a/src/OneSignalServiceProvider.php +++ b/src/OneSignalServiceProvider.php @@ -36,9 +36,7 @@ public function register() $config = $app['config']['onesignal'] ?: $app['config']['onesignal::config']; } - $client = new OneSignalClient($config['app_id'], $config['rest_api_key'], $config['user_auth_key']); - - return $client; + return new OneSignalClient($config['app_id'], $config['rest_api_key'], $config['user_auth_key'] , $config['guzzle_client_timeout']); }); $this->app->alias('onesignal', 'Berkayk\OneSignal\OneSignalClient'); From cc7c14264d8f63cdd17cee0877d26344614bbaaf Mon Sep 17 00:00:00 2001 From: tomaszthreadable Date: Tue, 10 Aug 2021 13:11:23 +0100 Subject: [PATCH 2/3] update docs --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 5bd8302..6c2a05a 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,11 @@ You need to fill in your OneSignal *App ID* and *REST API Key* inside your ONESIGNAL_APP_ID=xxxxxxxxxxxxxxxxxxxx ONESIGNAL_REST_API_KEY=xxxxxxxxxxxxxxxxxx ``` +You can control timeout of the Guzzle client used by OnesignalClient by adding following into your .env file +``` +ONESIGNAL_GUZZLE_CLIENT_TIMEOUT=integer_value +``` +This param is useful when you are planning to send push notification via [Laravel queues](https://divinglaravel.com/always-set-a-timeout-for-guzzle-requests-inside-a-queued-job) ## Usage From b88d0ad88b8906e1fb121e1323f61797e350ec25 Mon Sep 17 00:00:00 2001 From: tomaszthreadable Date: Tue, 10 Aug 2021 13:12:26 +0100 Subject: [PATCH 3/3] update docs - fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c2a05a..9d53b49 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ You need to fill in your OneSignal *App ID* and *REST API Key* inside your ONESIGNAL_APP_ID=xxxxxxxxxxxxxxxxxxxx ONESIGNAL_REST_API_KEY=xxxxxxxxxxxxxxxxxx ``` -You can control timeout of the Guzzle client used by OnesignalClient by adding following into your .env file +You can control timeout of the Guzzle client used by OneSignalClient by adding following into your .env file ``` ONESIGNAL_GUZZLE_CLIENT_TIMEOUT=integer_value ```