Skip to content

Commit

Permalink
[feat] handle timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
aryala7 committed Apr 8, 2024
1 parent ed5c45c commit 9a707cd
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
11 changes: 11 additions & 0 deletions config/chapaar.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@
*/
'status' => false,

/*
* Timeout if a server does not return a response in seconds.
*/
'timeout' => env('CHAPAAR_TIMEOUT', 30),

/*
* Connect timeout in seconds.
*/
'connect_timeout' => env('CHAPAAR_CONNECT_TIMEOUT', 0),


/*
* Define configurations for different drivers
*/
Expand Down
7 changes: 5 additions & 2 deletions src/Drivers/Farapayamak/FarapayamakConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\RequestOptions;
use TookanTech\Chapaar\Contracts\DriverConnector;
use TookanTech\Chapaar\Exceptions\ApiException;
use TookanTech\Chapaar\Exceptions\HttpException;
Expand All @@ -21,11 +22,13 @@ public function __construct()
{
self::$setting = (object) config('chapaar.drivers.farapayamak');
$this->client = new Client([
'headers' => [
RequestOptions::HEADERS => [
'Content-Type' => 'application/x-www-form-urlencoded',
'charset' => 'utf-8',
],
'http_errors' => false,
RequestOptions::HTTP_ERRORS => false,
RequestOptions::TIMEOUT => config('chapaar.timeout'),
RequestOptions::CONNECT_TIMEOUT => config('chapaar.connect_timeout'),
]);

}
Expand Down
5 changes: 4 additions & 1 deletion src/Drivers/Ghasedak/GhasedakConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\RequestOptions;
use Illuminate\Http\Response;
use TookanTech\Chapaar\Contracts\DriverConnector;
use TookanTech\Chapaar\Exceptions\ApiException;
Expand All @@ -22,11 +23,13 @@ public function __construct()
{
self::$setting = (object) config('chapaar.drivers.ghasedak');
$this->client = new Client([
'headers' => [
RequestOptions::HEADERS => [
'apikey' => self::$setting->api_key,
'cache-control' => 'no-cache',
'content-type' => 'application/x-www-form-urlencoded',
],
RequestOptions::TIMEOUT => config('chapaar.timeout'),
RequestOptions::CONNECT_TIMEOUT => config('chapaar.connect_timeout'),
]);

}
Expand Down
9 changes: 6 additions & 3 deletions src/Drivers/Kavenegar/KavenegarConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\RequestOptions;
use Symfony\Component\HttpFoundation\Response;
use TookanTech\Chapaar\Contracts\DriverConnector;
use TookanTech\Chapaar\Exceptions\ApiException;
Expand All @@ -19,13 +20,15 @@ class KavenegarConnector implements DriverConnector
public function __construct()
{
$this->client = (new Client([
'headers' => [
RequestOptions::HEADERS => [
'Accept' => 'application/json',
'Content-Type' => 'application/x-www-form-urlencoded',
'charset' => 'utf-8',
],
'verify' => false,
'http_errors' => false,
RequestOptions::VERIFY => false,
RequestOptions::HTTP_ERRORS => false,
RequestOptions::TIMEOUT => config('chapaar.timeout'),
RequestOptions::CONNECT_TIMEOUT => config('chapaar.connect_timeout'),
]));
self::$setting = (object) config('chapaar.drivers.kavenegar');
}
Expand Down
5 changes: 4 additions & 1 deletion src/Drivers/SmsIr/SmsIrConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\RequestOptions;
use TookanTech\Chapaar\Contracts\DriverConnector;
use TookanTech\Chapaar\Exceptions\ApiException;
use TookanTech\Chapaar\Exceptions\HttpException;
Expand All @@ -19,11 +20,13 @@ public function __construct()
{
self::$setting = (object) config('chapaar.drivers.smsir');
$this->client = new Client([
'headers' => [
RequestOptions::HEADERS => [
'x-api-key' => self::$setting->api_key,
'Accept' => 'text/plain',
'Content-Type' => 'application/json',
],
RequestOptions::TIMEOUT => config('chapaar.timeout'),
RequestOptions::CONNECT_TIMEOUT => config('chapaar.connect_timeout'),
]);

}
Expand Down

0 comments on commit 9a707cd

Please sign in to comment.