Skip to content

Commit 2230f8e

Browse files
authored
Merge pull request #1 from jtl-software/DefaultTimeout
add a timeout with default 5s to HttpClient
2 parents 44f5619 + ab8f34b commit 2230f8e

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/HttpClient.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,14 @@ class HttpClient
3131
* @param string $version
3232
* @return HttpClient
3333
*/
34-
public static function createForUSApi(string $authToken, string $version = '2'): HttpClient
34+
public static function createForUSApi(string $authToken, string $version = '2', int $timeout = 5): HttpClient
3535
{
36-
$guzzleClient = new \GuzzleHttp\Client(['base_uri' => "https://api.opsgenie.com/v{$version}/"]);
36+
$guzzleClient = new \GuzzleHttp\Client(
37+
[
38+
'base_uri' => "https://api.opsgenie.com/v{$version}/",
39+
RequestOptions::TIMEOUT => $timeout,
40+
]
41+
);
3742
return new HttpClient($authToken, $guzzleClient);
3843
}
3944

@@ -42,9 +47,14 @@ public static function createForUSApi(string $authToken, string $version = '2'):
4247
* @param string $version
4348
* @return HttpClient
4449
*/
45-
public static function createForEUApi(string $authToken, string $version = '2'): HttpClient
50+
public static function createForEUApi(string $authToken, string $version = '2', int $timeout = 5): HttpClient
4651
{
47-
$guzzleClient = new \GuzzleHttp\Client(['base_uri' => "https://api.eu.opsgenie.com/v{$version}/"]);
52+
$guzzleClient = new \GuzzleHttp\Client(
53+
[
54+
'base_uri' => "https://api.eu.opsgenie.com/v{$version}/",
55+
RequestOptions::TIMEOUT => $timeout,
56+
]
57+
);
4858
return new HttpClient($authToken, $guzzleClient);
4959
}
5060

0 commit comments

Comments
 (0)