Skip to content

Commit 5014253

Browse files
committed
Add a method to set the user agent after creation
1 parent bf26981 commit 5014253

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/Trafiklab/Common/Internal/CurlWebClient.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
namespace Trafiklab\Common\Internal;
99

10-
use Trafiklab\Common\Model\Exceptions\RequestTimedOutException;
1110
use Trafiklab\Common\Model\Contract\WebResponse;
11+
use Trafiklab\Common\Model\Exceptions\RequestTimedOutException;
1212

1313
/**
1414
* @internal
@@ -22,7 +22,7 @@ class CurlWebClient implements WebClient
2222
private $_userAgent;
2323
private $_cache;
2424

25-
public function __construct($userAgent)
25+
public function __construct($userAgent = '')
2626
{
2727
$this->_userAgent = $userAgent;
2828
$this->_cache = CacheImpl::getInstance();
@@ -98,4 +98,14 @@ function makeRequest(string $endpoint, array $parameters): WebResponse
9898
return $response;
9999
}
100100
}
101+
102+
/**
103+
* Set the user agent string to use when making web requests.
104+
*
105+
* @param string $userAgent The user agent to use.
106+
*/
107+
function setUserAgent(string $userAgent): void
108+
{
109+
$this->_userAgent = $userAgent;
110+
}
101111
}

src/Trafiklab/Common/Internal/WebClient.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,11 @@ interface WebClient
2525
* @throws RequestTimedOutException
2626
*/
2727
function makeRequest(string $endpoint, array $parameters): WebResponse;
28+
29+
/**
30+
* Set the user agent string to use when making web requests.
31+
*
32+
* @param string $userAgent The user agent to use.
33+
*/
34+
function setUserAgent(string $userAgent): void;
2835
}

0 commit comments

Comments
 (0)